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

Commit d572ae7f authored by YoungJoon Yang's avatar YoungJoon Yang Committed by Android (Google) Code Review
Browse files

Merge changes from topic "wear-lefty-mode"

* changes:
  Start WristOrientationService from SystemServer
  Add a flag to fix to user rotation for non auto rotation
parents fb189a07 9e2aea05
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -93,6 +93,11 @@ interface IWindowManager
     * Only use {@link DisplayRotation#mUserRotation} as the display rotation.
     */
    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 =====
+9 −3
Original line number Diff line number Diff line
@@ -977,6 +977,8 @@ public class DisplayRotation {
                return false;
            case IWindowManager.FIXED_TO_USER_ROTATION_ENABLED:
                return true;
            case IWindowManager.FIXED_TO_USER_ROTATION_IF_NO_AUTO_ROTATION:
                return false;
            default:
                return mDefaultFixedToUserRotation;
        }
@@ -1290,9 +1292,13 @@ public class DisplayRotation {
            // Application just wants to remain locked in the last rotation.
            preferredRotation = lastRotation;
        } 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
                // the sensor and any rotation lock settings.
                preferredRotation = -1;
            }
        } else if (((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
                            || isTabletopAutoRotateOverrideEnabled())
                        && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
+11 −1
Original line number Diff line number Diff line
@@ -337,6 +337,8 @@ public final class SystemServer implements Dumpable {
            "com.android.clockwork.time.WearTimeService";
    private static final String WEAR_SETTINGS_SERVICE_CLASS =
            "com.android.clockwork.settings.WearSettingsService";
    private static final String WRIST_ORIENTATION_SERVICE_CLASS =
            "com.android.clockwork.wristorientation.WristOrientationService";
    private static final String ACCOUNT_SERVICE_CLASS =
            "com.android.server.accounts.AccountManagerService$Lifecycle";
    private static final String CONTENT_SERVICE_CLASS =
@@ -2615,6 +2617,14 @@ public final class SystemServer implements Dumpable {
            t.traceBegin("StartWearModeService");
            mSystemServiceManager.startService(WEAR_MODE_SERVICE_CLASS);
            t.traceEnd();

            boolean enableWristOrientationService = SystemProperties.getBoolean(
                    "config.enable_wristorientation", false);
            if (enableWristOrientationService) {
                t.traceBegin("StartWristOrientationService");
                mSystemServiceManager.startService(WRIST_ORIENTATION_SERVICE_CLASS);
                t.traceEnd();
            }
        }

        if (!mPackageManager.hasSystemFeature(PackageManager.FEATURE_SLICES_DISABLED)) {
+26 −0
Original line number 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_DISABLED;
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.anyBoolean;
@@ -1128,6 +1129,22 @@ public class DisplayRotationTests {
                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
    // ========================
@@ -1148,6 +1165,15 @@ public class DisplayRotationTests {
                + " 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) {
        sCurrentUptimeMillis += timeMillis;
        sClock.fastForward(timeMillis);