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

Commit 143ae495 authored by Riddle Hsu's avatar Riddle Hsu
Browse files

Update window configuration for reused ResourcesImpl

This aligns the same behavior as if a new ResourcesImpl is created
for a override configuration with different WindowConfiguration:
The resource configuration has the values as override configuration.

The update of windowConfiguration is needed because
Display#getRotation() reads the rotation from WindowConfiguration#
getDisplayRotation() in resource configuration.

The case may happen when display rotates 180 degree that there is
no size change (all public fields of Configuration are the same) but
only the rotation in WindowConfiguration.

Bug: 413273054
Flag: android.content.res.ignore_non_public_config_diff_for_resources_key
Test: atest FrameworksCoreTests:ResourcesManagerTest# \
            testUpdateResourcesForActivityUpdateWindowConfiguration
Test: atest AttachedSurfaceControlTest# \
            testOnBufferTransformHintChangesFromLandToSea
Change-Id: Iad35be1c9a6dc9517b9a8febae36e67349f70163
parent 7a299db3
Loading
Loading
Loading
Loading
+14 −1
Original line number Diff line number Diff line
@@ -1381,10 +1381,23 @@ public class ResourcesManager {
                    // constructions.
                    final ResourcesImpl resourcesImpl =
                            findOrCreateResourcesImplForKeyLocked(newKey);
                    if (resourcesImpl != null && resourcesImpl != resources.getImpl()) {
                    if (resourcesImpl == null) {
                        continue;
                    }
                    if (resourcesImpl != resources.getImpl()) {
                        // Set the ResourcesImpl, updating it for all users of this Resources
                        // object.
                        resources.setImpl(resourcesImpl);
                    } else if (android.content.res.Flags
                            .ignoreNonPublicConfigDiffForResourcesKey()) {
                        // If the ResourcesImpl is reused, also update fields not related to
                        // resources in case the app accesses WindowConfiguration, e.g. rotation.
                        final Configuration resConfig = resourcesImpl.getConfiguration();
                        resConfig.windowConfiguration.updateFrom(
                                newKey.mOverrideConfiguration.windowConfiguration);
                        if (newKey.mOverrideConfiguration.seq != 0) {
                            resConfig.seq = newKey.mOverrideConfiguration.seq;
                        }
                    }
                }
            }
+16 −0
Original line number Diff line number Diff line
@@ -373,6 +373,22 @@ public class ResourcesManagerTest {
                defaultDisplayResources.getDisplayMetrics().widthPixels);
    }

    @Test
    @SmallTest
    public void testUpdateResourcesForActivityUpdateWindowConfiguration() {
        final Binder activity = new Binder();
        final Configuration overrideConfig = new Configuration();
        final Resources resources = mResourcesManager.getResources(
                activity, APP_ONE_RES_DIR, null, null, null, null, Display.DEFAULT_DISPLAY,
                overrideConfig, CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO, null, null);
        overrideConfig.windowConfiguration.getBounds().set(100, 100, 600, 1200);
        mResourcesManager.updateResourcesForActivity(activity, overrideConfig,
                Display.DEFAULT_DISPLAY);

        assertEquals(overrideConfig.windowConfiguration,
                resources.getConfiguration().windowConfiguration);
    }

    @Test
    @SmallTest
    @RequiresFlagsEnabled(Flags.FLAG_IGNORE_NON_PUBLIC_CONFIG_DIFF_FOR_RESOURCES_KEY)