From 19b7b98a85443769762695b0d9236ff46dd01c07 Mon Sep 17 00:00:00 2001 From: YoungJoon Yang Date: Wed, 21 Jun 2023 16:25:45 +0900 Subject: [PATCH 1/2] 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 --- core/java/android/view/IWindowManager.aidl | 5 ++++ .../android/server/wm/DisplayRotation.java | 12 ++++++--- .../server/wm/DisplayRotationTests.java | 26 +++++++++++++++++++ 3 files changed, 40 insertions(+), 3 deletions(-) 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/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); From 9e2aea05811d8cfdc2dee56de4e04402742bc683 Mon Sep 17 00:00:00 2001 From: YoungJoon Yang Date: Thu, 22 Jun 2023 11:43:06 +0900 Subject: [PATCH 2/2] Start WristOrientationService from SystemServer Start the service if config.enable.wristorientation is enabled. Bug: 272527836 Test: enable config.enable.wristorientation -> boot -> WristOrientationService is running Change-Id: I83b9ca14349c753896c179e2acccdc790d2716dd --- services/java/com/android/server/SystemServer.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/services/java/com/android/server/SystemServer.java b/services/java/com/android/server/SystemServer.java index 31efcca16ecd8..aa3b1d10a99b1 100644 --- a/services/java/com/android/server/SystemServer.java +++ b/services/java/com/android/server/SystemServer.java @@ -338,6 +338,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 = @@ -2584,7 +2586,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); @@ -2617,6 +2619,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)) {