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 467e9c7a116be..1959eb03a6b37 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 961e3e9c57357..ff380e92322d0 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 @@ -702,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(); @@ -743,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)