diff options
| author | 2024-01-30 13:00:28 +0000 | |
|---|---|---|
| committer | 2024-01-30 13:00:28 +0000 | |
| commit | 98a766e4a42ffcc6c75d454d65826c45efecfb39 (patch) | |
| tree | c5aea13576848901d973858b9381d040a159b983 | |
| parent | 1739de56092e00526d1dea33005ff8de2f256a5f (diff) | |
| parent | b90aef7bd7890208535d970e8cc296fd82d54741 (diff) | |
Merge "Update decor insets by checking frame of all insets sources" into main
| -rw-r--r-- | services/core/java/com/android/server/wm/DisplayPolicy.java | 39 | ||||
| -rw-r--r-- | services/tests/wmtests/src/com/android/server/wm/DisplayPolicyTests.java | 8 |
2 files changed, 38 insertions, 9 deletions
diff --git a/services/core/java/com/android/server/wm/DisplayPolicy.java b/services/core/java/com/android/server/wm/DisplayPolicy.java index e2bc59bb6550..a7bbc25d0bb1 100644 --- a/services/core/java/com/android/server/wm/DisplayPolicy.java +++ b/services/core/java/com/android/server/wm/DisplayPolicy.java @@ -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; diff --git a/services/tests/wmtests/src/com/android/server/wm/DisplayPolicyTests.java b/services/tests/wmtests/src/com/android/server/wm/DisplayPolicyTests.java index 9e00f927a568..5d14334aaf69 100644 --- a/services/tests/wmtests/src/com/android/server/wm/DisplayPolicyTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/DisplayPolicyTests.java @@ -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(); |