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

Commit 4fd8e6f6 authored by Ryan Mitchell's avatar Ryan Mitchell
Browse files

Add component-override to sysconfig

The <component-override> tag in sys config allows an OEM to configure
the enabled state of package components.

Eg.
<!-- Disable com.foo.bar.MyActivity -->
<component-override package="com.foo.bar">
    <component class=".MyActivity" enabled="false">
</component-override>

The value in the sys config file overrides the value defined within
the package manifest.

Bug: 135048762
Test: adb shell pm resolve-activity
com.android.settings/com.android.settings.RegulatoryInfoDisplayActivity

Change-Id: I71de31601bb175d4be1cc5996142ef93ca279fc1
parent 2515002a
Loading
Loading
Loading
Loading
+64 −0
Original line number Diff line number Diff line
@@ -168,6 +168,10 @@ public class SystemConfig {
    // These are the permitted backup transport service components
    final ArraySet<ComponentName> mBackupTransportWhitelist = new ArraySet<>();

    // These are packages mapped to maps of component class name to default enabled state.
    final ArrayMap<String, ArrayMap<String, Boolean>> mPackageComponentEnabledState =
            new ArrayMap<>();

    // Package names that are exempted from private API blacklisting
    final ArraySet<String> mHiddenApiPackageWhitelist = new ArraySet<>();

@@ -301,6 +305,10 @@ public class SystemConfig {
        return mBackupTransportWhitelist;
    }

    public ArrayMap<String, Boolean> getComponentsEnabledStates(String packageName) {
        return mPackageComponentEnabledState.get(packageName);
    }

    public ArraySet<String> getDisabledUntilUsedPreinstalledCarrierApps() {
        return mDisabledUntilUsedPreinstalledCarrierApps;
    }
@@ -846,6 +854,14 @@ public class SystemConfig {
                        }
                        XmlUtils.skipCurrentTag(parser);
                    } break;
                    case "component-override": {
                        if (allowAppConfigs) {
                            readComponentOverrides(parser, permFile);
                        } else {
                            logNotAllowedInPartition(name, permFile, parser);
                        }
                        XmlUtils.skipCurrentTag(parser);
                    } break;
                    case "backup-transport-whitelisted-service": {
                        if (allowFeatures) {
                            String serviceName = parser.getAttributeValue(null, "service");
@@ -1269,6 +1285,54 @@ public class SystemConfig {
        }
    }

    private void readComponentOverrides(XmlPullParser parser, File permFile)
            throws IOException, XmlPullParserException {
        String pkgname = parser.getAttributeValue(null, "package");
        if (pkgname == null) {
            Slog.w(TAG, "<component-override> without package in "
                    + permFile + " at " + parser.getPositionDescription());
            return;
        }

        pkgname = pkgname.intern();

        final int depth = parser.getDepth();
        while (XmlUtils.nextElementWithin(parser, depth)) {
            String name = parser.getName();
            if ("component".equals(name)) {
                String clsname = parser.getAttributeValue(null, "class");
                String enabled = parser.getAttributeValue(null, "enabled");
                if (clsname == null) {
                    Slog.w(TAG, "<component> without class in "
                            + permFile + " at " + parser.getPositionDescription());
                    return;
                } else if (enabled == null) {
                    Slog.w(TAG, "<component> without enabled in "
                            + permFile + " at " + parser.getPositionDescription());
                    return;
                }

                if (clsname.startsWith(".")) {
                    clsname = pkgname + clsname;
                }

                clsname = clsname.intern();

                ArrayMap<String, Boolean> componentEnabledStates =
                        mPackageComponentEnabledState.get(pkgname);
                if (componentEnabledStates == null) {
                    componentEnabledStates = new ArrayMap<>();
                    mPackageComponentEnabledState.put(pkgname,
                            componentEnabledStates);
                }

                componentEnabledStates.put(clsname, !"false".equals(enabled));
            } else {
                XmlUtils.skipCurrentTag(parser);
            }
        }
    }

    private static boolean isSystemProcess() {
        return Process.myUid() == Process.SYSTEM_UID;
    }
+48 −0
Original line number Diff line number Diff line
@@ -10657,6 +10657,50 @@ public class PackageManagerService extends IPackageManager.Stub
        return changedAbiCodePath;
    }
    /**
     * Sets the enabled state of components configured through {@link SystemConfig}.
     * This modifies the {@link PackageSetting} object.
     **/
    static void configurePackageComponents(PackageParser.Package pkg) {
        final ArrayMap<String, Boolean> componentsEnabledStates = SystemConfig.getInstance()
                .getComponentsEnabledStates(pkg.packageName);
        if (componentsEnabledStates == null) {
            return;
        }
        for (int i = pkg.activities.size() - 1; i >= 0; i--) {
            final PackageParser.Activity component = pkg.activities.get(i);
            final Boolean enabled = componentsEnabledStates.get(component.className);
            if (enabled != null) {
                component.info.enabled = enabled;
            }
        }
        for (int i = pkg.receivers.size() - 1; i >= 0; i--) {
            final PackageParser.Activity component = pkg.receivers.get(i);
            final Boolean enabled = componentsEnabledStates.get(component.className);
            if (enabled != null) {
                component.info.enabled = enabled;
            }
        }
        for (int i = pkg.providers.size() - 1; i >= 0; i--) {
            final PackageParser.Provider component = pkg.providers.get(i);
            final Boolean enabled = componentsEnabledStates.get(component.className);
            if (enabled != null) {
                component.info.enabled = enabled;
            }
        }
        for (int i = pkg.services.size() - 1; i >= 0; i--) {
            final PackageParser.Service component = pkg.services.get(i);
            final Boolean enabled = componentsEnabledStates.get(component.className);
            if (enabled != null) {
                component.info.enabled = enabled;
            }
        }
    }
    /**
     * Just scans the package without any side effects.
@@ -10824,6 +10868,10 @@ public class PackageManagerService extends IPackageManager.Stub
            pkg.applicationInfo.initForUser(UserHandle.USER_SYSTEM);
        }
        if (pkg.isSystem()) {
            configurePackageComponents(pkg);
        }
        final String cpuAbiOverride = deriveAbiOverride(pkg.cpuAbiOverride, pkgSetting);
        if ((scanFlags & SCAN_NEW_INSTALL) == 0) {