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);
mSettingsObserver = new SettingsObserver(uiHandler);
mSettingsObserver.observe();
if (mSupportAutoRotation && mContext.getResources().getBoolean(
R.bool.config_windowManagerHalfFoldAutoRotateOverride)) {
if (mSupportAutoRotation && isFoldable(mContext)) {
mFoldController = new FoldController();
} else {
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
@Nullable
DisplayRotationImmersiveAppCompatPolicy initImmersiveAppCompatPolicy(
@@ -1463,11 +1466,6 @@ public class DisplayRotation {
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.
if (isTabletopAutoRotateOverrideEnabled()) return false;
@@ -1775,8 +1773,11 @@ public class DisplayRotation {
private SensorEventListener mHingeAngleSensorEventListener;
private final Set<Integer> mTabletopRotations;
private final Runnable mActivityBoundsUpdateCallback;
private final boolean mAllowHalfFoldAutoRotationOverride;
FoldController() {
mAllowHalfFoldAutoRotationOverride = mContext.getResources().getBoolean(
R.bool.config_windowManagerHalfFoldAutoRotateOverride);
mTabletopRotations = new ArraySet<>();
int[] tabletop_rotations = mContext.getResources().getIntArray(
R.array.config_deviceTabletopRotations);
@@ -1894,12 +1895,14 @@ public class DisplayRotation {
}
boolean overrideFrozenRotation() {
return mDeviceState == DeviceStateController.DeviceState.HALF_FOLDED;
return mAllowHalfFoldAutoRotationOverride
&& mDeviceState == DeviceStateController.DeviceState.HALF_FOLDED;
}
boolean shouldRevertOverriddenRotation() {
// When transitioning to open.
return mDeviceState == DeviceStateController.DeviceState.OPEN
return mAllowHalfFoldAutoRotationOverride
&& mDeviceState == DeviceStateController.DeviceState.OPEN
&& !mShouldIgnoreSensorRotation // Ignore if the hinge angle still moving
&& mInHalfFoldTransition
&& mDisplayContent.getRotationReversionController().isOverrideActive(

View File

@@ -73,6 +73,7 @@ import android.view.WindowManager;
import androidx.annotation.Nullable;
import androidx.test.filters.SmallTest;
import com.android.internal.R;
import com.android.internal.util.test.FakeSettingsProvider;
import com.android.server.LocalServices;
import com.android.server.UiThread;
@@ -879,6 +880,33 @@ public class DisplayRotationTests {
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
// =================================
@@ -1016,7 +1044,7 @@ public class DisplayRotationTests {
@Test
public void testSensorRotationAfterDisplayChangeBeforeTimeout_ignoresSensor() throws Exception {
mBuilder.setSupportHalfFoldAutoRotateOverride(true)
mBuilder.setIsFoldable(true)
.setPauseRotationWhenUnfolding(true)
.setDisplaySwitchRotationBlockTimeMs(1000)
.build();
@@ -1034,7 +1062,7 @@ public class DisplayRotationTests {
@Test
public void testSensorRotationAfterDisplayChangeAfterTimeout_usesSensor() throws Exception {
mBuilder.setSupportHalfFoldAutoRotateOverride(true)
mBuilder.setIsFoldable(true)
.setPauseRotationWhenUnfolding(true)
.setDisplaySwitchRotationBlockTimeMs(1000)
.build();
@@ -1052,7 +1080,7 @@ public class DisplayRotationTests {
@Test
public void testSensorRotationAfterHingeEventBeforeTimeout_ignoresSensor() throws Exception {
mBuilder.setSupportHalfFoldAutoRotateOverride(true)
mBuilder.setIsFoldable(true)
.setPauseRotationWhenUnfolding(true)
.setMaxHingeAngle(165)
.setHingeAngleRotationBlockTimeMs(400)
@@ -1072,7 +1100,7 @@ public class DisplayRotationTests {
@Test
public void testSensorRotationAfterHingeEventBeforeTimeoutFlagDisabled_usesSensorData()
throws Exception {
mBuilder.setSupportHalfFoldAutoRotateOverride(true)
mBuilder.setIsFoldable(true)
.setPauseRotationWhenUnfolding(false)
.setMaxHingeAngle(165)
.setHingeAngleRotationBlockTimeMs(400)
@@ -1091,7 +1119,7 @@ public class DisplayRotationTests {
@Test
public void testSensorRotationAfterHingeEventAfterTimeout_usesSensorData() throws Exception {
mBuilder.setSupportHalfFoldAutoRotateOverride(true)
mBuilder.setIsFoldable(true)
.setPauseRotationWhenUnfolding(true)
.setMaxHingeAngle(165)
.setHingeAngleRotationBlockTimeMs(400)
@@ -1111,7 +1139,7 @@ public class DisplayRotationTests {
@Test
public void testSensorRotationAfterLargeHingeEventBeforeTimeout_usesSensor() throws Exception {
mBuilder.setSupportHalfFoldAutoRotateOverride(true)
mBuilder.setIsFoldable(true)
.setPauseRotationWhenUnfolding(true)
.setMaxHingeAngle(165)
.setHingeAngleRotationBlockTimeMs(400)
@@ -1228,6 +1256,7 @@ public class DisplayRotationTests {
private int mCarDockRotation;
private int mDeskDockRotation;
private int mUndockedHdmiRotation;
private boolean mIsFoldable;
private DisplayRotationBuilder setIsDefaultDisplay(boolean isDefaultDisplay) {
mIsDefaultDisplay = isDefaultDisplay;
@@ -1282,9 +1311,17 @@ public class DisplayRotationTests {
return this;
}
private DisplayRotationBuilder setIsFoldable(boolean value) {
mIsFoldable = value;
return this;
}
private DisplayRotationBuilder setSupportHalfFoldAutoRotateOverride(
boolean supportHalfFoldAutoRotateOverride) {
mSupportHalfFoldAutoRotateOverride = supportHalfFoldAutoRotateOverride;
if (supportHalfFoldAutoRotateOverride) {
mIsFoldable = true;
}
return this;
}
@@ -1429,6 +1466,11 @@ public class DisplayRotationTests {
when(mMockContext.getResources().getBoolean(
com.android.internal.R.bool.config_windowManagerHalfFoldAutoRotateOverride))
.thenReturn(mSupportHalfFoldAutoRotateOverride);
when(mMockContext.getResources().getIntArray(
R.array.config_foldedDeviceStates))
.thenReturn(mIsFoldable ? new int[]{0} : new int[]{});
mMockDisplayRotationReversionController =
mock(DisplayRotationReversionController.class);
when(mMockDisplayContent.getRotationReversionController())