Merge "Add and use config_deviceStatesToReverseDefaultDisplayRotationAroundZAxis" into tm-qpr-dev

This commit is contained in:
Kevin Chyn
2023-01-27 08:51:12 +00:00
committed by Android (Google) Code Review
6 changed files with 84 additions and 5 deletions

View File

@@ -984,6 +984,12 @@
<!-- Boolean indicating whether light mode is allowed when DWB is turned on. --> <!-- Boolean indicating whether light mode is allowed when DWB is turned on. -->
<bool name="config_displayWhiteBalanceLightModeAllowed">true</bool> <bool name="config_displayWhiteBalanceLightModeAllowed">true</bool>
<!-- Device states where the sensor based rotation values should be reversed around the Z axis
for the default display.
TODO(b/265312193): Remove this workaround when this bug is fixed.-->
<integer-array name="config_deviceStatesToReverseDefaultDisplayRotationAroundZAxis">
</integer-array>
<!-- Indicate available ColorDisplayManager.COLOR_MODE_xxx. --> <!-- Indicate available ColorDisplayManager.COLOR_MODE_xxx. -->
<integer-array name="config_availableColorModes"> <integer-array name="config_availableColorModes">
<!-- Example: <!-- Example:

View File

@@ -3436,6 +3436,11 @@
<java-symbol type="array" name="config_displayWhiteBalanceDisplayNominalWhite" /> <java-symbol type="array" name="config_displayWhiteBalanceDisplayNominalWhite" />
<java-symbol type="bool" name="config_displayWhiteBalanceLightModeAllowed" /> <java-symbol type="bool" name="config_displayWhiteBalanceLightModeAllowed" />
<!-- Device states where the sensor based rotation values should be reversed around the Z axis
for the default display.
TODO(b/265312193): Remove this workaround when this bug is fixed.-->
<java-symbol type="array" name="config_deviceStatesToReverseDefaultDisplayRotationAroundZAxis" />
<!-- Default first user restrictions --> <!-- Default first user restrictions -->
<java-symbol type="array" name="config_defaultFirstUserRestrictions" /> <java-symbol type="array" name="config_defaultFirstUserRestrictions" />

View File

@@ -47,10 +47,13 @@ final class DeviceStateController implements DeviceStateManager.DeviceStateCallb
@NonNull @NonNull
private final int[] mRearDisplayDeviceStates; private final int[] mRearDisplayDeviceStates;
@NonNull @NonNull
private final int[] mReverseRotationAroundZAxisStates;
@NonNull
private final List<Consumer<DeviceState>> mDeviceStateCallbacks = new ArrayList<>(); private final List<Consumer<DeviceState>> mDeviceStateCallbacks = new ArrayList<>();
@Nullable @Nullable
private DeviceState mLastDeviceState; private DeviceState mLastDeviceState;
private int mCurrentState;
public enum DeviceState { public enum DeviceState {
UNKNOWN, OPEN, FOLDED, HALF_FOLDED, REAR, UNKNOWN, OPEN, FOLDED, HALF_FOLDED, REAR,
@@ -58,6 +61,7 @@ final class DeviceStateController implements DeviceStateManager.DeviceStateCallb
DeviceStateController(@NonNull Context context, @NonNull Handler handler) { DeviceStateController(@NonNull Context context, @NonNull Handler handler) {
mDeviceStateManager = context.getSystemService(DeviceStateManager.class); mDeviceStateManager = context.getSystemService(DeviceStateManager.class);
mOpenDeviceStates = context.getResources() mOpenDeviceStates = context.getResources()
.getIntArray(R.array.config_openDeviceStates); .getIntArray(R.array.config_openDeviceStates);
mHalfFoldedDeviceStates = context.getResources() mHalfFoldedDeviceStates = context.getResources()
@@ -66,6 +70,8 @@ final class DeviceStateController implements DeviceStateManager.DeviceStateCallb
.getIntArray(R.array.config_foldedDeviceStates); .getIntArray(R.array.config_foldedDeviceStates);
mRearDisplayDeviceStates = context.getResources() mRearDisplayDeviceStates = context.getResources()
.getIntArray(R.array.config_rearDisplayDeviceStates); .getIntArray(R.array.config_rearDisplayDeviceStates);
mReverseRotationAroundZAxisStates = context.getResources()
.getIntArray(R.array.config_deviceStatesToReverseDefaultDisplayRotationAroundZAxis);
if (mDeviceStateManager != null) { if (mDeviceStateManager != null) {
mDeviceStateManager.registerCallback(new HandlerExecutor(handler), this); mDeviceStateManager.registerCallback(new HandlerExecutor(handler), this);
@@ -82,8 +88,17 @@ final class DeviceStateController implements DeviceStateManager.DeviceStateCallb
mDeviceStateCallbacks.add(callback); mDeviceStateCallbacks.add(callback);
} }
/**
* @return true if the rotation direction on the Z axis should be reversed.
*/
boolean shouldReverseRotationDirectionAroundZAxis() {
return ArrayUtils.contains(mReverseRotationAroundZAxisStates, mCurrentState);
}
@Override @Override
public void onStateChanged(int state) { public void onStateChanged(int state) {
mCurrentState = state;
final DeviceState deviceState; final DeviceState deviceState;
if (ArrayUtils.contains(mHalfFoldedDeviceStates, state)) { if (ArrayUtils.contains(mHalfFoldedDeviceStates, state)) {
deviceState = DeviceState.HALF_FOLDED; deviceState = DeviceState.HALF_FOLDED;

View File

@@ -1128,7 +1128,8 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
mDeviceStateController = new DeviceStateController(mWmService.mContext, mWmService.mH); mDeviceStateController = new DeviceStateController(mWmService.mContext, mWmService.mH);
mDisplayPolicy = new DisplayPolicy(mWmService, this); mDisplayPolicy = new DisplayPolicy(mWmService, this);
mDisplayRotation = new DisplayRotation(mWmService, this, mDisplayInfo.address); mDisplayRotation = new DisplayRotation(mWmService, this, mDisplayInfo.address,
mDeviceStateController);
final Consumer<DeviceStateController.DeviceState> deviceStateConsumer = final Consumer<DeviceStateController.DeviceState> deviceStateConsumer =
(@NonNull DeviceStateController.DeviceState newFoldState) -> { (@NonNull DeviceStateController.DeviceState newFoldState) -> {

View File

@@ -41,6 +41,7 @@ import static com.android.server.wm.WindowManagerService.WINDOW_FREEZE_TIMEOUT_D
import android.annotation.AnimRes; import android.annotation.AnimRes;
import android.annotation.IntDef; import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable; import android.annotation.Nullable;
import android.app.ActivityManager; import android.app.ActivityManager;
import android.content.ContentResolver; import android.content.ContentResolver;
@@ -117,6 +118,8 @@ public class DisplayRotation {
private SettingsObserver mSettingsObserver; private SettingsObserver mSettingsObserver;
@Nullable @Nullable
private FoldController mFoldController; private FoldController mFoldController;
@NonNull
private final DeviceStateController mDeviceStateController;
@ScreenOrientation @ScreenOrientation
private int mCurrentAppOrientation = SCREEN_ORIENTATION_UNSPECIFIED; private int mCurrentAppOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
@@ -218,21 +221,24 @@ public class DisplayRotation {
private boolean mDemoRotationLock; private boolean mDemoRotationLock;
DisplayRotation(WindowManagerService service, DisplayContent displayContent, DisplayRotation(WindowManagerService service, DisplayContent displayContent,
DisplayAddress displayAddress) { DisplayAddress displayAddress, @NonNull DeviceStateController deviceStateController) {
this(service, displayContent, displayAddress, displayContent.getDisplayPolicy(), this(service, displayContent, displayAddress, displayContent.getDisplayPolicy(),
service.mDisplayWindowSettings, service.mContext, service.getWindowManagerLock()); service.mDisplayWindowSettings, service.mContext, service.getWindowManagerLock(),
deviceStateController);
} }
@VisibleForTesting @VisibleForTesting
DisplayRotation(WindowManagerService service, DisplayContent displayContent, DisplayRotation(WindowManagerService service, DisplayContent displayContent,
DisplayAddress displayAddress, DisplayPolicy displayPolicy, DisplayAddress displayAddress, DisplayPolicy displayPolicy,
DisplayWindowSettings displayWindowSettings, Context context, Object lock) { DisplayWindowSettings displayWindowSettings, Context context, Object lock,
@NonNull DeviceStateController deviceStateController) {
mService = service; mService = service;
mDisplayContent = displayContent; mDisplayContent = displayContent;
mDisplayPolicy = displayPolicy; mDisplayPolicy = displayPolicy;
mDisplayWindowSettings = displayWindowSettings; mDisplayWindowSettings = displayWindowSettings;
mContext = context; mContext = context;
mLock = lock; mLock = lock;
mDeviceStateController = deviceStateController;
isDefaultDisplay = displayContent.isDefaultDisplay; isDefaultDisplay = displayContent.isDefaultDisplay;
mCompatPolicyForImmersiveApps = initImmersiveAppCompatPolicy(service, displayContent); mCompatPolicyForImmersiveApps = initImmersiveAppCompatPolicy(service, displayContent);
@@ -1137,6 +1143,15 @@ public class DisplayRotation {
int sensorRotation = mOrientationListener != null int sensorRotation = mOrientationListener != null
? mOrientationListener.getProposedRotation() // may be -1 ? mOrientationListener.getProposedRotation() // may be -1
: -1; : -1;
if (mDeviceStateController.shouldReverseRotationDirectionAroundZAxis()) {
// Flipping 270 and 90 has the same effect as changing the direction which rotation is
// applied.
if (sensorRotation == Surface.ROTATION_90) {
sensorRotation = Surface.ROTATION_270;
} else if (sensorRotation == Surface.ROTATION_270) {
sensorRotation = Surface.ROTATION_90;
}
}
mLastSensorRotation = sensorRotation; mLastSensorRotation = sensorRotation;
if (sensorRotation < 0) { if (sensorRotation < 0) {
sensorRotation = lastRotation; sensorRotation = lastRotation;

View File

@@ -56,6 +56,7 @@ import android.hardware.Sensor;
import android.hardware.SensorEvent; import android.hardware.SensorEvent;
import android.hardware.SensorEventListener; import android.hardware.SensorEventListener;
import android.hardware.SensorManager; import android.hardware.SensorManager;
import android.hardware.devicestate.DeviceStateManager;
import android.os.PowerManagerInternal; import android.os.PowerManagerInternal;
import android.os.SystemClock; import android.os.SystemClock;
import android.platform.test.annotations.Presubmit; import android.platform.test.annotations.Presubmit;
@@ -111,6 +112,7 @@ public class DisplayRotationTests {
private ContentResolver mMockResolver; private ContentResolver mMockResolver;
private FakeSettingsProvider mFakeSettingsProvider; private FakeSettingsProvider mFakeSettingsProvider;
private StatusBarManagerInternal mMockStatusBarManagerInternal; private StatusBarManagerInternal mMockStatusBarManagerInternal;
private DeviceStateManager mMockDeviceStateManager;
// Fields below are callbacks captured from test target. // Fields below are callbacks captured from test target.
private ContentObserver mShowRotationSuggestionsObserver; private ContentObserver mShowRotationSuggestionsObserver;
@@ -120,6 +122,7 @@ public class DisplayRotationTests {
private DisplayRotationBuilder mBuilder; private DisplayRotationBuilder mBuilder;
private DeviceStateController mDeviceStateController;
private DisplayRotation mTarget; private DisplayRotation mTarget;
@BeforeClass @BeforeClass
@@ -484,6 +487,34 @@ public class DisplayRotationTests {
SCREEN_ORIENTATION_UNSPECIFIED, Surface.ROTATION_0)); SCREEN_ORIENTATION_UNSPECIFIED, Surface.ROTATION_0));
} }
@Test
public void testReverseRotation() throws Exception {
mBuilder.build();
configureDisplayRotation(SCREEN_ORIENTATION_PORTRAIT, false, false);
when(mDeviceStateController.shouldReverseRotationDirectionAroundZAxis()).thenReturn(true);
thawRotation();
enableOrientationSensor();
mOrientationSensorListener.onSensorChanged(createSensorEvent(Surface.ROTATION_90));
assertEquals(Surface.ROTATION_270, mTarget.rotationForOrientation(
SCREEN_ORIENTATION_UNSPECIFIED, Surface.ROTATION_0));
mOrientationSensorListener.onSensorChanged(createSensorEvent(Surface.ROTATION_270));
assertEquals(Surface.ROTATION_90, mTarget.rotationForOrientation(
SCREEN_ORIENTATION_UNSPECIFIED, Surface.ROTATION_0));
mOrientationSensorListener.onSensorChanged(createSensorEvent(Surface.ROTATION_0));
assertEquals(Surface.ROTATION_0, mTarget.rotationForOrientation(
SCREEN_ORIENTATION_UNSPECIFIED, Surface.ROTATION_0));
mOrientationSensorListener.onSensorChanged(createSensorEvent(Surface.ROTATION_180));
assertEquals(Surface.ROTATION_180, mTarget.rotationForOrientation(
SCREEN_ORIENTATION_UNSPECIFIED, Surface.ROTATION_180));
}
private boolean waitForUiHandler() { private boolean waitForUiHandler() {
final CountDownLatch latch = new CountDownLatch(1); final CountDownLatch latch = new CountDownLatch(1);
UiThread.getHandler().post(latch::countDown); UiThread.getHandler().post(latch::countDown);
@@ -1097,8 +1128,14 @@ public class DisplayRotationTests {
mMockDisplayWindowSettings = mock(DisplayWindowSettings.class); mMockDisplayWindowSettings = mock(DisplayWindowSettings.class);
mMockDeviceStateManager = mock(DeviceStateManager.class);
when(mMockContext.getSystemService(eq(DeviceStateManager.class)))
.thenReturn(mMockDeviceStateManager);
mDeviceStateController = mock(DeviceStateController.class);
mTarget = new DisplayRotation(sMockWm, mMockDisplayContent, mMockDisplayAddress, mTarget = new DisplayRotation(sMockWm, mMockDisplayContent, mMockDisplayAddress,
mMockDisplayPolicy, mMockDisplayWindowSettings, mMockContext, new Object()) { mMockDisplayPolicy, mMockDisplayWindowSettings, mMockContext, new Object(),
mDeviceStateController) {
@Override @Override
DisplayRotationImmersiveAppCompatPolicy initImmersiveAppCompatPolicy( DisplayRotationImmersiveAppCompatPolicy initImmersiveAppCompatPolicy(
WindowManagerService service, DisplayContent displayContent) { WindowManagerService service, DisplayContent displayContent) {