summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Chris Göllner <chrisgollner@google.com> 2023-07-27 11:54:19 +0100
committer Chris Göllner <chrisgollner@google.com> 2023-07-27 12:14:16 +0100
commit8749e0ad555501712487e8746cc966dfcfd4a69f (patch)
treea9291b3ad82d1e86fc0517bc538536701d275931
parent9ed6c4f9a406844ecef8753972f9babf03af8dcb (diff)
Disable table top auto-rotation override
- Sets the resource config to false, that controls the override - Also removes the code that was preventing the auto-rotation suggestion button from showing Test: DisplayRotationTests.java Test: Manually - Go into tabletop Bug: 282072452 Change-Id: If1bcfef89e7233207b0296eb0effb9d2508a0d85
-rw-r--r--services/core/java/com/android/server/wm/DisplayRotation.java21
-rw-r--r--services/tests/wmtests/src/com/android/server/wm/DisplayRotationTests.java54
2 files changed, 60 insertions, 15 deletions
diff --git a/services/core/java/com/android/server/wm/DisplayRotation.java b/services/core/java/com/android/server/wm/DisplayRotation.java
index b681c198538f..ed3fad0dd3e7 100644
--- a/services/core/java/com/android/server/wm/DisplayRotation.java
+++ b/services/core/java/com/android/server/wm/DisplayRotation.java
@@ -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(
diff --git a/services/tests/wmtests/src/com/android/server/wm/DisplayRotationTests.java b/services/tests/wmtests/src/com/android/server/wm/DisplayRotationTests.java
index 2a8f0ffc4d49..f7573303d887 100644
--- a/services/tests/wmtests/src/com/android/server/wm/DisplayRotationTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/DisplayRotationTests.java
@@ -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())