diff --git a/core/java/android/provider/DeviceConfig.java b/core/java/android/provider/DeviceConfig.java index 052e4d0538f2..f935cbf1d846 100644 --- a/core/java/android/provider/DeviceConfig.java +++ b/core/java/android/provider/DeviceConfig.java @@ -73,6 +73,13 @@ public final class DeviceConfig { @SystemApi public static final String NAMESPACE_ACTIVITY_MANAGER = "activity_manager"; + /** + * Namespace for activity manager, specific to the "component alias" feature. We needed a + * different namespace in order to avoid phonetype from resetting it. + * @hide + */ + public static final String NAMESPACE_ACTIVITY_MANAGER_COMPONENT_ALIAS = "activity_manager_ca"; + /** * Namespace for all activity manager related features that are used at the native level. * These features are applied at reboot. diff --git a/services/core/java/com/android/server/am/ActivityManagerConstants.java b/services/core/java/com/android/server/am/ActivityManagerConstants.java index 18e0155cfd34..c42666247e98 100644 --- a/services/core/java/com/android/server/am/ActivityManagerConstants.java +++ b/services/core/java/com/android/server/am/ActivityManagerConstants.java @@ -127,7 +127,15 @@ final class ActivityManagerConstants extends ContentObserver { static final String KEY_KILL_BG_RESTRICTED_CACHED_IDLE = "kill_bg_restricted_cached_idle"; static final String KEY_KILL_BG_RESTRICTED_CACHED_IDLE_SETTLE_TIME = "kill_bg_restricted_cached_idle_settle_time"; + /** + * Note this key is on {@link DeviceConfig#NAMESPACE_ACTIVITY_MANAGER_COMPONENT_ALIAS}. + * @see #mEnableComponentAlias + */ static final String KEY_ENABLE_COMPONENT_ALIAS = "enable_experimental_component_alias"; + /** + * Note this key is on {@link DeviceConfig#NAMESPACE_ACTIVITY_MANAGER_COMPONENT_ALIAS}. + * @see #mComponentAliasOverrides + */ static final String KEY_COMPONENT_ALIAS_OVERRIDES = "component_alias_overrides"; private static final int DEFAULT_MAX_CACHED_PROCESSES = 32; @@ -899,10 +907,6 @@ final class ActivityManagerConstants extends ContentObserver { case KEY_ENABLE_EXTRA_SERVICE_RESTART_DELAY_ON_MEM_PRESSURE: updateEnableExtraServiceRestartDelayOnMemPressure(); break; - case KEY_ENABLE_COMPONENT_ALIAS: - case KEY_COMPONENT_ALIAS_OVERRIDES: - updateComponentAliases(); - break; case KEY_PROCESS_KILL_TIMEOUT: updateProcessKillTimeout(); break; @@ -925,6 +929,26 @@ final class ActivityManagerConstants extends ContentObserver { } }; + private final OnPropertiesChangedListener mOnDeviceConfigChangedForComponentAliasListener = + new OnPropertiesChangedListener() { + @Override + public void onPropertiesChanged(Properties properties) { + for (String name : properties.getKeyset()) { + if (name == null) { + return; + } + switch (name) { + case KEY_ENABLE_COMPONENT_ALIAS: + case KEY_COMPONENT_ALIAS_OVERRIDES: + updateComponentAliases(); + break; + default: + break; + } + } + } + }; + ActivityManagerConstants(Context context, ActivityManagerService service, Handler handler) { super(handler); mService = service; @@ -991,6 +1015,10 @@ final class ActivityManagerConstants extends ContentObserver { DeviceConfig.addOnPropertiesChangedListener(DeviceConfig.NAMESPACE_ACTIVITY_MANAGER, ActivityThread.currentApplication().getMainExecutor(), mOnDeviceConfigChangedListener); + DeviceConfig.addOnPropertiesChangedListener( + DeviceConfig.NAMESPACE_ACTIVITY_MANAGER_COMPONENT_ALIAS, + ActivityThread.currentApplication().getMainExecutor(), + mOnDeviceConfigChangedForComponentAliasListener); loadDeviceConfigConstants(); // The following read from Settings. updateActivityStartsLoggingEnabled(); @@ -1000,6 +1028,9 @@ final class ActivityManagerConstants extends ContentObserver { private void loadDeviceConfigConstants() { mOnDeviceConfigChangedListener.onPropertiesChanged( DeviceConfig.getProperties(DeviceConfig.NAMESPACE_ACTIVITY_MANAGER)); + mOnDeviceConfigChangedForComponentAliasListener.onPropertiesChanged( + DeviceConfig.getProperties( + DeviceConfig.NAMESPACE_ACTIVITY_MANAGER_COMPONENT_ALIAS)); } public void setOverrideMaxCachedProcesses(int value) { @@ -1379,11 +1410,11 @@ final class ActivityManagerConstants extends ContentObserver { private void updateComponentAliases() { mEnableComponentAlias = DeviceConfig.getBoolean( - DeviceConfig.NAMESPACE_ACTIVITY_MANAGER, + DeviceConfig.NAMESPACE_ACTIVITY_MANAGER_COMPONENT_ALIAS, KEY_ENABLE_COMPONENT_ALIAS, DEFAULT_ENABLE_COMPONENT_ALIAS); mComponentAliasOverrides = DeviceConfig.getString( - DeviceConfig.NAMESPACE_ACTIVITY_MANAGER, + DeviceConfig.NAMESPACE_ACTIVITY_MANAGER_COMPONENT_ALIAS, KEY_COMPONENT_ALIAS_OVERRIDES, DEFAULT_COMPONENT_ALIAS_OVERRIDES); mService.mComponentAliasResolver.update(mEnableComponentAlias, mComponentAliasOverrides); diff --git a/tests/componentalias/src/android/content/componentalias/tests/BaseComponentAliasTest.java b/tests/componentalias/src/android/content/componentalias/tests/BaseComponentAliasTest.java index 9658d6f6a698..164f61c4c630 100644 --- a/tests/componentalias/src/android/content/componentalias/tests/BaseComponentAliasTest.java +++ b/tests/componentalias/src/android/content/componentalias/tests/BaseComponentAliasTest.java @@ -37,7 +37,7 @@ public class BaseComponentAliasTest { protected static final Context sContext = InstrumentationRegistry.getTargetContext(); protected static final DeviceConfigStateHelper sDeviceConfig = new DeviceConfigStateHelper( - DeviceConfig.NAMESPACE_ACTIVITY_MANAGER); + DeviceConfig.NAMESPACE_ACTIVITY_MANAGER_COMPONENT_ALIAS); @Before public void enableComponentAliasWithCompatFlag() throws Exception { Assume.assumeTrue(Build.isDebuggable()); diff --git a/tests/componentalias/src/android/content/componentalias/tests/ComponentAliasEnableWithDeviceConfigTest.java b/tests/componentalias/src/android/content/componentalias/tests/ComponentAliasEnableWithDeviceConfigTest.java index 52c6d5b8ae12..ee20379d971a 100644 --- a/tests/componentalias/src/android/content/componentalias/tests/ComponentAliasEnableWithDeviceConfigTest.java +++ b/tests/componentalias/src/android/content/componentalias/tests/ComponentAliasEnableWithDeviceConfigTest.java @@ -28,7 +28,7 @@ import org.junit.Test; public class ComponentAliasEnableWithDeviceConfigTest { protected static final DeviceConfigStateHelper sDeviceConfig = new DeviceConfigStateHelper( - DeviceConfig.NAMESPACE_ACTIVITY_MANAGER); + DeviceConfig.NAMESPACE_ACTIVITY_MANAGER_COMPONENT_ALIAS); @AfterClass public static void restoreDeviceConfig() throws Exception { diff --git a/tests/componentalias/src/android/content/componentalias/tests/ComponentAliasNotSupportedOnUserBuildTest.java b/tests/componentalias/src/android/content/componentalias/tests/ComponentAliasNotSupportedOnUserBuildTest.java index 7935476d6156..0899886fe951 100644 --- a/tests/componentalias/src/android/content/componentalias/tests/ComponentAliasNotSupportedOnUserBuildTest.java +++ b/tests/componentalias/src/android/content/componentalias/tests/ComponentAliasNotSupportedOnUserBuildTest.java @@ -32,7 +32,7 @@ import org.junit.Test; */ public class ComponentAliasNotSupportedOnUserBuildTest { protected static final DeviceConfigStateHelper sDeviceConfig = new DeviceConfigStateHelper( - DeviceConfig.NAMESPACE_ACTIVITY_MANAGER); + DeviceConfig.NAMESPACE_ACTIVITY_MANAGER_COMPONENT_ALIAS); @AfterClass public static void restoreDeviceConfig() throws Exception {