Loading core/java/android/app/ResourcesManager.java +12 −1 Original line number Diff line number Diff line Loading @@ -340,6 +340,9 @@ public class ResourcesManager { @Nullable public WeakReference<Resources> resources; /** Whether this resource is created for the token itself. */ boolean isBaseResource; private ActivityResource() {} } Loading Loading @@ -946,6 +949,9 @@ public class ResourcesManager { activityResource.overrideConfig.setTo(initialOverrideConfig); activityResource.overrideDisplayId = overrideDisplayId; activityResources.activityResources.add(activityResource); if (activityResources.activityResources.size() == 1) { activityResource.isBaseResource = true; } if (DEBUG) { Slog.d(TAG, "- creating new ref=" + resources); Slog.d(TAG, "- setting ref=" + resources + " with impl=" + impl); Loading Loading @@ -1476,8 +1482,13 @@ public class ResourcesManager { // Ensure the new key keeps the expected override display instead of the new token display. displayId = overrideDisplayId != null ? overrideDisplayId : displayId; // Do not use token identify if it is a derived resource (isBaseResource == false) because // if the window configuration is different, the key for derived resource should not find // the ResourcesImpl instance of token resource. final int tokenIdentity = activityResource.isBaseResource ? System.identityHashCode(activityToken) : 0; // Create the new ResourcesKey with the rebased override config. final ResourcesKey newKey = new ResourcesKey(System.identityHashCode(activityToken), final ResourcesKey newKey = new ResourcesKey(tokenIdentity, oldKey.mResDir, oldKey.mSplitResDirs, oldKey.mOverlayPaths, oldKey.mLibDirs, displayId, rebasedOverrideConfig, oldKey.mCompatInfo, oldKey.mLoaders); Loading core/tests/coretests/src/android/content/res/ResourcesManagerTest.java +29 −0 Original line number Diff line number Diff line Loading @@ -407,6 +407,35 @@ public class ResourcesManagerTest { resources2.getConfiguration().windowConfiguration); } @Test @SmallTest public void testUpdateActivityResourcesOverrideWindowConfiguration() { final Binder activity = new Binder(); final Resources activityResources = mResourcesManager.createBaseTokenResources( activity, null, null, null, null, null, Display.DEFAULT_DISPLAY, null, CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO, null, null); final Configuration overrideConfig = new Configuration(); overrideConfig.windowConfiguration.getBounds().set(0, 0, 500, 1000); // Simulate the usage of Activity#createConfigurationContext. final Resources overrideConfigResources = mResourcesManager.getResources( activity, null, null, null, null, null, Display.DEFAULT_DISPLAY, overrideConfig, CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO, null, null); // This is a key step to make the non-window configuration fields have the same value // (which were assigned from ResourcesManager#applyDisplayMetricsToConfiguration). And the // following update shouldn't create the ResourcesKey that finds the same ResourcesImpl. final Configuration newActivityOverrideConfig = new Configuration(overrideConfigResources.getConfiguration()); newActivityOverrideConfig.windowConfiguration.getBounds().set(100, 200, 600, 1200); mResourcesManager.updateResourcesForActivity(activity, newActivityOverrideConfig, Display.DEFAULT_DISPLAY); // Verifies that the update applies the configuration to the correct ResourcesImpl. assertEquals(overrideConfig.windowConfiguration.getBounds(), overrideConfigResources.getConfiguration().windowConfiguration.getBounds()); assertEquals(newActivityOverrideConfig.windowConfiguration.getBounds(), activityResources.getConfiguration().windowConfiguration.getBounds()); } @Test @SmallTest @RequiresFlagsEnabled(Flags.FLAG_IGNORE_NON_PUBLIC_CONFIG_DIFF_FOR_RESOURCES_KEY) Loading Loading
core/java/android/app/ResourcesManager.java +12 −1 Original line number Diff line number Diff line Loading @@ -340,6 +340,9 @@ public class ResourcesManager { @Nullable public WeakReference<Resources> resources; /** Whether this resource is created for the token itself. */ boolean isBaseResource; private ActivityResource() {} } Loading Loading @@ -946,6 +949,9 @@ public class ResourcesManager { activityResource.overrideConfig.setTo(initialOverrideConfig); activityResource.overrideDisplayId = overrideDisplayId; activityResources.activityResources.add(activityResource); if (activityResources.activityResources.size() == 1) { activityResource.isBaseResource = true; } if (DEBUG) { Slog.d(TAG, "- creating new ref=" + resources); Slog.d(TAG, "- setting ref=" + resources + " with impl=" + impl); Loading Loading @@ -1476,8 +1482,13 @@ public class ResourcesManager { // Ensure the new key keeps the expected override display instead of the new token display. displayId = overrideDisplayId != null ? overrideDisplayId : displayId; // Do not use token identify if it is a derived resource (isBaseResource == false) because // if the window configuration is different, the key for derived resource should not find // the ResourcesImpl instance of token resource. final int tokenIdentity = activityResource.isBaseResource ? System.identityHashCode(activityToken) : 0; // Create the new ResourcesKey with the rebased override config. final ResourcesKey newKey = new ResourcesKey(System.identityHashCode(activityToken), final ResourcesKey newKey = new ResourcesKey(tokenIdentity, oldKey.mResDir, oldKey.mSplitResDirs, oldKey.mOverlayPaths, oldKey.mLibDirs, displayId, rebasedOverrideConfig, oldKey.mCompatInfo, oldKey.mLoaders); Loading
core/tests/coretests/src/android/content/res/ResourcesManagerTest.java +29 −0 Original line number Diff line number Diff line Loading @@ -407,6 +407,35 @@ public class ResourcesManagerTest { resources2.getConfiguration().windowConfiguration); } @Test @SmallTest public void testUpdateActivityResourcesOverrideWindowConfiguration() { final Binder activity = new Binder(); final Resources activityResources = mResourcesManager.createBaseTokenResources( activity, null, null, null, null, null, Display.DEFAULT_DISPLAY, null, CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO, null, null); final Configuration overrideConfig = new Configuration(); overrideConfig.windowConfiguration.getBounds().set(0, 0, 500, 1000); // Simulate the usage of Activity#createConfigurationContext. final Resources overrideConfigResources = mResourcesManager.getResources( activity, null, null, null, null, null, Display.DEFAULT_DISPLAY, overrideConfig, CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO, null, null); // This is a key step to make the non-window configuration fields have the same value // (which were assigned from ResourcesManager#applyDisplayMetricsToConfiguration). And the // following update shouldn't create the ResourcesKey that finds the same ResourcesImpl. final Configuration newActivityOverrideConfig = new Configuration(overrideConfigResources.getConfiguration()); newActivityOverrideConfig.windowConfiguration.getBounds().set(100, 200, 600, 1200); mResourcesManager.updateResourcesForActivity(activity, newActivityOverrideConfig, Display.DEFAULT_DISPLAY); // Verifies that the update applies the configuration to the correct ResourcesImpl. assertEquals(overrideConfig.windowConfiguration.getBounds(), overrideConfigResources.getConfiguration().windowConfiguration.getBounds()); assertEquals(newActivityOverrideConfig.windowConfiguration.getBounds(), activityResources.getConfiguration().windowConfiguration.getBounds()); } @Test @SmallTest @RequiresFlagsEnabled(Flags.FLAG_IGNORE_NON_PUBLIC_CONFIG_DIFF_FOR_RESOURCES_KEY) Loading