Merge "Disable table top auto-rotation override" into udc-qpr-dev

This commit is contained in:
Nick Chameyev
2023-08-03 09:49:48 +00:00
committed by Android (Google) Code Review
2 changed files with 60 additions and 15 deletions

View File

@@ -303,8 +303,7 @@ public class DisplayRotation {
mOrientationListener.setCurrentRotation(mRotation); mOrientationListener.setCurrentRotation(mRotation);
mSettingsObserver = new SettingsObserver(uiHandler); mSettingsObserver = new SettingsObserver(uiHandler);
mSettingsObserver.observe(); mSettingsObserver.observe();
if (mSupportAutoRotation && mContext.getResources().getBoolean( if (mSupportAutoRotation && isFoldable(mContext)) {
R.bool.config_windowManagerHalfFoldAutoRotateOverride)) {
mFoldController = new FoldController(); mFoldController = new FoldController();
} else { } else {
mFoldController = null; mFoldController = null;
@@ -314,6 +313,10 @@ public class DisplayRotation {
} }
} }
private static boolean isFoldable(Context context) {
return context.getResources().getIntArray(R.array.config_foldedDeviceStates).length > 0;
}
@VisibleForTesting @VisibleForTesting
@Nullable @Nullable
DisplayRotationImmersiveAppCompatPolicy initImmersiveAppCompatPolicy( DisplayRotationImmersiveAppCompatPolicy initImmersiveAppCompatPolicy(
@@ -1463,11 +1466,6 @@ public class DisplayRotation {
return false; return false;
} }
// Do not show rotation choice when fold controller blocks rotation sensor
if (mFoldController != null && mFoldController.shouldIgnoreSensorRotation()) {
return false;
}
// Don't show rotation choice if we are in tabletop or book modes. // Don't show rotation choice if we are in tabletop or book modes.
if (isTabletopAutoRotateOverrideEnabled()) return false; if (isTabletopAutoRotateOverrideEnabled()) return false;
@@ -1775,8 +1773,11 @@ public class DisplayRotation {
private SensorEventListener mHingeAngleSensorEventListener; private SensorEventListener mHingeAngleSensorEventListener;
private final Set<Integer> mTabletopRotations; private final Set<Integer> mTabletopRotations;
private final Runnable mActivityBoundsUpdateCallback; private final Runnable mActivityBoundsUpdateCallback;
private final boolean mAllowHalfFoldAutoRotationOverride;
FoldController() { FoldController() {
mAllowHalfFoldAutoRotationOverride = mContext.getResources().getBoolean(
R.bool.config_windowManagerHalfFoldAutoRotateOverride);
mTabletopRotations = new ArraySet<>(); mTabletopRotations = new ArraySet<>();
int[] tabletop_rotations = mContext.getResources().getIntArray( int[] tabletop_rotations = mContext.getResources().getIntArray(
R.array.config_deviceTabletopRotations); R.array.config_deviceTabletopRotations);
@@ -1894,12 +1895,14 @@ public class DisplayRotation {
} }
boolean overrideFrozenRotation() { boolean overrideFrozenRotation() {
return mDeviceState == DeviceStateController.DeviceState.HALF_FOLDED; return mAllowHalfFoldAutoRotationOverride
&& mDeviceState == DeviceStateController.DeviceState.HALF_FOLDED;
} }
boolean shouldRevertOverriddenRotation() { boolean shouldRevertOverriddenRotation() {
// When transitioning to open. // When transitioning to open.
return mDeviceState == DeviceStateController.DeviceState.OPEN return mAllowHalfFoldAutoRotationOverride
&& mDeviceState == DeviceStateController.DeviceState.OPEN
&& !mShouldIgnoreSensorRotation // Ignore if the hinge angle still moving && !mShouldIgnoreSensorRotation // Ignore if the hinge angle still moving
&& mInHalfFoldTransition && mInHalfFoldTransition
&& mDisplayContent.getRotationReversionController().isOverrideActive( && mDisplayContent.getRotationReversionController().isOverrideActive(

View File

@@ -73,6 +73,7 @@ import android.view.WindowManager;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.test.filters.SmallTest; import androidx.test.filters.SmallTest;
import com.android.internal.R;
import com.android.internal.util.test.FakeSettingsProvider; import com.android.internal.util.test.FakeSettingsProvider;
import com.android.server.LocalServices; import com.android.server.LocalServices;
import com.android.server.UiThread; import com.android.server.UiThread;
@@ -879,6 +880,33 @@ public class DisplayRotationTests {
SCREEN_ORIENTATION_UNSPECIFIED, Surface.ROTATION_0)); SCREEN_ORIENTATION_UNSPECIFIED, Surface.ROTATION_0));
} }
@Test
public void sensorRotation_locked_halfFolded_configOff_rotationUnchanged() throws Exception {
mBuilder.setIsFoldable(true);
mBuilder.setSupportHalfFoldAutoRotateOverride(false);
mBuilder.build();
configureDisplayRotation(SCREEN_ORIENTATION_LANDSCAPE, false, false);
enableOrientationSensor();
mTarget.foldStateChanged(DeviceStateController.DeviceState.OPEN);
freezeRotation(Surface.ROTATION_270);
mOrientationSensorListener.onSensorChanged(createSensorEvent(Surface.ROTATION_0));
assertTrue(waitForUiHandler());
// No rotation...
assertEquals(Surface.ROTATION_270, mTarget.rotationForOrientation(
SCREEN_ORIENTATION_UNSPECIFIED, Surface.ROTATION_0));
// ... half-fold -> still no rotation
mTarget.foldStateChanged(DeviceStateController.DeviceState.HALF_FOLDED);
assertTrue(waitForUiHandler());
verify(sMockWm).updateRotation(false, false);
assertTrue(waitForUiHandler());
assertEquals(Surface.ROTATION_270, mTarget.rotationForOrientation(
SCREEN_ORIENTATION_UNSPECIFIED, Surface.ROTATION_0));
}
// ================================= // =================================
// Tests for Policy based Rotation // Tests for Policy based Rotation
// ================================= // =================================
@@ -1016,7 +1044,7 @@ public class DisplayRotationTests {
@Test @Test
public void testSensorRotationAfterDisplayChangeBeforeTimeout_ignoresSensor() throws Exception { public void testSensorRotationAfterDisplayChangeBeforeTimeout_ignoresSensor() throws Exception {
mBuilder.setSupportHalfFoldAutoRotateOverride(true) mBuilder.setIsFoldable(true)
.setPauseRotationWhenUnfolding(true) .setPauseRotationWhenUnfolding(true)
.setDisplaySwitchRotationBlockTimeMs(1000) .setDisplaySwitchRotationBlockTimeMs(1000)
.build(); .build();
@@ -1034,7 +1062,7 @@ public class DisplayRotationTests {
@Test @Test
public void testSensorRotationAfterDisplayChangeAfterTimeout_usesSensor() throws Exception { public void testSensorRotationAfterDisplayChangeAfterTimeout_usesSensor() throws Exception {
mBuilder.setSupportHalfFoldAutoRotateOverride(true) mBuilder.setIsFoldable(true)
.setPauseRotationWhenUnfolding(true) .setPauseRotationWhenUnfolding(true)
.setDisplaySwitchRotationBlockTimeMs(1000) .setDisplaySwitchRotationBlockTimeMs(1000)
.build(); .build();
@@ -1052,7 +1080,7 @@ public class DisplayRotationTests {
@Test @Test
public void testSensorRotationAfterHingeEventBeforeTimeout_ignoresSensor() throws Exception { public void testSensorRotationAfterHingeEventBeforeTimeout_ignoresSensor() throws Exception {
mBuilder.setSupportHalfFoldAutoRotateOverride(true) mBuilder.setIsFoldable(true)
.setPauseRotationWhenUnfolding(true) .setPauseRotationWhenUnfolding(true)
.setMaxHingeAngle(165) .setMaxHingeAngle(165)
.setHingeAngleRotationBlockTimeMs(400) .setHingeAngleRotationBlockTimeMs(400)
@@ -1072,7 +1100,7 @@ public class DisplayRotationTests {
@Test @Test
public void testSensorRotationAfterHingeEventBeforeTimeoutFlagDisabled_usesSensorData() public void testSensorRotationAfterHingeEventBeforeTimeoutFlagDisabled_usesSensorData()
throws Exception { throws Exception {
mBuilder.setSupportHalfFoldAutoRotateOverride(true) mBuilder.setIsFoldable(true)
.setPauseRotationWhenUnfolding(false) .setPauseRotationWhenUnfolding(false)
.setMaxHingeAngle(165) .setMaxHingeAngle(165)
.setHingeAngleRotationBlockTimeMs(400) .setHingeAngleRotationBlockTimeMs(400)
@@ -1091,7 +1119,7 @@ public class DisplayRotationTests {
@Test @Test
public void testSensorRotationAfterHingeEventAfterTimeout_usesSensorData() throws Exception { public void testSensorRotationAfterHingeEventAfterTimeout_usesSensorData() throws Exception {
mBuilder.setSupportHalfFoldAutoRotateOverride(true) mBuilder.setIsFoldable(true)
.setPauseRotationWhenUnfolding(true) .setPauseRotationWhenUnfolding(true)
.setMaxHingeAngle(165) .setMaxHingeAngle(165)
.setHingeAngleRotationBlockTimeMs(400) .setHingeAngleRotationBlockTimeMs(400)
@@ -1111,7 +1139,7 @@ public class DisplayRotationTests {
@Test @Test
public void testSensorRotationAfterLargeHingeEventBeforeTimeout_usesSensor() throws Exception { public void testSensorRotationAfterLargeHingeEventBeforeTimeout_usesSensor() throws Exception {
mBuilder.setSupportHalfFoldAutoRotateOverride(true) mBuilder.setIsFoldable(true)
.setPauseRotationWhenUnfolding(true) .setPauseRotationWhenUnfolding(true)
.setMaxHingeAngle(165) .setMaxHingeAngle(165)
.setHingeAngleRotationBlockTimeMs(400) .setHingeAngleRotationBlockTimeMs(400)
@@ -1228,6 +1256,7 @@ public class DisplayRotationTests {
private int mCarDockRotation; private int mCarDockRotation;
private int mDeskDockRotation; private int mDeskDockRotation;
private int mUndockedHdmiRotation; private int mUndockedHdmiRotation;
private boolean mIsFoldable;
private DisplayRotationBuilder setIsDefaultDisplay(boolean isDefaultDisplay) { private DisplayRotationBuilder setIsDefaultDisplay(boolean isDefaultDisplay) {
mIsDefaultDisplay = isDefaultDisplay; mIsDefaultDisplay = isDefaultDisplay;
@@ -1282,9 +1311,17 @@ public class DisplayRotationTests {
return this; return this;
} }
private DisplayRotationBuilder setIsFoldable(boolean value) {
mIsFoldable = value;
return this;
}
private DisplayRotationBuilder setSupportHalfFoldAutoRotateOverride( private DisplayRotationBuilder setSupportHalfFoldAutoRotateOverride(
boolean supportHalfFoldAutoRotateOverride) { boolean supportHalfFoldAutoRotateOverride) {
mSupportHalfFoldAutoRotateOverride = supportHalfFoldAutoRotateOverride; mSupportHalfFoldAutoRotateOverride = supportHalfFoldAutoRotateOverride;
if (supportHalfFoldAutoRotateOverride) {
mIsFoldable = true;
}
return this; return this;
} }
@@ -1429,6 +1466,11 @@ public class DisplayRotationTests {
when(mMockContext.getResources().getBoolean( when(mMockContext.getResources().getBoolean(
com.android.internal.R.bool.config_windowManagerHalfFoldAutoRotateOverride)) com.android.internal.R.bool.config_windowManagerHalfFoldAutoRotateOverride))
.thenReturn(mSupportHalfFoldAutoRotateOverride); .thenReturn(mSupportHalfFoldAutoRotateOverride);
when(mMockContext.getResources().getIntArray(
R.array.config_foldedDeviceStates))
.thenReturn(mIsFoldable ? new int[]{0} : new int[]{});
mMockDisplayRotationReversionController = mMockDisplayRotationReversionController =
mock(DisplayRotationReversionController.class); mock(DisplayRotationReversionController.class);
when(mMockDisplayContent.getRotationReversionController()) when(mMockDisplayContent.getRotationReversionController())