From e32e5c3041540d02ec052e33ceabad33c83f8f39 Mon Sep 17 00:00:00 2001 From: Riddle Hsu Date: Thu, 8 Jun 2023 22:57:54 +0800 Subject: [PATCH] Use seamless rotation if navigation bar allows This aligns partial behavior of [1]. Though the getUpsideDownRotation is no longer accurate because the default rotation of display can be customized. However, since navigation bar defines the allow-seamless config [2] for large screen, it is enough to apply seamless rotation for both gesture and 3-button navigation on large screen. [1]: I9165f44b42fd058cb52753ecdf3cb98789c675d2 [2]: I3fbf4d8c8fa477746abd18fd40ad65f55dc14d8f Fix: 286306717 Test: atest ShellTransitionTests#testShouldRotateSeamlessly Change-Id: I856111ef4bf7aa052c03f7ef3cd7135ffdf46572 --- .../android/wm/shell/common/DisplayLayout.java | 7 +++++-- .../transition/DefaultTransitionHandler.java | 16 +++++++++------- .../shell/transition/ShellTransitionTests.java | 8 ++++---- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/common/DisplayLayout.java b/libs/WindowManager/Shell/src/com/android/wm/shell/common/DisplayLayout.java index d6e1a82a68ff6..989d035b6a53f 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/common/DisplayLayout.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/common/DisplayLayout.java @@ -300,9 +300,12 @@ public class DisplayLayout { return mAllowSeamlessRotationDespiteNavBarMoving; } - /** @return whether the navigation bar will change sides during rotation. */ + /** + * Returns {@code true} if the navigation bar will change sides during rotation and the display + * is not square. + */ public boolean navigationBarCanMove() { - return mNavigationBarCanMove; + return mNavigationBarCanMove && mWidth != mHeight; } /** @return the rotation that would make the physical display "upside down". */ diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/transition/DefaultTransitionHandler.java b/libs/WindowManager/Shell/src/com/android/wm/shell/transition/DefaultTransitionHandler.java index 3bf278cc46cf2..e52fd00e7df7d 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/transition/DefaultTransitionHandler.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/transition/DefaultTransitionHandler.java @@ -260,6 +260,12 @@ public class DefaultTransitionHandler implements Transitions.TransitionHandler { // This is the only way to get display-id currently, so check display capabilities here. final DisplayLayout displayLayout = displayController.getDisplayLayout( topTaskInfo.displayId); + // This condition should be true when using gesture navigation or the screen size is large + // (>600dp) because the bar is small relative to screen. + if (displayLayout.allowSeamlessRotationDespiteNavBarMoving()) { + ProtoLog.v(ShellProtoLogGroup.WM_SHELL_TRANSITIONS, " nav bar allows seamless."); + return ROTATION_ANIMATION_SEAMLESS; + } // For the upside down rotation we don't rotate seamlessly as the navigation bar moves // position. Note most apps (using orientation:sensor or user as opposed to fullSensor) // will not enter the reverse portrait orientation, so actually the orientation won't @@ -272,13 +278,9 @@ public class DefaultTransitionHandler implements Transitions.TransitionHandler { return animationHint; } - // If the navigation bar can't change sides, then it will jump when we change orientations - // and we don't rotate seamlessly - unless that is allowed, e.g. with gesture navigation - // where the navbar is low-profile enough that this isn't very noticeable. - if (!displayLayout.allowSeamlessRotationDespiteNavBarMoving() - && (!(displayLayout.navigationBarCanMove() - && (displayChange.getStartAbsBounds().width() - != displayChange.getStartAbsBounds().height())))) { + // If the navigation bar cannot change sides, then it will jump when changing orientation + // so do not use seamless rotation. + if (!displayLayout.navigationBarCanMove()) { ProtoLog.v(ShellProtoLogGroup.WM_SHELL_TRANSITIONS, " nav bar changes sides, so not seamless."); return animationHint; diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/transition/ShellTransitionTests.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/transition/ShellTransitionTests.java index 963632b1f8f69..4de182d2a6c72 100644 --- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/transition/ShellTransitionTests.java +++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/transition/ShellTransitionTests.java @@ -51,7 +51,6 @@ import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.isNull; -import static org.mockito.Mockito.after; import static org.mockito.Mockito.clearInvocations; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.inOrder; @@ -703,8 +702,8 @@ public class ShellTransitionTests extends ShellTestCase { createTaskInfo(1, WINDOWING_MODE_PINNED, ACTIVITY_TYPE_STANDARD); final DisplayController displays = createTestDisplayController(); - final @Surface.Rotation int upsideDown = displays - .getDisplayLayout(DEFAULT_DISPLAY).getUpsideDownRotation(); + final DisplayLayout displayLayout = displays.getDisplayLayout(DEFAULT_DISPLAY); + final @Surface.Rotation int upsideDown = displayLayout.getUpsideDownRotation(); TransitionInfo.Change displayChange = new ChangeBuilder(TRANSIT_CHANGE) .setFlags(FLAG_IS_DISPLAY).setRotate().build(); @@ -744,7 +743,8 @@ public class ShellTransitionTests extends ShellTestCase { assertEquals(ROTATION_ANIMATION_ROTATE, DefaultTransitionHandler.getRotationAnimationHint( displayChange, noTask, displays)); - // Not seamless if one of rotations is upside-down + // Not seamless if the nav bar cares rotation and one of rotations is upside-down. + doReturn(false).when(displayLayout).allowSeamlessRotationDespiteNavBarMoving(); displayChange = new ChangeBuilder(TRANSIT_CHANGE).setFlags(FLAG_IS_DISPLAY) .setRotate(upsideDown, ROTATION_ANIMATION_UNSPECIFIED).build(); final TransitionInfo seamlessUpsideDown = new TransitionInfoBuilder(TRANSIT_CHANGE)