diff options
author | Pawit Pornkitprasan <p.pawit@gmail.com> | 2013-09-01 16:24:14 +0700 |
---|---|---|
committer | Nolen Johnson <johnsonnolen@gmail.com> | 2019-11-15 04:43:44 +0000 |
commit | 67ffb9a81e011e16bf0a1870fd64af1950db001f (patch) | |
tree | 4b2ee653bd3b7b3523add6e29b75aa9d88352675 | |
parent | aaef70a48756129f2d0a633e3fb5d8d1237afa23 (diff) | |
download | android_frameworks_base-67ffb9a81e011e16bf0a1870fd64af1950db001f.tar.gz android_frameworks_base-67ffb9a81e011e16bf0a1870fd64af1950db001f.tar.bz2 android_frameworks_base-67ffb9a81e011e16bf0a1870fd64af1950db001f.zip |
PackageManager: allow build-time disabling of components
Author: Pawit Pornkitprasan <p.pawit@gmail.com>
Date: Sun Sep 1 16:24:14 2013 +0700
PackageManager: allow build-time disabling of components
Allow components to be specified as disabled at build time
(applied on boot).
This allows stock OTA components to be marked as disabled in
CM builds.
Change-Id: I6e4499cc40a779792a5ea97a10137399dad7d69f
Author: Gianmarco Reverberi <gianmarco.reverberi@gmail.com>
Date: Mon Mar 16 20:02:15 2015 +0100
SystemUpdateService: enable service but lock its receivers [1/2]
Added a check for ensure that disabled components are not
re-enabled at runtime
Added code for forcing enable of previously disabled components
Change-Id: Icfcfa26ccb85028d32edbb5cdb3dd7cdae85b720
Author: Michael W <baddaemon87@gmail.com>
Date: Mon Oct 28 14:26:43 2019 +0100
PM: Allow disabling components per-device
* Introduce a new overlayable string-array
"config_deviceDisabledComponents"
* This is equally used to disable components per-device, e.g.
NearbyMessagingService
* At the same time, rename config_disabledComponents to
config_globallyDisabledComponents to reflect the difference
Change-Id: Ieeec0788b063a33e8a2830dd95b239c99a58466f
Author: Michael W <baddaemon87@gmail.com>
Date: Fri Nov 1 11:11:29 2019 +0100
PackageManager: Refactor en-/disabling of components
* Don't use the same code twice, make it reusable
Change-Id: I9fc388f56cea413654a390cb0ccd15a706fb3ad8
Change-Id: Ic26c9d2f080ab61e09b2d64ae48cd6f29147774a
-rw-r--r-- | core/res/res/values/lineage_config.xml | 15 | ||||
-rw-r--r-- | core/res/res/values/lineage_symbols.xml | 7 | ||||
-rw-r--r-- | services/core/java/com/android/server/pm/PackageManagerService.java | 42 |
3 files changed, 62 insertions, 2 deletions
diff --git a/core/res/res/values/lineage_config.xml b/core/res/res/values/lineage_config.xml index a3694ebe5dc..9ceccfe6caf 100644 --- a/core/res/res/values/lineage_config.xml +++ b/core/res/res/values/lineage_config.xml @@ -1,6 +1,6 @@ <!-- Copyright (C) 2012-2015 The CyanogenMod Project - Copyright (C) 2017 The LineageOS Project + Copyright (C) 2017-2019 The LineageOS Project Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -25,4 +25,17 @@ <!-- Older rotation sensors are not setting event.timestamp correctly. Setting to true will use SystemClock.elapsedRealtimeNanos() to set timestamp. --> <bool name="config_useSystemClockforRotationSensor">false</bool> + + <!-- The list of components which should be automatically disabled for a specific device. + Note: this MUST not be used to randomly disable components, ask for approval first! --> + <string-array name="config_deviceDisabledComponents" translatable="false"> + </string-array> + + <!-- The list of components which should be automatically disabled for all devices. --> + <string-array name="config_globallyDisabledComponents" translatable="false"> + </string-array> + + <!-- The list of components which should be forced to be enabled. --> + <string-array name="config_forceEnabledComponents" translatable="false"> + </string-array> </resources> diff --git a/core/res/res/values/lineage_symbols.xml b/core/res/res/values/lineage_symbols.xml index 570c7d594b3..34b4acf9ddc 100644 --- a/core/res/res/values/lineage_symbols.xml +++ b/core/res/res/values/lineage_symbols.xml @@ -1,6 +1,6 @@ <!-- Copyright (C) 2012-2015 The CyanogenMod Project - Copyright (C) 2017 The LineageOS Project + Copyright (C) 2017-2019 The LineageOS Project Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -29,4 +29,9 @@ <!-- Rotation sensor --> <java-symbol type="bool" name="config_useSystemClockforRotationSensor" /> + + <!-- Package Manager --> + <java-symbol type="array" name="config_deviceDisabledComponents" /> + <java-symbol type="array" name="config_globallyDisabledComponents" /> + <java-symbol type="array" name="config_forceEnabledComponents" /> </resources> diff --git a/services/core/java/com/android/server/pm/PackageManagerService.java b/services/core/java/com/android/server/pm/PackageManagerService.java index 1b5a03b0943..5c150de4308 100644 --- a/services/core/java/com/android/server/pm/PackageManagerService.java +++ b/services/core/java/com/android/server/pm/PackageManagerService.java @@ -1247,6 +1247,8 @@ public class PackageManagerService extends IPackageManager.Stub filter.hasDataScheme(IntentFilter.SCHEME_HTTPS)); } + ArrayList<ComponentName> mDisabledComponentsList; + // Set of pending broadcasts for aggregating enable/disable of components. static class PendingPackageBroadcasts { // for each user id, a map of <package name -> components within that package> @@ -3240,6 +3242,17 @@ public class PackageManagerService extends IPackageManager.Stub Slog.i(TAG, "Deferred reconcileAppsData finished " + count + " packages"); }, "prepareAppData"); + // Disable components marked for disabling at build-time + mDisabledComponentsList = new ArrayList<ComponentName>(); + enableComponents(mContext.getResources().getStringArray( + com.android.internal.R.array.config_deviceDisabledComponents), false); + enableComponents(mContext.getResources().getStringArray( + com.android.internal.R.array.config_globallyDisabledComponents), false); + + // Enable components marked for forced-enable at build-time + enableComponents(mContext.getResources().getStringArray( + com.android.internal.R.array.config_forceEnabledComponents), true); + // If this is first boot after an OTA, and a normal boot, then // we need to clear code cache directories. // Note that we do *not* clear the application profiles. These remain valid @@ -3392,6 +3405,29 @@ public class PackageManagerService extends IPackageManager.Stub Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER); } + private void enableComponents(String[] components, boolean enable) { + // Disable or enable components marked at build-time + for (String name : components) { + ComponentName cn = ComponentName.unflattenFromString(name); + if (!enable) { + mDisabledComponentsList.add(cn); + } + Slog.v(TAG, "Changing enabled state of " + name + " to " + enable); + String className = cn.getClassName(); + PackageSetting pkgSetting = mSettings.mPackages.get(cn.getPackageName()); + if (pkgSetting == null || pkgSetting.pkg == null + || !pkgSetting.pkg.hasComponentClassName(className)) { + Slog.w(TAG, "Unable to change enabled state of " + name + " to " + enable); + continue; + } + if (enable) { + pkgSetting.enableComponentLPw(className, UserHandle.USER_OWNER); + } else { + pkgSetting.disableComponentLPw(className, UserHandle.USER_OWNER); + } + } + } + /** * Uncompress and install stub applications. * <p>In order to save space on the system partition, some applications are shipped in a @@ -21212,6 +21248,12 @@ public class PackageManagerService extends IPackageManager.Stub public void setComponentEnabledSetting(ComponentName componentName, int newState, int flags, int userId) { if (!sUserManager.exists(userId)) return; + // Don't allow to enable components marked for disabling at build-time + if (mDisabledComponentsList.contains(componentName)) { + Slog.d(TAG, "Ignoring attempt to set enabled state of disabled component " + + componentName.flattenToString()); + return; + } setEnabledSetting(componentName.getPackageName(), componentName.getClassName(), newState, flags, userId, null); } |