From ca20e306074ea7da837f042f797e39fe2853594e Mon Sep 17 00:00:00 2001 From: Riddle Hsu Date: Fri, 9 Jun 2023 22:28:14 +0800 Subject: [PATCH] Do not apply letterbox when entering PiP Because the design of animation always animate while the activity is in fullscreen appearance, the PiP activity still needs to apply letterbox when exiting PiP. But when entering PiP, the condition is the same: task windowing mode=pinned activity windowing mode=fullscreen So check mWaitForEnteringPinnedMode to exclude the entering case: The order of applying WCT after the enter-pip animation is "set PiP task bounds" -> "clear override of activity windowing mode". The configuration change from "set PiP task bounds" will hit the windowing mode condition as above. This also replaces I83c5d32ef7cff4b3b6c85a698d068935c83c9423. Fix: 283008030 Test: RootWindowContainerTests#testSingleActivityTaskEnterPip Test: adb shell wm set-letterbox-style --cornerRadius 400 An activity declares fixed orientation and requests to enter PiP. The PiP activity should not show weird round corner. Change-Id: I22e294601b628adab9732bec373506c8543f116e --- .../java/com/android/server/wm/ActivityRecord.java | 11 +++++++---- .../com/android/server/wm/RootWindowContainer.java | 5 ++++- .../core/java/com/android/server/wm/WindowState.java | 4 +--- .../android/server/wm/RootWindowContainerTests.java | 11 +++++++++++ 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/services/core/java/com/android/server/wm/ActivityRecord.java b/services/core/java/com/android/server/wm/ActivityRecord.java index 9f16a84415331..3ac655ad5ebb4 100644 --- a/services/core/java/com/android/server/wm/ActivityRecord.java +++ b/services/core/java/com/android/server/wm/ActivityRecord.java @@ -8294,6 +8294,8 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A } mIsAspectRatioApplied = false; + mIsEligibleForFixedOrientationLetterbox = false; + mLetterboxBoundsForFixedOrientationAndAspectRatio = null; // Can't use resolvedConfig.windowConfiguration.getWindowingMode() because it can be // different from windowing mode of the task (PiP) during transition from fullscreen to PiP @@ -8303,8 +8305,11 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A final boolean isFixedOrientationLetterboxAllowed = parentWindowingMode == WINDOWING_MODE_MULTI_WINDOW || parentWindowingMode == WINDOWING_MODE_FULLSCREEN - // Switching from PiP to fullscreen. - || (parentWindowingMode == WINDOWING_MODE_PINNED + // When starting to switch between PiP and fullscreen, the task is pinned + // and the activity is fullscreen. But only allow to apply letterbox if the + // activity is exiting PiP because an entered PiP should fill the task. + || (!mWaitForEnteringPinnedMode + && parentWindowingMode == WINDOWING_MODE_PINNED && resolvedConfig.windowConfiguration.getWindowingMode() == WINDOWING_MODE_FULLSCREEN); // TODO(b/181207944): Consider removing the if condition and always run @@ -8698,8 +8703,6 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A * in this method. */ private void resolveFixedOrientationConfiguration(@NonNull Configuration newParentConfig) { - mLetterboxBoundsForFixedOrientationAndAspectRatio = null; - mIsEligibleForFixedOrientationLetterbox = false; final Rect parentBounds = newParentConfig.windowConfiguration.getBounds(); final Rect stableBounds = new Rect(); // If orientation is respected when insets are applied, then stableBounds will be empty. diff --git a/services/core/java/com/android/server/wm/RootWindowContainer.java b/services/core/java/com/android/server/wm/RootWindowContainer.java index bc7fa31125f99..b544196cda8d9 100644 --- a/services/core/java/com/android/server/wm/RootWindowContainer.java +++ b/services/core/java/com/android/server/wm/RootWindowContainer.java @@ -2013,7 +2013,6 @@ class RootWindowContainer extends WindowContainer // from doing work and changing the activity visuals while animating // TODO(task-org): Figure-out more structured way to do this long term. r.setWindowingMode(r.getWindowingMode()); - r.mWaitForEnteringPinnedMode = true; final TaskFragment organizedTf = r.getOrganizedTaskFragment(); final boolean singleActivity = task.getNonFinishingActivityCount() == 1; @@ -2140,6 +2139,10 @@ class RootWindowContainer extends WindowContainer } rootTask.setDeferTaskAppear(false); + // After setting this, it is not expected to change activity configuration until the + // transition animation is finished. So the activity can keep consistent appearance + // when animating. + r.mWaitForEnteringPinnedMode = true; // Reset the state that indicates it can enter PiP while pausing after we've moved it // to the root pinned task r.supportsEnterPipOnTaskSwitch = false; diff --git a/services/core/java/com/android/server/wm/WindowState.java b/services/core/java/com/android/server/wm/WindowState.java index 8f49384f6101c..b899b4f581062 100644 --- a/services/core/java/com/android/server/wm/WindowState.java +++ b/services/core/java/com/android/server/wm/WindowState.java @@ -3883,15 +3883,13 @@ class WindowState extends WindowContainer implements WindowManagerP } /** - * @return {@code true} if activity bounds are letterboxed or letterboxed for display cutout. - * Note that it's always {@code false} if the activity is in pip mode. + * Returns {@code true} if activity bounds are letterboxed or letterboxed for display cutout. * *

Note that letterbox UI may not be shown even when this returns {@code true}. See {@link * LetterboxUiController#shouldShowLetterboxUi} for more context. */ boolean areAppWindowBoundsLetterboxed() { return mActivityRecord != null - && !mActivityRecord.inPinnedWindowingMode() && (mActivityRecord.areBoundsLetterboxed() || isLetterboxedForDisplayCutout()); } diff --git a/services/tests/wmtests/src/com/android/server/wm/RootWindowContainerTests.java b/services/tests/wmtests/src/com/android/server/wm/RootWindowContainerTests.java index d173ce9d522a5..3bc6450ae5910 100644 --- a/services/tests/wmtests/src/com/android/server/wm/RootWindowContainerTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/RootWindowContainerTests.java @@ -337,6 +337,17 @@ public class RootWindowContainerTests extends WindowTestsBase { // Ensure a task has moved over. ensureTaskPlacement(task, activity); assertTrue(task.inPinnedWindowingMode()); + + // The activity with fixed orientation should not apply letterbox when entering PiP. + final int requestedOrientation = task.getConfiguration().orientation + == Configuration.ORIENTATION_PORTRAIT + ? Configuration.ORIENTATION_LANDSCAPE : Configuration.ORIENTATION_PORTRAIT; + doReturn(requestedOrientation).when(activity).getRequestedConfigurationOrientation(); + doReturn(false).when(activity).handlesOrientationChangeFromDescendant(anyInt()); + final Rect bounds = new Rect(task.getBounds()); + bounds.scale(0.5f); + task.setBounds(bounds); + assertFalse(activity.isLetterboxedForFixedOrientationAndAspectRatio()); } /**