Add a flag to fix to user rotation for non auto rotation

Wrist orientation shows the screen with the user rotation
except for special cases (docking etc.).
However, if auto rotation is not supported,
user rotation is ignored and rotation is set to 0,
so rotation is not displayed as intended.

Add a new mode to prioritize user rotation
when auto rotation is not supported.

Bug: 272527836
Test: atest WmTests:DisplayRotationTests
Change-Id: I0564d797db7cd98374d406483a30f6ad6aa399aa
This commit is contained in:
YoungJoon Yang
2023-06-21 16:25:45 +09:00
parent 5e56f8b903
commit 19b7b98a85
3 changed files with 40 additions and 3 deletions

View File

@@ -93,6 +93,11 @@ interface IWindowManager
* Only use {@link DisplayRotation#mUserRotation} as the display rotation.
*/
const int FIXED_TO_USER_ROTATION_ENABLED = 2;
/**
* If auto-rotation is not supported, {@link DisplayRotation#mUserRotation} will be used.
* Otherwise the behavior is same as {link #FIXED_TO_USER_ROTATION_DISABLED}.
*/
const int FIXED_TO_USER_ROTATION_IF_NO_AUTO_ROTATION = 3;
/**
* ===== NOTICE =====

View File

@@ -977,6 +977,8 @@ public class DisplayRotation {
return false;
case IWindowManager.FIXED_TO_USER_ROTATION_ENABLED:
return true;
case IWindowManager.FIXED_TO_USER_ROTATION_IF_NO_AUTO_ROTATION:
return false;
default:
return mDefaultFixedToUserRotation;
}
@@ -1290,9 +1292,13 @@ public class DisplayRotation {
// Application just wants to remain locked in the last rotation.
preferredRotation = lastRotation;
} else if (!mSupportAutoRotation) {
// If we don't support auto-rotation then bail out here and ignore
// the sensor and any rotation lock settings.
preferredRotation = -1;
if (mFixedToUserRotation == IWindowManager.FIXED_TO_USER_ROTATION_IF_NO_AUTO_ROTATION) {
preferredRotation = mUserRotation;
} else {
// If we don't support auto-rotation then bail out here and ignore
// the sensor and any rotation lock settings.
preferredRotation = -1;
}
} else if (((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
|| isTabletopAutoRotateOverrideEnabled())
&& (orientation == ActivityInfo.SCREEN_ORIENTATION_USER

View File

@@ -26,6 +26,7 @@ import static android.view.DisplayCutout.NO_CUTOUT;
import static android.view.IWindowManager.FIXED_TO_USER_ROTATION_DEFAULT;
import static android.view.IWindowManager.FIXED_TO_USER_ROTATION_DISABLED;
import static android.view.IWindowManager.FIXED_TO_USER_ROTATION_ENABLED;
import static android.view.IWindowManager.FIXED_TO_USER_ROTATION_IF_NO_AUTO_ROTATION;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.any;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.anyBoolean;
@@ -1128,6 +1129,22 @@ public class DisplayRotationTests {
SCREEN_ORIENTATION_UNSPECIFIED, Surface.ROTATION_0));
}
@Test
public void testReturnsUserRotation_FixedToUserRotationIfNoAutoRotation_AutoRotationNotSupport()
throws Exception {
mBuilder.setSupportAutoRotation(false).build();
configureDisplayRotation(SCREEN_ORIENTATION_PORTRAIT, false, false);
mTarget.setFixedToUserRotation(FIXED_TO_USER_ROTATION_IF_NO_AUTO_ROTATION);
freezeRotation(Surface.ROTATION_180);
assertEquals(WindowManagerPolicy.USER_ROTATION_LOCKED, mTarget.getUserRotationMode());
assertEquals(Surface.ROTATION_180, mTarget.getUserRotation());
assertEquals(Surface.ROTATION_180, mTarget.rotationForOrientation(
SCREEN_ORIENTATION_UNSPECIFIED, Surface.ROTATION_0));
}
// ========================
// Non-rotation API Tests
// ========================
@@ -1148,6 +1165,15 @@ public class DisplayRotationTests {
+ " fixed to user rotation.", mTarget.isFixedToUserRotation());
}
@Test
public void testIsFixedToUserRotation_FixedToUserRotationIfNoAutoRotation() throws Exception {
mBuilder.build();
mTarget.setFixedToUserRotation(FIXED_TO_USER_ROTATION_IF_NO_AUTO_ROTATION);
assertFalse("Display rotation should respect app requested orientation if"
+ " fixed to user rotation if no auto rotation.", mTarget.isFixedToUserRotation());
}
private void moveTimeForward(long timeMillis) {
sCurrentUptimeMillis += timeMillis;
sClock.fastForward(timeMillis);