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

Commit 19b7b98a authored by YoungJoon Yang's avatar YoungJoon Yang
Browse files

Add a flag to fix to user rotation for non auto rotation

Wrist orientation shows the screen with the user rotation
except for special cases (docking etc.).
However, if auto rotation is not supported,
user rotation is ignored and rotation is set to 0,
so rotation is not displayed as intended.

Add a new mode to prioritize user rotation
when auto rotation is not supported.

Bug: 272527836
Test: atest WmTests:DisplayRotationTests
Change-Id: I0564d797db7cd98374d406483a30f6ad6aa399aa
parent 5e56f8b9
Loading
Loading
Loading
Loading
+5 −0
Original line number Original line Diff line number Diff line
@@ -93,6 +93,11 @@ interface IWindowManager
     * Only use {@link DisplayRotation#mUserRotation} as the display rotation.
     * Only use {@link DisplayRotation#mUserRotation} as the display rotation.
     */
     */
    const int FIXED_TO_USER_ROTATION_ENABLED = 2;
    const int FIXED_TO_USER_ROTATION_ENABLED = 2;
    /**
     * If auto-rotation is not supported, {@link DisplayRotation#mUserRotation} will be used.
     * Otherwise the behavior is same as {link #FIXED_TO_USER_ROTATION_DISABLED}.
     */
    const int FIXED_TO_USER_ROTATION_IF_NO_AUTO_ROTATION = 3;


    /**
    /**
     * ===== NOTICE =====
     * ===== NOTICE =====
+9 −3
Original line number Original line Diff line number Diff line
@@ -977,6 +977,8 @@ public class DisplayRotation {
                return false;
                return false;
            case IWindowManager.FIXED_TO_USER_ROTATION_ENABLED:
            case IWindowManager.FIXED_TO_USER_ROTATION_ENABLED:
                return true;
                return true;
            case IWindowManager.FIXED_TO_USER_ROTATION_IF_NO_AUTO_ROTATION:
                return false;
            default:
            default:
                return mDefaultFixedToUserRotation;
                return mDefaultFixedToUserRotation;
        }
        }
@@ -1290,9 +1292,13 @@ public class DisplayRotation {
            // Application just wants to remain locked in the last rotation.
            // Application just wants to remain locked in the last rotation.
            preferredRotation = lastRotation;
            preferredRotation = lastRotation;
        } else if (!mSupportAutoRotation) {
        } else if (!mSupportAutoRotation) {
            if (mFixedToUserRotation == IWindowManager.FIXED_TO_USER_ROTATION_IF_NO_AUTO_ROTATION) {
                preferredRotation = mUserRotation;
            } else {
                // If we don't support auto-rotation then bail out here and ignore
                // If we don't support auto-rotation then bail out here and ignore
                // the sensor and any rotation lock settings.
                // the sensor and any rotation lock settings.
                preferredRotation = -1;
                preferredRotation = -1;
            }
        } else if (((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
        } else if (((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
                            || isTabletopAutoRotateOverrideEnabled())
                            || isTabletopAutoRotateOverrideEnabled())
                        && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
                        && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
+26 −0
Original line number Original line Diff line number Diff line
@@ -26,6 +26,7 @@ import static android.view.DisplayCutout.NO_CUTOUT;
import static android.view.IWindowManager.FIXED_TO_USER_ROTATION_DEFAULT;
import static android.view.IWindowManager.FIXED_TO_USER_ROTATION_DEFAULT;
import static android.view.IWindowManager.FIXED_TO_USER_ROTATION_DISABLED;
import static android.view.IWindowManager.FIXED_TO_USER_ROTATION_DISABLED;
import static android.view.IWindowManager.FIXED_TO_USER_ROTATION_ENABLED;
import static android.view.IWindowManager.FIXED_TO_USER_ROTATION_ENABLED;
import static android.view.IWindowManager.FIXED_TO_USER_ROTATION_IF_NO_AUTO_ROTATION;


import static com.android.dx.mockito.inline.extended.ExtendedMockito.any;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.any;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.anyBoolean;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.anyBoolean;
@@ -1128,6 +1129,22 @@ public class DisplayRotationTests {
                SCREEN_ORIENTATION_UNSPECIFIED, Surface.ROTATION_0));
                SCREEN_ORIENTATION_UNSPECIFIED, Surface.ROTATION_0));
    }
    }


    @Test
    public void testReturnsUserRotation_FixedToUserRotationIfNoAutoRotation_AutoRotationNotSupport()
            throws Exception {
        mBuilder.setSupportAutoRotation(false).build();
        configureDisplayRotation(SCREEN_ORIENTATION_PORTRAIT, false, false);
        mTarget.setFixedToUserRotation(FIXED_TO_USER_ROTATION_IF_NO_AUTO_ROTATION);

        freezeRotation(Surface.ROTATION_180);

        assertEquals(WindowManagerPolicy.USER_ROTATION_LOCKED, mTarget.getUserRotationMode());
        assertEquals(Surface.ROTATION_180, mTarget.getUserRotation());

        assertEquals(Surface.ROTATION_180, mTarget.rotationForOrientation(
                SCREEN_ORIENTATION_UNSPECIFIED, Surface.ROTATION_0));
    }

    // ========================
    // ========================
    // Non-rotation API Tests
    // Non-rotation API Tests
    // ========================
    // ========================
@@ -1148,6 +1165,15 @@ public class DisplayRotationTests {
                + " fixed to user rotation.", mTarget.isFixedToUserRotation());
                + " fixed to user rotation.", mTarget.isFixedToUserRotation());
    }
    }


    @Test
    public void testIsFixedToUserRotation_FixedToUserRotationIfNoAutoRotation() throws Exception {
        mBuilder.build();
        mTarget.setFixedToUserRotation(FIXED_TO_USER_ROTATION_IF_NO_AUTO_ROTATION);

        assertFalse("Display rotation should respect app requested orientation if"
                + " fixed to user rotation if no auto rotation.", mTarget.isFixedToUserRotation());
    }

    private void moveTimeForward(long timeMillis) {
    private void moveTimeForward(long timeMillis) {
        sCurrentUptimeMillis += timeMillis;
        sCurrentUptimeMillis += timeMillis;
        sClock.fastForward(timeMillis);
        sClock.fastForward(timeMillis);