Loading core/tests/coretests/src/android/util/RotationUtilsTest.java +16 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ package android.util; import static android.util.RotationUtils.rotateBounds; import static android.util.RotationUtils.rotatePoint; import static android.util.RotationUtils.rotatePointF; import static android.view.Surface.ROTATION_0; import static android.view.Surface.ROTATION_180; import static android.view.Surface.ROTATION_270; import static android.view.Surface.ROTATION_90; Loading Loading @@ -103,4 +104,19 @@ public class RotationUtilsTest { assertEquals(560f, testResult.x, .1f); assertEquals(60f, testResult.y, .1f); } @Test public void testReverseRotationDirectionAroundZAxis() { assertEquals(ROTATION_90, RotationUtils.reverseRotationDirectionAroundZAxis(ROTATION_270)); assertEquals(ROTATION_270, RotationUtils.reverseRotationDirectionAroundZAxis(ROTATION_90)); assertEquals(ROTATION_0, RotationUtils.reverseRotationDirectionAroundZAxis(ROTATION_0)); assertEquals(ROTATION_180, RotationUtils.reverseRotationDirectionAroundZAxis(ROTATION_180)); assertEquals(-1, RotationUtils.reverseRotationDirectionAroundZAxis(-1)); } } services/core/java/com/android/server/wm/DisplayRotation.java +4 −0 Original line number Diff line number Diff line Loading @@ -946,6 +946,10 @@ public class DisplayRotation { } void freezeRotation(int rotation) { if (mDeviceStateController.shouldReverseRotationDirectionAroundZAxis()) { rotation = RotationUtils.reverseRotationDirectionAroundZAxis(rotation); } rotation = (rotation == -1) ? mRotation : rotation; setUserRotation(WindowManagerPolicy.USER_ROTATION_LOCKED, rotation); } Loading services/tests/wmtests/src/com/android/server/wm/DisplayRotationTests.java +18 −0 Original line number Diff line number Diff line Loading @@ -541,6 +541,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); Loading Loading
core/tests/coretests/src/android/util/RotationUtilsTest.java +16 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ package android.util; import static android.util.RotationUtils.rotateBounds; import static android.util.RotationUtils.rotatePoint; import static android.util.RotationUtils.rotatePointF; import static android.view.Surface.ROTATION_0; import static android.view.Surface.ROTATION_180; import static android.view.Surface.ROTATION_270; import static android.view.Surface.ROTATION_90; Loading Loading @@ -103,4 +104,19 @@ public class RotationUtilsTest { assertEquals(560f, testResult.x, .1f); assertEquals(60f, testResult.y, .1f); } @Test public void testReverseRotationDirectionAroundZAxis() { assertEquals(ROTATION_90, RotationUtils.reverseRotationDirectionAroundZAxis(ROTATION_270)); assertEquals(ROTATION_270, RotationUtils.reverseRotationDirectionAroundZAxis(ROTATION_90)); assertEquals(ROTATION_0, RotationUtils.reverseRotationDirectionAroundZAxis(ROTATION_0)); assertEquals(ROTATION_180, RotationUtils.reverseRotationDirectionAroundZAxis(ROTATION_180)); assertEquals(-1, RotationUtils.reverseRotationDirectionAroundZAxis(-1)); } }
services/core/java/com/android/server/wm/DisplayRotation.java +4 −0 Original line number Diff line number Diff line Loading @@ -946,6 +946,10 @@ public class DisplayRotation { } void freezeRotation(int rotation) { if (mDeviceStateController.shouldReverseRotationDirectionAroundZAxis()) { rotation = RotationUtils.reverseRotationDirectionAroundZAxis(rotation); } rotation = (rotation == -1) ? mRotation : rotation; setUserRotation(WindowManagerPolicy.USER_ROTATION_LOCKED, rotation); } Loading
services/tests/wmtests/src/com/android/server/wm/DisplayRotationTests.java +18 −0 Original line number Diff line number Diff line Loading @@ -541,6 +541,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); Loading