diff options
author | Kevin Chyn <kchyn@google.com> | 2023-04-21 22:00:11 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-04-28 15:54:23 +0000 |
commit | 09355a36307b3e7fa06d819a55d52e38e911ba93 (patch) | |
tree | 299da25d4fadf2c32cf8c21866fe869bcaf964b5 | |
parent | 59cb04c32141a679368f8939837fded8ae1f99e6 (diff) | |
download | base-09355a36307b3e7fa06d819a55d52e38e911ba93.tar.gz |
Also reverse rotation for #freezeRotation path
When auto-rotation is disabled, users can apply the suggested rotation
using the rotation icon from SysUI. The sensor value passed to
DisplayRotation#freezeRotation(int) that comes from
WindowManagerService#freezeDisplayRotation also needs to apply the
same reversing logic as DisplayRotation#rotationForOrientation.
Fixes: 275286150
Test: atest DisplayRotationTests
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:4c2b792c116e04591b0d28235ca6329b944ecf32)
Merged-In: I985ae560d8eff6ea063206c1e39bd694ab576fde
Change-Id: I985ae560d8eff6ea063206c1e39bd694ab576fde
-rw-r--r-- | services/core/java/com/android/server/wm/DisplayRotation.java | 10 | ||||
-rw-r--r-- | services/tests/wmtests/src/com/android/server/wm/DisplayRotationTests.java | 18 |
2 files changed, 28 insertions, 0 deletions
diff --git a/services/core/java/com/android/server/wm/DisplayRotation.java b/services/core/java/com/android/server/wm/DisplayRotation.java index 0a1e29ace045..31b987943f5b 100644 --- a/services/core/java/com/android/server/wm/DisplayRotation.java +++ b/services/core/java/com/android/server/wm/DisplayRotation.java @@ -913,6 +913,16 @@ public class DisplayRotation { } void freezeRotation(int rotation) { + if (mDeviceStateController.shouldReverseRotationDirectionAroundZAxis()) { + // Flipping 270 and 90 has the same effect as changing the direction which rotation is + // applied. + if (rotation == Surface.ROTATION_90) { + rotation = Surface.ROTATION_270; + } else if (rotation == Surface.ROTATION_270) { + rotation = Surface.ROTATION_90; + } + } + rotation = (rotation == -1) ? mRotation : rotation; setUserRotation(WindowManagerPolicy.USER_ROTATION_LOCKED, rotation); } 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 950e9e4848b0..a831b270dbd9 100644 --- a/services/tests/wmtests/src/com/android/server/wm/DisplayRotationTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/DisplayRotationTests.java @@ -537,6 +537,24 @@ public class DisplayRotationTests { SCREEN_ORIENTATION_UNSPECIFIED, Surface.ROTATION_180)); } + @Test + public void testFreezeRotation_reverseRotationDirectionAroundZAxis_yes() throws Exception { + mBuilder.build(); + when(mDeviceStateController.shouldReverseRotationDirectionAroundZAxis()).thenReturn(true); + + freezeRotation(Surface.ROTATION_90); + assertEquals(Surface.ROTATION_270, mTarget.getUserRotation()); + } + + @Test + public void testFreezeRotation_reverseRotationDirectionAroundZAxis_no() throws Exception { + mBuilder.build(); + when(mDeviceStateController.shouldReverseRotationDirectionAroundZAxis()).thenReturn(false); + + freezeRotation(Surface.ROTATION_90); + assertEquals(Surface.ROTATION_90, mTarget.getUserRotation()); + } + private boolean waitForUiHandler() { final CountDownLatch latch = new CountDownLatch(1); UiThread.getHandler().post(latch::countDown); |