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

Commit 83db1fee authored by Riddle Hsu's avatar Riddle Hsu
Browse files

Use current insets source visibility for display switch

The preserved insets is a snapshot from display's insets state,
so it may store an invisible insets source if keyguard becomes
active when folding. Then when unfolding to apps, the restored
insets should respect the requested visibility from apps.

Fix: 433656558
Flag: EXEMPT BUGFIX
Test: atest DisplayPolicyTests#testSwitchDecorInsets
Test: Set fold mode to "Swipe up to continue".
      Set navigation mode to 3 button.
      Unfold the device, the app should get visible navbar insets.
Change-Id: If462a4c5432102f5425c2e7189093622ca9ea402
parent e8ce1497
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 */);