Merge "Also reverse rotation for #freezeRotation path" into udc-dev

This commit is contained in:
Kevin Chyn
2023-04-24 17:59:10 +00:00
committed by Android (Google) Code Review
3 changed files with 38 additions and 0 deletions

View File

@@ -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;
@@ -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));
}
}

View File

@@ -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);
}

View File

@@ -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);