Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e32e5c30 authored by Riddle Hsu's avatar Riddle Hsu
Browse files

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
parent f4f5ce43
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -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". */
+9 −7
Original line number Diff line number Diff line
@@ -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;
+4 −4
Original line number Diff line number Diff line
@@ -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)