From 6cb16984ea12f42ee1c1546e03f6fd3a29fd93e3 Mon Sep 17 00:00:00 2001 From: chaviw Date: Tue, 14 Jul 2020 11:27:49 -0700 Subject: [PATCH] Fix some inset issues 1. Rotate the window bounds so they are in the orientation of the requested display frame. In most cases, this will do nothing. This is specifically meant to ensure fixed rotation works 2. Ensure windows top and left are also adjusted if the bounds are not at 0, 0 Test: Open app in fixed rotation Test: DisplayAreaOrganizer Test app Test: DisplayPolicyLayoutTests Rotate window bounds if display frame in different orientation Change-Id: I5444456eb7fc0e1538596ae0d3a2faf3419c3e23 --- .../com/android/server/wm/DisplayPolicy.java | 48 ++++++++++++++----- .../server/wm/DisplayPolicyLayoutTests.java | 18 ++++--- 2 files changed, 46 insertions(+), 20 deletions(-) diff --git a/services/core/java/com/android/server/wm/DisplayPolicy.java b/services/core/java/com/android/server/wm/DisplayPolicy.java index b4ead8eccf02e..e6cf85d6b2656 100644 --- a/services/core/java/com/android/server/wm/DisplayPolicy.java +++ b/services/core/java/com/android/server/wm/DisplayPolicy.java @@ -373,7 +373,10 @@ public class DisplayPolicy { private static final Rect sTmpDisplayCutoutSafeExceptMaybeBarsRect = new Rect(); private static final Rect sTmpRect = new Rect(); private static final Rect sTmpNavFrame = new Rect(); + private static final Rect sTmpStatusFrame = new Rect(); + private static final Rect sTmpScreenDecorFrame = new Rect(); private static final Rect sTmpLastParentFrame = new Rect(); + private static final Rect sTmpDisplayFrameBounds = new Rect(); private WindowState mTopFullscreenOpaqueWindowState; private WindowState mTopFullscreenOpaqueOrDimmingWindowState; @@ -997,6 +1000,22 @@ public class DisplayPolicy { return ADD_OKAY; } + private void getRotatedWindowBounds(DisplayFrames displayFrames, WindowState windowState, + Rect outBounds) { + outBounds.set(windowState.getBounds()); + + int windowRotation = windowState.getWindowConfiguration().getRotation(); + if (windowRotation == displayFrames.mRotation) { + return; + } + + // Get displayFrames bounds + sTmpDisplayFrameBounds.set(0, 0, displayFrames.mDisplayWidth, displayFrames.mDisplayHeight); + // Rotate the WindowState's bounds based on the displayFrames rotation + mDisplayContent.rotateBounds(sTmpDisplayFrameBounds, windowRotation, + displayFrames.mRotation, outBounds); + } + /** * Called when a window is being added to the system. Must not throw an exception. * @@ -1020,7 +1039,6 @@ public class DisplayPolicy { mStatusBarController.setWindow(win); final TriConsumer frameProvider = (displayFrames, windowState, rect) -> { - rect.set(windowState.getFrameLw()); rect.bottom = rect.top + getStatusBarHeight(displayFrames); }; mDisplayContent.setInsetProvider(ITYPE_STATUS_BAR, win, frameProvider); @@ -1041,7 +1059,7 @@ public class DisplayPolicy { displayFrames.mDisplayHeight, displayFrames.mRotation) == NAV_BAR_BOTTOM && !mNavButtonForcedVisible) { - sTmpRect.set(windowState.getFrameLw()); + sTmpRect.set(inOutFrame); sTmpRect.intersectUnchecked(displayFrames.mDisplayCutoutSafe); inOutFrame.top = sTmpRect.bottom - getNavigationBarHeight(displayFrames.mRotation, @@ -1669,11 +1687,13 @@ public class DisplayPolicy { if (isSimulatedLayout) { w.setSimulatedWindowFrames(simulatedFrames); } - Rect bounds = w.getBounds(); + getRotatedWindowBounds(displayFrames, w, sTmpScreenDecorFrame); final WindowFrames windowFrames = w.getLayoutingWindowFrames(); - windowFrames.setFrames(bounds /* parentFrame */, bounds /* displayFrame */, - bounds /* contentFrame */, bounds /* visibleFrame */, sTmpRect /* decorFrame */, - bounds /* stableFrame */); + windowFrames.setFrames(sTmpScreenDecorFrame /* parentFrame */, + sTmpScreenDecorFrame /* displayFrame */, + sTmpScreenDecorFrame /* contentFrame */, + sTmpScreenDecorFrame /* visibleFrame */, sTmpRect /* decorFrame */, + sTmpScreenDecorFrame /* stableFrame */); try { w.computeFrame(displayFrames); } finally { @@ -1731,12 +1751,13 @@ public class DisplayPolicy { return false; } // apply any status bar insets - Rect bounds = mStatusBar.getBounds(); + getRotatedWindowBounds(displayFrames, mStatusBar, sTmpStatusFrame); sTmpRect.setEmpty(); final WindowFrames windowFrames = mStatusBar.getLayoutingWindowFrames(); - windowFrames.setFrames(bounds /* parentFrame */, bounds /* displayFrame */, - bounds /* contentFrame */, bounds /* visibleFrame */, sTmpRect /* decorFrame */, - bounds /* stableFrame */); + windowFrames.setFrames(sTmpStatusFrame /* parentFrame */, + sTmpStatusFrame /* displayFrame */, sTmpStatusFrame /* contentFrame */, + sTmpStatusFrame /* visibleFrame */, sTmpRect /* decorFrame */, + sTmpStatusFrame /* stableFrame */); // Let the status bar determine its size. mStatusBar.computeFrame(displayFrames); @@ -1807,7 +1828,7 @@ public class DisplayPolicy { final Rect dockFrame = displayFrames.mDock; final int navBarPosition = navigationBarPosition(displayWidth, displayHeight, rotation); - navigationFrame.set(mNavigationBar.getBounds()); + getRotatedWindowBounds(displayFrames, mNavigationBar, navigationFrame); final Rect cutoutSafeUnrestricted = sTmpRect; cutoutSafeUnrestricted.set(displayFrames.mUnrestricted); @@ -2047,7 +2068,8 @@ public class DisplayPolicy { final @InsetsType int typesToFit = attrs.getFitInsetsTypes(); final @InsetsSide int sidesToFit = attrs.getFitInsetsSides(); final ArraySet types = InsetsState.toInternalType(typesToFit); - final Rect dfu = win.getBounds(); + getRotatedWindowBounds(displayFrames, win, sTmpRect); + final Rect dfu = sTmpRect; Insets insets = Insets.of(0, 0, 0, 0); for (int i = types.size() - 1; i >= 0; i--) { final InsetsSource source = mDisplayContent.getInsetsPolicy() @@ -2062,7 +2084,7 @@ public class DisplayPolicy { final int top = (sidesToFit & Side.TOP) != 0 ? insets.top : 0; final int right = (sidesToFit & Side.RIGHT) != 0 ? insets.right : 0; final int bottom = (sidesToFit & Side.BOTTOM) != 0 ? insets.bottom : 0; - df.set(left, top, dfu.right - right, dfu.bottom - bottom); + df.set(dfu.left + left, dfu.top + top, dfu.right - right, dfu.bottom - bottom); if (attached == null) { pf.set(df); vf.set(adjust != SOFT_INPUT_ADJUST_NOTHING diff --git a/services/tests/wmtests/src/com/android/server/wm/DisplayPolicyLayoutTests.java b/services/tests/wmtests/src/com/android/server/wm/DisplayPolicyLayoutTests.java index f9de379943503..8fc97701bdf0c 100644 --- a/services/tests/wmtests/src/com/android/server/wm/DisplayPolicyLayoutTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/DisplayPolicyLayoutTests.java @@ -122,9 +122,14 @@ public class DisplayPolicyLayoutTests extends DisplayPolicyTestsBase { updateDisplayFrames(); } - public void setRotation(int rotation) { + public void setRotation(int rotation, boolean includingWindows) { mRotation = rotation; updateDisplayFrames(); + if (includingWindows) { + mNavBarWindow.getWindowConfiguration().setRotation(rotation); + mStatusBarWindow.getWindowConfiguration().setRotation(rotation); + mWindow.getWindowConfiguration().setRotation(rotation); + } } public void addDisplayCutout() { @@ -483,8 +488,7 @@ public class DisplayPolicyLayoutTests extends DisplayPolicyTestsBase { @Test public void layoutWindowLw_withDisplayCutout_landscape() { addDisplayCutout(); - setRotation(ROTATION_90); - + setRotation(ROTATION_90, true /* includingWindows */); mWindow.mAttrs.flags = FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS; mWindow.mAttrs.setFitInsetsTypes(0 /* types */); @@ -504,7 +508,7 @@ public class DisplayPolicyLayoutTests extends DisplayPolicyTestsBase { @Test public void layoutWindowLw_withDisplayCutout_seascape() { addDisplayCutout(); - setRotation(ROTATION_270); + setRotation(ROTATION_270, true /* includingWindows */); mWindow.mAttrs.flags = FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS; @@ -525,7 +529,7 @@ public class DisplayPolicyLayoutTests extends DisplayPolicyTestsBase { @Test public void layoutWindowLw_withDisplayCutout_fullscreen_landscape() { addDisplayCutout(); - setRotation(ROTATION_90); + setRotation(ROTATION_90, true /* includingWindows */); mWindow.mAttrs.flags = FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS; @@ -566,7 +570,7 @@ public class DisplayPolicyLayoutTests extends DisplayPolicyTestsBase { @Test public void layoutWindowLw_withDisplayCutout_fullscreenInCutout_landscape() { addDisplayCutout(); - setRotation(ROTATION_90); + setRotation(ROTATION_90, true /* includingWindows */); mWindow.mAttrs.flags = FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS; @@ -784,7 +788,7 @@ public class DisplayPolicyLayoutTests extends DisplayPolicyTestsBase { @Test public void testSimulateLayoutDisplay() { assertSimulateLayoutSameDisplayFrames(); - setRotation(ROTATION_90); + setRotation(ROTATION_90, false /* includingWindows */); assertSimulateLayoutSameDisplayFrames(); addDisplayCutout(); assertSimulateLayoutSameDisplayFrames();