Merge "Respect allowAllRotations for rotation suggestion button" into tm-dev am: 50cc288b94
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/17983847 Change-Id: Ib90b0d237eead246f142cfa2db3c7a6ec0d6929a Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
@@ -514,6 +516,69 @@ public class DisplayRotationTests {
|
||||
verify(mMockStatusBarManagerInternal).onProposedRotationChanged(Surface.ROTATION_90, true);
|
||||
}
|
||||
|
||||
@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();
|
||||
@@ -941,6 +1006,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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user