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 Test: atest RotationUtilsTest Change-Id: I985ae560d8eff6ea063206c1e39bd694ab576fde
This commit is contained in:
@@ -19,6 +19,7 @@ package android.util;
|
|||||||
import static android.util.RotationUtils.rotateBounds;
|
import static android.util.RotationUtils.rotateBounds;
|
||||||
import static android.util.RotationUtils.rotatePoint;
|
import static android.util.RotationUtils.rotatePoint;
|
||||||
import static android.util.RotationUtils.rotatePointF;
|
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_180;
|
||||||
import static android.view.Surface.ROTATION_270;
|
import static android.view.Surface.ROTATION_270;
|
||||||
import static android.view.Surface.ROTATION_90;
|
import static android.view.Surface.ROTATION_90;
|
||||||
@@ -103,4 +104,19 @@ public class RotationUtilsTest {
|
|||||||
assertEquals(560f, testResult.x, .1f);
|
assertEquals(560f, testResult.x, .1f);
|
||||||
assertEquals(60f, testResult.y, .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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -946,6 +946,10 @@ public class DisplayRotation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void freezeRotation(int rotation) {
|
void freezeRotation(int rotation) {
|
||||||
|
if (mDeviceStateController.shouldReverseRotationDirectionAroundZAxis()) {
|
||||||
|
rotation = RotationUtils.reverseRotationDirectionAroundZAxis(rotation);
|
||||||
|
}
|
||||||
|
|
||||||
rotation = (rotation == -1) ? mRotation : rotation;
|
rotation = (rotation == -1) ? mRotation : rotation;
|
||||||
setUserRotation(WindowManagerPolicy.USER_ROTATION_LOCKED, rotation);
|
setUserRotation(WindowManagerPolicy.USER_ROTATION_LOCKED, rotation);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -541,6 +541,24 @@ public class DisplayRotationTests {
|
|||||||
SCREEN_ORIENTATION_UNSPECIFIED, Surface.ROTATION_180));
|
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() {
|
private boolean waitForUiHandler() {
|
||||||
final CountDownLatch latch = new CountDownLatch(1);
|
final CountDownLatch latch = new CountDownLatch(1);
|
||||||
UiThread.getHandler().post(latch::countDown);
|
UiThread.getHandler().post(latch::countDown);
|
||||||
|
|||||||
Reference in New Issue
Block a user