summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPawit Pornkitprasan <p.pawit@gmail.com>2013-09-01 16:24:14 +0700
committeralk3pInjection <webmaster@raspii.tech>2022-05-02 09:56:20 +0800
commit7d87793679dd4979c4c95d379f14af464b58ec38 (patch)
tree746385aec0f995be54c5c369da69acffda6312ed
parentb07e75c37b40446289645961aac7c8bc23cf5eb2 (diff)
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/ice_config.xml13
-rw-r--r--core/res/res/values/ice_symbols.xml5
-rw-r--r--services/core/java/com/android/server/pm/PackageManagerService.java42
3 files changed, 60 insertions, 0 deletions
diff --git a/core/res/res/values/ice_config.xml b/core/res/res/values/ice_config.xml
index 0dba9cbaeb9f..07802d7a3603 100644
--- a/core/res/res/values/ice_config.xml
+++ b/core/res/res/values/ice_config.xml
@@ -18,4 +18,17 @@
platform signatures, specifically for use on devices with a vendor partition. -->
<string-array name="config_vendorPlatformSignatures">
</string-array>
+
+ <!-- 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/ice_symbols.xml b/core/res/res/values/ice_symbols.xml
index 054e161f819b..c981eae9f9ca 100644
--- a/core/res/res/values/ice_symbols.xml
+++ b/core/res/res/values/ice_symbols.xml
@@ -16,4 +16,9 @@
<resources>
<!-- Vendor signatures -->
<java-symbol type="array" name="config_vendorPlatformSignatures" />
+
+ <!-- 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 2d16f7430dc3..fec2adbbe5b3 100644
--- a/services/core/java/com/android/server/pm/PackageManagerService.java
+++ b/services/core/java/com/android/server/pm/PackageManagerService.java
@@ -1551,6 +1551,8 @@ public class PackageManagerService extends IPackageManager.Stub
private final PackageProperty mPackageProperty = new PackageProperty();
+ ArrayList<ComponentName> mDisabledComponentsList;
+
// Set of pending broadcasts for aggregating enable/disable of components.
@VisibleForTesting(visibility = Visibility.PACKAGE)
public static class PendingPackageBroadcasts {
@@ -8076,6 +8078,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
@@ -8241,6 +8254,29 @@ public class PackageManagerService extends IPackageManager.Stub
Slog.i(TAG, "Fix for b/169414761 is applied");
}
+ 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
+ || !AndroidPackageUtils.hasComponentClassName(pkgSetting.pkg, 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
@@ -24181,6 +24217,12 @@ public class PackageManagerService extends IPackageManager.Stub
public void setComponentEnabledSetting(ComponentName componentName,
int newState, int flags, int userId) {
if (!mUserManager.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);
}