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

Commit f0f68f46 authored by Riddle Hsu's avatar Riddle Hsu Committed by Android (Google) Code Review
Browse files

Merge "Use current insets source visibility for display switch" into main

parents a0763385 83db1fee
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -2311,9 +2311,11 @@ public class DisplayPolicy {
        final ArrayList<InsetsSource> preservedSources = mCachedDecorInsets.mPreservedInsets;
        final InsetsState state = copyState ? new InsetsState(originalState) : originalState;
        for (int i = preservedSources.size() - 1; i >= 0; i--) {
            final InsetsSource cacheSource = preservedSources.get(i);
            if (state.peekSource(cacheSource.getId()) != null) {
                state.addSource(new InsetsSource(cacheSource));
            final InsetsSource cachedSource = preservedSources.get(i);
            final InsetsSource originalSource = state.peekSource(cachedSource.getId());
            if (originalSource != null) {
                state.addSource(new InsetsSource(cachedSource)
                        .setVisible(originalSource.isVisible()));
            }
        }
        return state;
+12 −6
Original line number Diff line number Diff line
@@ -378,8 +378,9 @@ public class DisplayPolicyTests extends WindowTestsBase {
        provider.setServerVisible(true);
        provider.updateSourceFrame(bar.getFrame());

        final InsetsState prevInsetsState = new InsetsState();
        prevInsetsState.addSource(new InsetsSource(provider.getSource()));
        final InsetsSource prevInsetsSource = new InsetsSource(provider.getSource());
        // Assume that the insets provider is temporarily invisible during switching.
        provider.getSource().setVisible(false);

        final DisplayPolicy displayPolicy = mDisplayContent.getDisplayPolicy();
        final DisplayInfo info = mDisplayContent.getDisplayInfo();
@@ -406,12 +407,17 @@ public class DisplayPolicyTests extends WindowTestsBase {
        // Assume that the InsetsSource in current InsetsState is not updated yet. And it will be
        // replaced by the one in cache.
        InsetsState currentInsetsState = new InsetsState();
        final InsetsSource prevSource = new InsetsSource(provider.getSource());
        prevSource.getFrame().scale(0.5f);
        currentInsetsState.addSource(prevSource);
        final InsetsSource currentSource = new InsetsSource(provider.getSource());
        currentSource.setVisible(true);
        currentSource.getFrame().scale(0.5f);
        currentInsetsState.addSource(currentSource);
        currentInsetsState = mDisplayContent.getInsetsPolicy().adjustInsetsForWindow(
                win, currentInsetsState);
        assertEquals(prevInsetsState.peekSource(insetsId), currentInsetsState.peekSource(insetsId));
        final InsetsSource adjustedSource = currentInsetsState.peekSource(insetsId);
        assertNotNull(adjustedSource);
        // The frame is restored from previous state, but the visibility still uses current state.
        assertEquals(prevInsetsSource.getFrame(), adjustedSource.getFrame());
        assertTrue(adjustedSource.isVisible());

        // If screen is not fully turned on, then the cache should be preserved.
        displayPolicy.screenTurnedOff(false /* acquireSleepToken */);