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

Commit e53cd2c8 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Update window configuration for reused ResourcesImpl" into main

parents 7472730c 143ae495
Loading
Loading
Loading
Loading
+14 −1
Original line number Original line Diff line number Diff line
@@ -1381,10 +1381,23 @@ public class ResourcesManager {
                    // constructions.
                    // constructions.
                    final ResourcesImpl resourcesImpl =
                    final ResourcesImpl resourcesImpl =
                            findOrCreateResourcesImplForKeyLocked(newKey);
                            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
                        // Set the ResourcesImpl, updating it for all users of this Resources
                        // object.
                        // object.
                        resources.setImpl(resourcesImpl);
                        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 Original line Diff line number Diff line
@@ -373,6 +373,22 @@ public class ResourcesManagerTest {
                defaultDisplayResources.getDisplayMetrics().widthPixels);
                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
    @Test
    @SmallTest
    @SmallTest
    @RequiresFlagsEnabled(Flags.FLAG_IGNORE_NON_PUBLIC_CONFIG_DIFF_FOR_RESOURCES_KEY)
    @RequiresFlagsEnabled(Flags.FLAG_IGNORE_NON_PUBLIC_CONFIG_DIFF_FOR_RESOURCES_KEY)