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

Commit c6fff30a authored by Victor Hsieh's avatar Victor Hsieh
Browse files

Clean up code for experiment of JIT'ing priv apps

Test: atest DexManagerTests
Bug: 142547770
Change-Id: I26690020d5f7017fcec48311059f03c65139af92
parent 0fd72921
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -5888,7 +5888,7 @@ package android.provider {
    field public static final String NAMESPACE_AUTOFILL = "autofill";
    field public static final String NAMESPACE_CONNECTIVITY = "connectivity";
    field public static final String NAMESPACE_CONTENT_CAPTURE = "content_capture";
    field public static final String NAMESPACE_DEX_BOOT = "dex_boot";
    field @Deprecated public static final String NAMESPACE_DEX_BOOT = "dex_boot";
    field public static final String NAMESPACE_DISPLAY_MANAGER = "display_manager";
    field public static final String NAMESPACE_GAME_DRIVER = "game_driver";
    field public static final String NAMESPACE_INPUT_NATIVE_BOOT = "input_native_boot";
+2 −0
Original line number Diff line number Diff line
@@ -130,8 +130,10 @@ public final class DeviceConfig {
    /**
     * Namespace for how dex runs. The feature requires a reboot to reach a clean state.
     *
     * @deprecated No longer used
     * @hide
     */
    @Deprecated
    @SystemApi
    public static final String NAMESPACE_DEX_BOOT = "dex_boot";

+0 −2
Original line number Diff line number Diff line
@@ -56,8 +56,6 @@ class SettingsProtoDumpUtil {
                ConfigSettingsProto.CONNECTIVITY_SETTINGS);
        namespaceToFieldMap.put(DeviceConfig.NAMESPACE_CONTENT_CAPTURE,
                ConfigSettingsProto.CONTENT_CAPTURE_SETTINGS);
        namespaceToFieldMap.put(DeviceConfig.NAMESPACE_DEX_BOOT,
                ConfigSettingsProto.DEX_BOOT_SETTINGS);
        namespaceToFieldMap.put(DeviceConfig.NAMESPACE_GAME_DRIVER,
                ConfigSettingsProto.GAME_DRIVER_SETTINGS);
        namespaceToFieldMap.put(DeviceConfig.NAMESPACE_INPUT_NATIVE_BOOT,
+3 −18
Original line number Diff line number Diff line
@@ -16,8 +16,6 @@

package com.android.server.pm.dex;

import static android.provider.DeviceConfig.NAMESPACE_DEX_BOOT;

import static com.android.server.pm.InstructionSets.getAppDexInstructionSets;
import static com.android.server.pm.dex.PackageDexUsage.DexUseInfo;
import static com.android.server.pm.dex.PackageDexUsage.PackageUseInfo;
@@ -31,7 +29,6 @@ import android.os.RemoteException;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.os.storage.StorageManager;
import android.provider.DeviceConfig;
import android.util.Log;
import android.util.Slog;
import android.util.jar.StrictJarFile;
@@ -72,10 +69,6 @@ public class DexManager {
    private static final String PROPERTY_NAME_PM_DEXOPT_PRIV_APPS_OOB_LIST =
            "pm.dexopt.priv-apps-oob-list";

    // flags for Device Config API
    private static final String PRIV_APPS_OOB_ENABLED = "priv_apps_oob_enabled";
    private static final String PRIV_APPS_OOB_WHITELIST = "priv_apps_oob_whitelist";

    private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);

    private final Context mContext;
@@ -717,24 +710,16 @@ public class DexManager {
        return isPackageSelectedToRunOobInternal(
                SystemProperties.getBoolean(PROPERTY_NAME_PM_DEXOPT_PRIV_APPS_OOB, false),
                SystemProperties.get(PROPERTY_NAME_PM_DEXOPT_PRIV_APPS_OOB_LIST, "ALL"),
                DeviceConfig.getProperty(NAMESPACE_DEX_BOOT, PRIV_APPS_OOB_ENABLED),
                DeviceConfig.getProperty(NAMESPACE_DEX_BOOT, PRIV_APPS_OOB_WHITELIST),
                packageNamesInSameProcess);
    }

    @VisibleForTesting
    /* package */ static boolean isPackageSelectedToRunOobInternal(
            boolean isDefaultEnabled, String defaultWhitelist, String overrideEnabled,
            String overrideWhitelist, Collection<String> packageNamesInSameProcess) {
        // Allow experiment (if exists) to override device configuration.
        boolean enabled = overrideEnabled != null ? overrideEnabled.equals("true")
                : isDefaultEnabled;
        if (!enabled) {
    /* package */ static boolean isPackageSelectedToRunOobInternal(boolean isEnabled,
            String whitelist, Collection<String> packageNamesInSameProcess) {
        if (!isEnabled) {
            return false;
        }

        // Similarly, experiment flag can override the whitelist.
        String whitelist = overrideWhitelist != null ? overrideWhitelist : defaultWhitelist;
        if ("ALL".equals(whitelist)) {
            return true;
        }
+19 −43
Original line number Diff line number Diff line
@@ -691,35 +691,16 @@ public class DexManagerTests {
        }
    }

    private boolean shouldPackageRunOob(
            boolean isDefaultEnabled, String defaultWhitelist, String overrideEnabled,
            String overrideWhitelist, Collection<String> packageNamesInSameProcess) {
    private boolean shouldPackageRunOob(boolean isDefaultEnabled, String whitelist,
            Collection<String> packageNamesInSameProcess) {
        return DexManager.isPackageSelectedToRunOobInternal(
                isDefaultEnabled, defaultWhitelist, overrideEnabled, overrideWhitelist,
                packageNamesInSameProcess);
                isDefaultEnabled, whitelist, packageNamesInSameProcess);
    }

    @Test
    public void testOobPackageSelectionSwitch() {
    public void testOobPackageSelectionDefault() {
        // Feature is off by default, not overriden
        assertFalse(shouldPackageRunOob(false, "ALL", null, null, null));

        // Feature is off by default, overriden
        assertTrue(shouldPackageRunOob(false, "ALL", "true", "ALL", null));
        assertFalse(shouldPackageRunOob(false, "ALL", "false", null, null));
        assertFalse(shouldPackageRunOob(false, "ALL", "false", "ALL", null));
        assertFalse(shouldPackageRunOob(false, "ALL", "false", null, null));

        // Feature is on by default, not overriden
        assertTrue(shouldPackageRunOob(true, "ALL", null, null, null));
        assertTrue(shouldPackageRunOob(true, "ALL", null, null, null));
        assertTrue(shouldPackageRunOob(true, "ALL", null, "ALL", null));

        // Feature is on by default, overriden
        assertTrue(shouldPackageRunOob(true, "ALL", "true", null, null));
        assertTrue(shouldPackageRunOob(true, "ALL", "true", "ALL", null));
        assertFalse(shouldPackageRunOob(true, "ALL", "false", null, null));
        assertFalse(shouldPackageRunOob(true, "ALL", "false", "ALL", null));
        assertFalse(shouldPackageRunOob(false, "ALL", null));
    }

    @Test
@@ -734,24 +715,19 @@ public class DexManagerTests {
        final Collection<String> runningPackages = Arrays.asList("com.priv.app1", "com.priv.app2");

        // Feature is off, whitelist does not matter
        assertFalse(shouldPackageRunOob(false, kWhitelistApp0, null, null, runningPackages));
        assertFalse(shouldPackageRunOob(false, kWhitelistApp1, null, null, runningPackages));
        assertFalse(shouldPackageRunOob(false, "", null, kWhitelistApp1, runningPackages));
        assertFalse(shouldPackageRunOob(false, "", null, "ALL", runningPackages));
        assertFalse(shouldPackageRunOob(false, "ALL", null, "ALL", runningPackages));
        assertFalse(shouldPackageRunOob(false, "ALL", null, "", runningPackages));

        // Feature is on, app not in default or overridden whitelist
        assertFalse(shouldPackageRunOob(true, kWhitelistApp0, null, null, runningPackages));
        assertFalse(shouldPackageRunOob(true, "", null, kWhitelistApp0, runningPackages));
        assertFalse(shouldPackageRunOob(true, "ALL", null, kWhitelistApp0, runningPackages));

        // Feature is on, app in default or overridden whitelist
        assertTrue(shouldPackageRunOob(true, kWhitelistApp1, null, null, runningPackages));
        assertTrue(shouldPackageRunOob(true, kWhitelistApp2, null, null, runningPackages));
        assertTrue(shouldPackageRunOob(true, kWhitelistApp1AndApp2, null, null, runningPackages));
        assertTrue(shouldPackageRunOob(true, kWhitelistApp1, null, "ALL", runningPackages));
        assertTrue(shouldPackageRunOob(true, "", null, kWhitelistApp1, runningPackages));
        assertTrue(shouldPackageRunOob(true, "ALL", null, kWhitelistApp1, runningPackages));
        assertFalse(shouldPackageRunOob(false, kWhitelistApp0, runningPackages));
        assertFalse(shouldPackageRunOob(false, kWhitelistApp1, runningPackages));
        assertFalse(shouldPackageRunOob(false, "", runningPackages));
        assertFalse(shouldPackageRunOob(false, "ALL", runningPackages));

        // Feature is on, app not in whitelist
        assertFalse(shouldPackageRunOob(true, kWhitelistApp0, runningPackages));
        assertFalse(shouldPackageRunOob(true, "", runningPackages));

        // Feature is on, app in whitelist
        assertTrue(shouldPackageRunOob(true, kWhitelistApp1, runningPackages));
        assertTrue(shouldPackageRunOob(true, kWhitelistApp2, runningPackages));
        assertTrue(shouldPackageRunOob(true, kWhitelistApp1AndApp2, runningPackages));
        assertTrue(shouldPackageRunOob(true, "ALL", runningPackages));
    }
}