Merge "Add check in #shouldReverseRotationDirectionAroundZAxis" into udc-dev

This commit is contained in:
Kevin Chyn
2023-06-02 21:02:44 +00:00
committed by Android (Google) Code Review
3 changed files with 15 additions and 8 deletions

View File

@@ -111,9 +111,13 @@ final class DeviceStateController {
}
/**
* @return true if the rotation direction on the Z axis should be reversed.
* @return true if the rotation direction on the Z axis should be reversed for the default
* display.
*/
boolean shouldReverseRotationDirectionAroundZAxis() {
boolean shouldReverseRotationDirectionAroundZAxis(@NonNull DisplayContent displayContent) {
if (!displayContent.isDefaultDisplay) {
return false;
}
return ArrayUtils.contains(mReverseRotationAroundZAxisStates, mCurrentState);
}

View File

@@ -950,7 +950,7 @@ public class DisplayRotation {
}
void freezeRotation(int rotation) {
if (mDeviceStateController.shouldReverseRotationDirectionAroundZAxis()) {
if (mDeviceStateController.shouldReverseRotationDirectionAroundZAxis(mDisplayContent)) {
rotation = RotationUtils.reverseRotationDirectionAroundZAxis(rotation);
}
@@ -1225,7 +1225,7 @@ public class DisplayRotation {
if (mFoldController != null && mFoldController.shouldIgnoreSensorRotation()) {
sensorRotation = -1;
}
if (mDeviceStateController.shouldReverseRotationDirectionAroundZAxis()) {
if (mDeviceStateController.shouldReverseRotationDirectionAroundZAxis(mDisplayContent)) {
sensorRotation = RotationUtils.reverseRotationDirectionAroundZAxis(sensorRotation);
}
mLastSensorRotation = sensorRotation;

View File

@@ -59,10 +59,10 @@ import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.hardware.devicestate.DeviceStateManager;
import android.os.Handler;
import android.os.IBinder;
import android.os.PowerManagerInternal;
import android.os.SystemClock;
import android.os.Handler;
import android.platform.test.annotations.Presubmit;
import android.provider.Settings;
import android.view.DisplayAddress;
@@ -518,7 +518,8 @@ public class DisplayRotationTests {
mBuilder.build();
configureDisplayRotation(SCREEN_ORIENTATION_PORTRAIT, false, false);
when(mDeviceStateController.shouldReverseRotationDirectionAroundZAxis()).thenReturn(true);
when(mDeviceStateController.shouldReverseRotationDirectionAroundZAxis(mMockDisplayContent))
.thenReturn(true);
thawRotation();
@@ -544,7 +545,8 @@ public class DisplayRotationTests {
@Test
public void testFreezeRotation_reverseRotationDirectionAroundZAxis_yes() throws Exception {
mBuilder.build();
when(mDeviceStateController.shouldReverseRotationDirectionAroundZAxis()).thenReturn(true);
when(mDeviceStateController.shouldReverseRotationDirectionAroundZAxis(mMockDisplayContent))
.thenReturn(true);
freezeRotation(Surface.ROTATION_90);
assertEquals(Surface.ROTATION_270, mTarget.getUserRotation());
@@ -553,7 +555,8 @@ public class DisplayRotationTests {
@Test
public void testFreezeRotation_reverseRotationDirectionAroundZAxis_no() throws Exception {
mBuilder.build();
when(mDeviceStateController.shouldReverseRotationDirectionAroundZAxis()).thenReturn(false);
when(mDeviceStateController.shouldReverseRotationDirectionAroundZAxis(mMockDisplayContent))
.thenReturn(false);
freezeRotation(Surface.ROTATION_90);
assertEquals(Surface.ROTATION_90, mTarget.getUserRotation());