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

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

Merge "Preserve decor insets cache if screen is not turned on" into main

parents 2b48314d d896230f
Loading
Loading
Loading
Loading
+1 −12
Original line number Diff line number Diff line
@@ -2070,8 +2070,7 @@ public class DisplayPolicy {
            }
            return false;
        }
        if (mCachedDecorInsets != null && !mCachedDecorInsets.canPreserve()
                && !mDisplayContent.isSleeping()) {
        if (mCachedDecorInsets != null && !mCachedDecorInsets.canPreserve() && mScreenOnFully) {
            mCachedDecorInsets = null;
        }
        mDecorInsets.invalidate();
@@ -2136,16 +2135,6 @@ public class DisplayPolicy {
        }
        mCachedDecorInsets.mPreserveId =
                mDisplayContent.mTransitionController.getCollectingTransitionId();
        // The validator will run after the transition is finished. So if the insets are changed
        // during the transition, it can update to the latest state.
        mDisplayContent.mTransitionController.mStateValidators.add(() -> {
            // The insets provider client may defer to change its window until screen is on. So
            // only validate when awake to avoid the cache being always dropped.
            if (!mDisplayContent.isSleeping() && updateDecorInsetsInfo()) {
                Slog.d(TAG, "Insets changed after display switch transition");
                mDisplayContent.sendNewConfiguration();
            }
        });
    }

    @NavigationBarPosition
+19 −0
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;

import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn;
import static com.android.server.policy.WindowManagerPolicy.NAV_BAR_BOTTOM;

import static org.junit.Assert.assertEquals;
@@ -388,6 +389,24 @@ public class DisplayPolicyTests extends WindowTestsBase {
        // The current insets are restored from cache directly.
        assertEquals(prevConfigFrame, displayPolicy.getDecorInsetsInfo(info.rotation,
                info.logicalWidth, info.logicalHeight).mConfigFrame);

        // If screen is not fully turned on, then the cache should be preserved.
        displayPolicy.screenTurnedOff();
        final TransitionController transitionController = mDisplayContent.mTransitionController;
        spyOn(transitionController);
        doReturn(true).when(transitionController).isCollecting();
        doReturn(Integer.MAX_VALUE).when(transitionController).getCollectingTransitionId();
        // Make CachedDecorInsets.canPreserve return false.
        displayPolicy.physicalDisplayUpdated();
        assertFalse(displayPolicy.shouldKeepCurrentDecorInsets());
        displayPolicy.getDecorInsetsInfo(info.rotation, info.logicalWidth, info.logicalHeight)
                .mConfigFrame.offset(1, 1);
        // Even if CachedDecorInsets.canPreserve returns false, the cache won't be cleared.
        displayPolicy.updateDecorInsetsInfo();
        // Successful to restore from cache.
        displayPolicy.updateCachedDecorInsets();
        assertEquals(prevConfigFrame, displayPolicy.getDecorInsetsInfo(info.rotation,
                info.logicalWidth, info.logicalHeight).mConfigFrame);
    }

    @Test