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

Commit 0c700bb7 authored by Pawit Pornkitprasan's avatar Pawit Pornkitprasan Committed by Bruno Martins
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 b369d0c8
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -22,4 +22,12 @@
    <!-- 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. -->
    <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>
+4 −0
Original line number Diff line number Diff line
@@ -26,4 +26,8 @@

    <!-- Rotation sensor -->
    <java-symbol type="bool" name="config_useSystemClockforRotationSensor" />

    <!-- Package Manager -->
    <java-symbol type="array" name="config_disabledComponents" />
    <java-symbol type="array" name="config_forceEnabledComponents" />
</resources>
+40 −0
Original line number Diff line number Diff line
@@ -1237,6 +1237,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>
@@ -3149,6 +3151,38 @@ 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>();
            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
@@ -20639,6 +20673,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);
    }