From b398861cebb113d33926f88b627e1d402f01a205 Mon Sep 17 00:00:00 2001 From: Riddle Hsu Date: Wed, 10 Feb 2021 17:44:40 +0800 Subject: [PATCH] Notify client to clear intermediate rotated adjustments The previous commit a83c85 for fixing uncleared rotated adjustments is too aggressive that clears the transform directly. If the previous activity is still animating, its unrotated window won't fit in display. E.g. launch an activity in different orientation and press home or back key before the launch animation is finished. So this change only notifies client to clear the rotated adjustments. The transform will be cleared at the end of transition animation. Bug: 177390830 Test: DisplayContentTests#testClearIntermediateFixedRotationAdjustments Change-Id: Ica074604df3e74eabbdef931531abe51855103e5 --- .../java/com/android/server/wm/DisplayContent.java | 12 ++++++------ .../core/java/com/android/server/wm/WindowToken.java | 2 +- .../com/android/server/wm/DisplayContentTests.java | 5 +++-- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/services/core/java/com/android/server/wm/DisplayContent.java b/services/core/java/com/android/server/wm/DisplayContent.java index 23eab98a671ad..fde2358708cd0 100644 --- a/services/core/java/com/android/server/wm/DisplayContent.java +++ b/services/core/java/com/android/server/wm/DisplayContent.java @@ -1573,12 +1573,12 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp } final int rotation = rotationForActivityInDifferentOrientation(r); if (rotation == ROTATION_UNDEFINED) { - // The display rotation won't be changed by current top activity. If there was fixed - // rotation activity, its rotated state should be cleared to cancel the adjustments. - if (hasTopFixedRotationLaunchingApp() - // Avoid breaking recents animation. - && !mFixedRotationLaunchingApp.getTask().isAnimatingByRecents()) { - clearFixedRotationLaunchingApp(); + // The display rotation won't be changed by current top activity. The client side + // adjustments of previous rotated activity should be cleared earlier. Otherwise if + // the current top is in the same process, it may get the rotated state. The transform + // will be cleared later with transition callback to ensure smooth animation. + if (hasTopFixedRotationLaunchingApp()) { + mFixedRotationLaunchingApp.notifyFixedRotationTransform(false /* enabled */); } return false; } diff --git a/services/core/java/com/android/server/wm/WindowToken.java b/services/core/java/com/android/server/wm/WindowToken.java index 1c3fe029a56bd..e87ee918e0f09 100644 --- a/services/core/java/com/android/server/wm/WindowToken.java +++ b/services/core/java/com/android/server/wm/WindowToken.java @@ -549,7 +549,7 @@ class WindowToken extends WindowContainer { } /** Notifies application side to enable or disable the rotation adjustment of display info. */ - private void notifyFixedRotationTransform(boolean enabled) { + void notifyFixedRotationTransform(boolean enabled) { FixedRotationAdjustments adjustments = null; // A token may contain windows of the same processes or different processes. The list is // used to avoid sending the same adjustments to a process multiple times. 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 b4fd3024a6348..ad54ffcd22854 100644 --- a/services/tests/wmtests/src/com/android/server/wm/DisplayContentTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/DisplayContentTests.java @@ -1489,7 +1489,7 @@ public class DisplayContentTests extends WindowTestsBase { } @Test - public void testClearIntermediateFixedRotation() throws RemoteException { + public void testClearIntermediateFixedRotationAdjustments() throws RemoteException { final ActivityRecord activity = new ActivityBuilder(mAtm).setCreateTask(true).build(); mDisplayContent.setFixedRotationLaunchingApp(activity, (mDisplayContent.getRotation() + 1) % 4); @@ -1508,7 +1508,8 @@ public class DisplayContentTests extends WindowTestsBase { ArgumentCaptor.forClass(FixedRotationAdjustmentsItem.class); verify(mAtm.getLifecycleManager(), atLeastOnce()).scheduleTransaction( eq(activity.app.getThread()), adjustmentsCaptor.capture()); - assertFalse(activity.hasFixedRotationTransform()); + // The transformation is kept for animation in real case. + assertTrue(activity.hasFixedRotationTransform()); final FixedRotationAdjustmentsItem clearAdjustments = FixedRotationAdjustmentsItem.obtain( activity.token, null /* fixedRotationAdjustments */); // The captor may match other items. The first one must be the item to clear adjustments.