From 2eee0e623a891be2aaea8f50bdea13316d750631 Mon Sep 17 00:00:00 2001 From: Riddle Hsu Date: Mon, 26 Apr 2021 23:05:02 +0800 Subject: [PATCH] Fix creating unexpected letterbox surfaces With fixed rotation, the rotated activity should compare bounds with rotated display. Otherwise AR#isLetterboxedAppWindow will return false and create unnecessary letterbox surfaces. Note that fixed rotation only applies when display area matches display bounds. The method matchesDisplayBounds is removed because the only usage in WS#computeFrame uses parent frame, that is computed from configuration bounds which doesn't tie to an actual display. Fix: 186407859 Test: DisplayContentTests#testApplyTopFixedRotationTransform Change-Id: I8cd978844f0ba8f9739f90c5c624d0c5fc3dc339 --- .../com/android/server/wm/DisplayContent.java | 2 +- .../com/android/server/wm/WindowState.java | 20 ++++++++----------- .../server/wm/DisplayContentTests.java | 2 ++ 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/services/core/java/com/android/server/wm/DisplayContent.java b/services/core/java/com/android/server/wm/DisplayContent.java index 0c4e1a2c0aaed..e28ab26b0c1c2 100644 --- a/services/core/java/com/android/server/wm/DisplayContent.java +++ b/services/core/java/com/android/server/wm/DisplayContent.java @@ -1575,7 +1575,7 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp } return false; } - if (!r.getParent().matchParentBounds()) { + if (!r.getDisplayArea().matchParentBounds()) { // Because the fixed rotated configuration applies to activity directly, if its parent // has it own policy for bounds, the activity bounds based on parent is unknown. return false; diff --git a/services/core/java/com/android/server/wm/WindowState.java b/services/core/java/com/android/server/wm/WindowState.java index 905534f7bd1f1..ea21c6e0a664e 100644 --- a/services/core/java/com/android/server/wm/WindowState.java +++ b/services/core/java/com/android/server/wm/WindowState.java @@ -1265,7 +1265,7 @@ class WindowState extends WindowContainer implements WindowManagerP mHaveFrame = true; final Task task = getTask(); - final boolean isFullscreenAndFillsDisplay = !inMultiWindowMode() && matchesDisplayBounds(); + final boolean isFullscreenAndFillsArea = !inMultiWindowMode() && matchesDisplayAreaBounds(); final boolean windowsAreFloating = task != null && task.isFloating(); final DisplayContent dc = getDisplayContent(); final DisplayInfo displayInfo = getDisplayInfo(); @@ -1290,7 +1290,7 @@ class WindowState extends WindowContainer implements WindowManagerP : isImeLayeringTarget(); final boolean isImeTarget = imeWin != null && imeWin.isVisibleNow() && isInputMethodAdjustTarget; - if (isFullscreenAndFillsDisplay || layoutInParentFrame()) { + if (isFullscreenAndFillsArea || layoutInParentFrame()) { // We use the parent frame as the containing frame for fullscreen and child windows windowFrames.mContainingFrame.set(windowFrames.mParentFrame); layoutDisplayFrame = windowFrames.mDisplayFrame; @@ -2272,19 +2272,15 @@ class WindowState extends WindowContainer implements WindowManagerP && mWindowFrames.mFrame.bottom >= displayInfo.appHeight; } - private boolean matchesDisplayBounds() { - final Rect displayBounds = mToken.getFixedRotationTransformDisplayBounds(); - if (displayBounds != null) { - // If the rotated display bounds are available, the window bounds are also rotated. - return displayBounds.equals(getBounds()); - } - return getDisplayContent().getBounds().equals(getBounds()); - } - boolean matchesDisplayAreaBounds() { + final Rect rotatedDisplayBounds = mToken.getFixedRotationTransformDisplayBounds(); + if (rotatedDisplayBounds != null) { + // If the rotated display bounds are available, the window bounds are also rotated. + return rotatedDisplayBounds.equals(getBounds()); + } final DisplayArea displayArea = getDisplayArea(); if (displayArea == null) { - return matchesDisplayBounds(); + return getDisplayContent().getBounds().equals(getBounds()); } return displayArea.getBounds().equals(getBounds()); } diff --git a/services/tests/wmtests/src/com/android/server/wm/DisplayContentTests.java b/services/tests/wmtests/src/com/android/server/wm/DisplayContentTests.java index d3a825bb57a2a..e1eef762059ee 100644 --- a/services/tests/wmtests/src/com/android/server/wm/DisplayContentTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/DisplayContentTests.java @@ -1320,6 +1320,8 @@ public class DisplayContentTests extends WindowTestsBase { app.setRequestedOrientation(newOrientation); assertTrue(app.isFixedRotationTransforming()); + assertTrue(mAppWindow.matchesDisplayAreaBounds()); + assertFalse(mAppWindow.isLetterboxedAppWindow()); assertTrue(mDisplayContent.getDisplayRotation().shouldRotateSeamlessly( ROTATION_0 /* oldRotation */, ROTATION_90 /* newRotation */, false /* forceUpdate */));