Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 6a3c15a7 authored by Pawit Pornkitprasan's avatar Pawit Pornkitprasan Committed by Michael Bestas
Browse files

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

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
parent 404ebaa8
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -35,4 +35,8 @@
    <java-symbol type="integer" name="config_longPressOnMenuBehavior" />
    <java-symbol type="integer" name="config_longPressOnAppSwitchBehavior" />

    <!-- Package Manager -->
    <java-symbol type="array" name="config_disabledComponents" />
    <java-symbol type="array" name="config_forceEnabledComponents" />

</resources>
+8 −0
Original line number Diff line number Diff line
@@ -2864,4 +2864,12 @@

    <!-- Setting to false will disable CM's IME switcher implementation for tablets -->
    <bool name="config_show_cmIMESwitcher">true</bool>

    <!-- The list of components which should be automatically disabled. -->
    <string-array name="config_disabledComponents" 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>
+41 −0
Original line number Diff line number Diff line
@@ -979,6 +979,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>
@@ -2659,6 +2661,38 @@ public class PackageManagerService extends IPackageManager.Stub {
            reconcileAppsDataLI(StorageManager.UUID_PRIVATE_INTERNAL, UserHandle.USER_SYSTEM,
                    storageFlags);
            // Disable components marked for disabling at build-time
            mDisabledComponentsList = new ArrayList<ComponentName>();
            for (String name : mContext.getResources().getStringArray(
                    com.android.internal.R.array.config_disabledComponents)) {
                ComponentName cn = ComponentName.unflattenFromString(name);
                mDisabledComponentsList.add(cn);
                Slog.v(TAG, "Disabling " + name);
                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 disable " + name);
                    continue;
                }
                pkgSetting.disableComponentLPw(className, UserHandle.USER_OWNER);
            }
            // Enable components marked for forced-enable at build-time
            for (String name : mContext.getResources().getStringArray(
                    com.android.internal.R.array.config_forceEnabledComponents)) {
                ComponentName cn = ComponentName.unflattenFromString(name);
                Slog.v(TAG, "Enabling " + name);
                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 enable " + name);
                    continue;
                }
                pkgSetting.enableComponentLPw(className, UserHandle.USER_OWNER);
            }
            // 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
@@ -18007,6 +18041,12 @@ Slog.v(TAG, ":: stepped forward, applying functor at tag " + parser.getName());
    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);
    }
@@ -18021,6 +18061,7 @@ Slog.v(TAG, ":: stepped forward, applying functor at tag " + parser.getName());
            throw new IllegalArgumentException("Invalid new component state: "
                    + newState);
        }
        PackageSetting pkgSetting;
        final int uid = Binder.getCallingUid();
        final int permission;