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

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

Merge "Update decor insets by checking frame of all insets sources" into main

parents 1739de56 b90aef7b
Loading
Loading
Loading
Loading
+30 −9
Original line number Diff line number Diff line
@@ -1913,12 +1913,9 @@ public class DisplayPolicy {
             */
            final Rect mConfigFrame = new Rect();

            /** The count of insets sources when calculating this info. */
            int mLastInsetsSourceCount;

            private boolean mNeedUpdate = true;

            void update(DisplayContent dc, int rotation, int w, int h) {
            InsetsState update(DisplayContent dc, int rotation, int w, int h) {
                final DisplayFrames df = new DisplayFrames();
                dc.updateDisplayFrames(df, rotation, w, h);
                dc.getDisplayPolicy().simulateLayoutDisplay(df);
@@ -1935,8 +1932,8 @@ public class DisplayPolicy {
                mNonDecorFrame.inset(mNonDecorInsets);
                mConfigFrame.set(displayFrame);
                mConfigFrame.inset(mConfigInsets);
                mLastInsetsSourceCount = dc.getDisplayPolicy().mInsetsSourceWindowsExceptIme.size();
                mNeedUpdate = false;
                return insetsState;
            }

            void set(Info other) {
@@ -1944,7 +1941,6 @@ public class DisplayPolicy {
                mConfigInsets.set(other.mConfigInsets);
                mNonDecorFrame.set(other.mNonDecorFrame);
                mConfigFrame.set(other.mConfigFrame);
                mLastInsetsSourceCount = other.mLastInsetsSourceCount;
                mNeedUpdate = false;
            }

@@ -1997,6 +1993,29 @@ public class DisplayPolicy {
            }
        }

        static boolean hasInsetsFrameDiff(InsetsState s1, InsetsState s2, int insetsTypes) {
            int insetsCount1 = 0;
            for (int i = s1.sourceSize() - 1; i >= 0; i--) {
                final InsetsSource source1 = s1.sourceAt(i);
                if ((source1.getType() & insetsTypes) == 0) {
                    continue;
                }
                insetsCount1++;
                final InsetsSource source2 = s2.peekSource(source1.getId());
                if (source2 == null || !source2.getFrame().equals(source1.getFrame())) {
                    return true;
                }
            }
            int insetsCount2 = 0;
            for (int i = s2.sourceSize() - 1; i >= 0; i--) {
                final InsetsSource source2 = s2.sourceAt(i);
                if ((source2.getType() & insetsTypes) != 0) {
                    insetsCount2++;
                }
            }
            return insetsCount1 != insetsCount2;
        }

        private static class Cache {
            /**
             * If {@link #mPreserveId} is this value, it is in the middle of updating display
@@ -2031,12 +2050,14 @@ public class DisplayPolicy {
        final int dw = displayFrames.mWidth;
        final int dh = displayFrames.mHeight;
        final DecorInsets.Info newInfo = mDecorInsets.mTmpInfo;
        newInfo.update(mDisplayContent, rotation, dw, dh);
        final InsetsState newInsetsState = newInfo.update(mDisplayContent, rotation, dw, dh);
        final DecorInsets.Info currentInfo = getDecorInsetsInfo(rotation, dw, dh);
        if (newInfo.mConfigFrame.equals(currentInfo.mConfigFrame)) {
            // Even if the config frame is not changed in current rotation, it may change the
            // insets in other rotations if the source count is changed.
            if (newInfo.mLastInsetsSourceCount != currentInfo.mLastInsetsSourceCount) {
            // insets in other rotations if the frame of insets source is changed.
            final InsetsState currentInsetsState = mDisplayContent.mDisplayFrames.mInsetsState;
            if (DecorInsets.hasInsetsFrameDiff(
                    newInsetsState, currentInsetsState, mService.mConfigTypes)) {
                for (int i = mDecorInsets.mInfoForRotation.length - 1; i >= 0; i--) {
                    if (i != rotation) {
                        final boolean flipSize = (i + rotation) % 2 == 1;
+8 −0
Original line number Diff line number Diff line
@@ -417,6 +417,8 @@ public class DisplayPolicyTests extends WindowTestsBase {
                    di.logicalWidth, di.logicalHeight).mConfigInsets.top);
        }

        // Flush the pending change (DecorInsets.Info#mNeedUpdate) for the rotation to be tested.
        displayPolicy.getDecorInsetsInfo(Surface.ROTATION_90, di.logicalHeight, di.logicalWidth);
        // Add a window that provides the same insets in current rotation. But it specifies
        // different insets in other rotations.
        final WindowState bar2 = createWindow(null, navbar.mAttrs.type, "bar2");
@@ -446,6 +448,12 @@ public class DisplayPolicyTests extends WindowTestsBase {
        // The insets in other rotations should be still updated.
        assertEquals(doubleHeightFor90, displayPolicy.getDecorInsetsInfo(Surface.ROTATION_90,
                di.logicalHeight, di.logicalWidth).mConfigInsets.bottom);
        // Restore to previous height and the insets can still be updated.
        bar2.mAttrs.paramsForRotation[Surface.ROTATION_90].providedInsets[0].setInsetsSize(
                Insets.of(0, 0, 0, NAV_BAR_HEIGHT));
        assertFalse(displayPolicy.updateDecorInsetsInfo());
        assertEquals(NAV_BAR_HEIGHT, displayPolicy.getDecorInsetsInfo(Surface.ROTATION_90,
                di.logicalHeight, di.logicalWidth).mConfigInsets.bottom);

        navbar.removeIfPossible();
        bar2.removeIfPossible();