diff --git a/core/java/android/view/IWindowManager.aidl b/core/java/android/view/IWindowManager.aidl index a9a5888207aa5..072a7f5ea3045 100644 --- a/core/java/android/view/IWindowManager.aidl +++ b/core/java/android/view/IWindowManager.aidl @@ -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 ===== diff --git a/services/core/java/com/android/server/wm/DisplayRotation.java b/services/core/java/com/android/server/wm/DisplayRotation.java index b681c198538f4..99cbdde306a2d 100644 --- a/services/core/java/com/android/server/wm/DisplayRotation.java +++ b/services/core/java/com/android/server/wm/DisplayRotation.java @@ -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 we don't support auto-rotation then bail out here and ignore - // the sensor and any rotation lock settings. - preferredRotation = -1; + 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 diff --git a/services/java/com/android/server/SystemServer.java b/services/java/com/android/server/SystemServer.java index 2f0e9dd0dde8d..ec3e73406004b 100644 --- a/services/java/com/android/server/SystemServer.java +++ b/services/java/com/android/server/SystemServer.java @@ -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 = @@ -2582,7 +2584,7 @@ public final class SystemServer implements Dumpable { mSystemServiceManager.startService(MediaProjectionManagerService.class); t.traceEnd(); - if (isWatch) { + if (isWatch) { // Must be started before services that depend it, e.g. WearConnectivityService t.traceBegin("StartWearPowerService"); mSystemServiceManager.startService(WEAR_POWER_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)) { diff --git a/services/tests/wmtests/src/com/android/server/wm/DisplayRotationTests.java b/services/tests/wmtests/src/com/android/server/wm/DisplayRotationTests.java index 2a8f0ffc4d49d..42422d91d5989 100644 --- a/services/tests/wmtests/src/com/android/server/wm/DisplayRotationTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/DisplayRotationTests.java @@ -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);