summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--services/core/java/com/android/server/wm/DisplayRotation.java28
-rw-r--r--services/tests/wmtests/src/com/android/server/wm/DisplayRotationTests.java67
2 files changed, 86 insertions, 9 deletions
diff --git a/services/core/java/com/android/server/wm/DisplayRotation.java b/services/core/java/com/android/server/wm/DisplayRotation.java
index 5aacb094207e..2f8754789016 100644
--- a/services/core/java/com/android/server/wm/DisplayRotation.java
+++ b/services/core/java/com/android/server/wm/DisplayRotation.java
@@ -1224,16 +1224,8 @@ public class DisplayRotation {
|| orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
// Otherwise, use sensor only if requested by the application or enabled
// by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR.
- if (mAllowAllRotations == ALLOW_ALL_ROTATIONS_UNDEFINED) {
- // Can't read this during init() because the context doesn't have display metrics at
- // that time so we cannot determine tablet vs. phone then.
- mAllowAllRotations = mContext.getResources().getBoolean(
- R.bool.config_allowAllRotations)
- ? ALLOW_ALL_ROTATIONS_ENABLED
- : ALLOW_ALL_ROTATIONS_DISABLED;
- }
if (sensorRotation != Surface.ROTATION_180
- || mAllowAllRotations == ALLOW_ALL_ROTATIONS_ENABLED
+ || getAllowAllRotations() == ALLOW_ALL_ROTATIONS_ENABLED
|| orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
|| orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) {
preferredRotation = sensorRotation;
@@ -1322,6 +1314,19 @@ public class DisplayRotation {
}
}
+ private int getAllowAllRotations() {
+ if (mAllowAllRotations == ALLOW_ALL_ROTATIONS_UNDEFINED) {
+ // Can't read this during init() because the context doesn't have display metrics at
+ // that time so we cannot determine tablet vs. phone then.
+ mAllowAllRotations = mContext.getResources().getBoolean(
+ R.bool.config_allowAllRotations)
+ ? ALLOW_ALL_ROTATIONS_ENABLED
+ : ALLOW_ALL_ROTATIONS_DISABLED;
+ }
+
+ return mAllowAllRotations;
+ }
+
private boolean isLandscapeOrSeascape(int rotation) {
return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
}
@@ -1349,6 +1354,11 @@ public class DisplayRotation {
case ActivityInfo.SCREEN_ORIENTATION_USER:
case ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED:
+ // When all rotations enabled it works with any of the 4 rotations
+ if (getAllowAllRotations() == ALLOW_ALL_ROTATIONS_ENABLED) {
+ return preferredRotation >= 0;
+ }
+
// Works with any rotation except upside down.
return (preferredRotation >= 0) && (preferredRotation != Surface.ROTATION_180);
}
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 25cff61c3b78..a3c41f357665 100644
--- a/services/tests/wmtests/src/com/android/server/wm/DisplayRotationTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/DisplayRotationTests.java
@@ -40,7 +40,9 @@ import static com.android.dx.mockito.inline.extended.ExtendedMockito.when;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.clearInvocations;
+import android.app.WindowConfiguration;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
@@ -515,6 +517,69 @@ public class DisplayRotationTests {
}
@Test
+ public void testAllowAllRotations_allowsUpsideDownSuggestion()
+ throws Exception {
+ mBuilder.build();
+ mTarget.updateOrientation(SCREEN_ORIENTATION_UNSPECIFIED, true);
+ configureDisplayRotation(SCREEN_ORIENTATION_LANDSCAPE, false, false);
+ when(mMockRes.getBoolean(com.android.internal.R.bool.config_allowAllRotations))
+ .thenReturn(true);
+ freezeRotation(Surface.ROTATION_0);
+ enableOrientationSensor();
+
+ mOrientationSensorListener.onSensorChanged(createSensorEvent(Surface.ROTATION_180));
+ assertTrue(waitForUiHandler());
+
+ verify(mMockStatusBarManagerInternal)
+ .onProposedRotationChanged(Surface.ROTATION_180, true);
+ }
+
+ @Test
+ public void testDoNotAllowAllRotations_doesNotAllowUpsideDownSuggestion()
+ throws Exception {
+ mBuilder.build();
+ mTarget.updateOrientation(SCREEN_ORIENTATION_UNSPECIFIED, true);
+ configureDisplayRotation(SCREEN_ORIENTATION_LANDSCAPE, false, false);
+ when(mMockRes.getBoolean(com.android.internal.R.bool.config_allowAllRotations))
+ .thenReturn(false);
+ freezeRotation(Surface.ROTATION_0);
+ enableOrientationSensor();
+
+ mOrientationSensorListener.onSensorChanged(createSensorEvent(Surface.ROTATION_180));
+ assertTrue(waitForUiHandler());
+
+ verify(mMockStatusBarManagerInternal)
+ .onProposedRotationChanged(Surface.ROTATION_180, false);
+ }
+
+ @Test
+ public void testAllowAllRotations_allowAllRotationsBecomesDisabled_forbidsUpsideDownSuggestion()
+ throws Exception {
+ mBuilder.build();
+ mTarget.updateOrientation(SCREEN_ORIENTATION_UNSPECIFIED, true);
+ configureDisplayRotation(SCREEN_ORIENTATION_LANDSCAPE, false, false);
+ when(mMockRes.getBoolean(com.android.internal.R.bool.config_allowAllRotations))
+ .thenReturn(true);
+ freezeRotation(Surface.ROTATION_0);
+ enableOrientationSensor();
+ mOrientationSensorListener.onSensorChanged(createSensorEvent(Surface.ROTATION_0));
+ assertTrue(waitForUiHandler());
+
+ // Change resource to disallow all rotations.
+ // Reset "allowAllRotations".
+ mTarget.applyCurrentRotation(Surface.ROTATION_0);
+ clearInvocations(mMockStatusBarManagerInternal);
+ when(mMockRes.getBoolean(com.android.internal.R.bool.config_allowAllRotations))
+ .thenReturn(false);
+ mTarget.resetAllowAllRotations();
+ mOrientationSensorListener.onSensorChanged(createSensorEvent(Surface.ROTATION_180));
+ assertTrue(waitForUiHandler());
+
+ verify(mMockStatusBarManagerInternal)
+ .onProposedRotationChanged(Surface.ROTATION_180, false);
+ }
+
+ @Test
public void testReturnsCompatibleRotation_SensorEnabled_RotationThawed() throws Exception {
mBuilder.build();
configureDisplayRotation(SCREEN_ORIENTATION_PORTRAIT, false, false);
@@ -935,6 +1000,8 @@ public class DisplayRotationTests {
.thenReturn(WmDisplayCutout.NO_CUTOUT);
when(mMockDisplayContent.getDefaultTaskDisplayArea())
.thenReturn(mock(TaskDisplayArea.class));
+ when(mMockDisplayContent.getWindowConfiguration())
+ .thenReturn(new WindowConfiguration());
mMockDisplayPolicy = mock(DisplayPolicy.class);