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

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

PackageManager: Allow build-time disabling of components



Co-authored-by: default avatarGianmarco Reverberi <gianmarco.reverberi@gmail.com>
Co-authored-by: default avatarMichael W <baddaemon87@gmail.com>
Change-Id: Ic26c9d2f080ab61e09b2d64ae48cd6f29147774a
parent 8c5dbd8c
Loading
Loading
Loading
Loading
+47 −0
Original line number Diff line number Diff line
@@ -904,6 +904,8 @@ public class PackageManagerService implements PackageSender, TestUtilityService

    private final PackageProperty mPackageProperty = new PackageProperty();

    ArrayList<ComponentName> mDisabledComponentsList;

    final PendingPackageBroadcasts mPendingBroadcasts;

    static final int SEND_PENDING_BROADCAST = 1;
@@ -2395,6 +2397,20 @@ public class PackageManagerService implements PackageSender, TestUtilityService
            // Defer the app data fixup until we are done with app data clearing above.
            mPrepareAppDataFuture = mAppDataHelper.fixAppsDataOnBoot();

            // Disable components marked for disabling at build-time
            mDisabledComponentsList = new ArrayList<ComponentName>();
            enableComponents(mContext.getResources().getStringArray(
                     org.lineageos.platform.internal.R.array.config_deviceDisabledComponents),
                     false);
            enableComponents(mContext.getResources().getStringArray(
                    org.lineageos.platform.internal.R.array.config_globallyDisabledComponents),
                    false);

            // Enable components marked for forced-enable at build-time
            enableComponents(mContext.getResources().getStringArray(
                    org.lineageos.platform.internal.R.array.config_forceEnabledComponents),
                    true);

            // Legacy existing (installed before Q) non-system apps to hide
            // their icons in launcher.
            if (mIsPreQUpgrade) {
@@ -2558,6 +2574,29 @@ public class PackageManagerService implements PackageSender, TestUtilityService
        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.getPkg() == null
                    || !AndroidPackageUtils.hasComponentClassName(pkgSetting.getPkg(), 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);
            }
        }
    }

    @GuardedBy("mLock")
    void updateInstantAppInstallerLocked(String modifiedPackage) {
        // we're only interested in updating the installer application when 1) it's not
@@ -3808,6 +3847,14 @@ public class PackageManagerService implements PackageSender, TestUtilityService
        final int targetSize = settings.size();
        for (int i = 0; i < targetSize; i++) {
            final int newState = settings.get(i).getEnabledState();
            if (settings.get(i).isComponent()) {
                // Don't allow to enable components marked for disabling at build-time
                if (mDisabledComponentsList.contains(settings.get(i).getComponentName())) {
                    Slog.d(TAG, "Ignoring attempt to set enabled state of disabled component "
                        + settings.get(i).getComponentName().flattenToString());
                    return;
                }
            }
            if (!(newState == COMPONENT_ENABLED_STATE_DEFAULT
                    || newState == COMPONENT_ENABLED_STATE_ENABLED
                    || newState == COMPONENT_ENABLED_STATE_DISABLED