Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 41d2239a authored by Kevin Chyn's avatar Kevin Chyn
Browse files

Add and use config_deviceStatesToReverseDefaultDisplayRotationAroundZAxis

The config defines a list of device states for which rotation anchored
on the Z axis should be reversed

Fixes: 264499484
Test: atest DisplayRotationTests

Change-Id: Ie9371b0f755d2d7852bc5244c5a06951a81051af
parent 0345d61b
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -974,6 +974,12 @@
    <!-- Boolean indicating whether light mode is allowed when DWB is turned on. -->
    <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. -->
    <integer-array name="config_availableColorModes">
        <!-- Example:
+5 −0
Original line number Diff line number Diff line
@@ -3385,6 +3385,11 @@
  <java-symbol type="array" name="config_displayWhiteBalanceDisplayNominalWhite" />
  <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 user restrictions for the SYSTEM user -->
  <java-symbol type="array" name="config_defaultFirstUserRestrictions" />

+15 −0
Original line number Diff line number Diff line
@@ -47,10 +47,13 @@ final class DeviceStateController implements DeviceStateManager.DeviceStateCallb
    @NonNull
    private final int[] mRearDisplayDeviceStates;
    @NonNull
    private final int[] mReverseRotationAroundZAxisStates;
    @NonNull
    private final List<Consumer<DeviceState>> mDeviceStateCallbacks = new ArrayList<>();

    @Nullable
    private DeviceState mLastDeviceState;
    private int mCurrentState;

    public enum DeviceState {
        UNKNOWN, OPEN, FOLDED, HALF_FOLDED, REAR,
@@ -58,6 +61,7 @@ final class DeviceStateController implements DeviceStateManager.DeviceStateCallb

    DeviceStateController(@NonNull Context context, @NonNull Handler handler) {
        mDeviceStateManager = context.getSystemService(DeviceStateManager.class);

        mOpenDeviceStates = context.getResources()
                .getIntArray(R.array.config_openDeviceStates);
        mHalfFoldedDeviceStates = context.getResources()
@@ -66,6 +70,8 @@ final class DeviceStateController implements DeviceStateManager.DeviceStateCallb
                .getIntArray(R.array.config_foldedDeviceStates);
        mRearDisplayDeviceStates = context.getResources()
                .getIntArray(R.array.config_rearDisplayDeviceStates);
        mReverseRotationAroundZAxisStates = context.getResources()
                .getIntArray(R.array.config_deviceStatesToReverseDefaultDisplayRotationAroundZAxis);

        if (mDeviceStateManager != null) {
            mDeviceStateManager.registerCallback(new HandlerExecutor(handler), this);
@@ -82,8 +88,17 @@ final class DeviceStateController implements DeviceStateManager.DeviceStateCallb
        mDeviceStateCallbacks.add(callback);
    }

    /**
     * @return true if the rotation direction on the Z axis should be reversed.
     */
    boolean shouldReverseRotationDirectionAroundZAxis() {
        return ArrayUtils.contains(mReverseRotationAroundZAxisStates, mCurrentState);
    }

    @Override
    public void onStateChanged(int state) {
        mCurrentState = state;

        final DeviceState deviceState;
        if (ArrayUtils.contains(mHalfFoldedDeviceStates, state)) {
            deviceState = DeviceState.HALF_FOLDED;
+2 −1
Original line number Diff line number Diff line
@@ -1148,7 +1148,8 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
        mDeviceStateController = new DeviceStateController(mWmService.mContext, mWmService.mH);

        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 =
                (@NonNull DeviceStateController.DeviceState newFoldState) -> {
+18 −3
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ import static com.android.server.wm.WindowManagerService.WINDOW_FREEZE_TIMEOUT_D

import android.annotation.AnimRes;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.ActivityManager;
import android.content.ContentResolver;
@@ -117,6 +118,8 @@ public class DisplayRotation {
    private SettingsObserver mSettingsObserver;
    @Nullable
    private FoldController mFoldController;
    @NonNull
    private final DeviceStateController mDeviceStateController;

    @ScreenOrientation
    private int mCurrentAppOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
@@ -218,21 +221,24 @@ public class DisplayRotation {
    private boolean mDemoRotationLock;

    DisplayRotation(WindowManagerService service, DisplayContent displayContent,
            DisplayAddress displayAddress) {
            DisplayAddress displayAddress, @NonNull DeviceStateController deviceStateController) {
        this(service, displayContent, displayAddress, displayContent.getDisplayPolicy(),
                service.mDisplayWindowSettings, service.mContext, service.getWindowManagerLock());
                service.mDisplayWindowSettings, service.mContext, service.getWindowManagerLock(),
                deviceStateController);
    }

    @VisibleForTesting
    DisplayRotation(WindowManagerService service, DisplayContent displayContent,
            DisplayAddress displayAddress, DisplayPolicy displayPolicy,
            DisplayWindowSettings displayWindowSettings, Context context, Object lock) {
            DisplayWindowSettings displayWindowSettings, Context context, Object lock,
            @NonNull DeviceStateController deviceStateController) {
        mService = service;
        mDisplayContent = displayContent;
        mDisplayPolicy = displayPolicy;
        mDisplayWindowSettings = displayWindowSettings;
        mContext = context;
        mLock = lock;
        mDeviceStateController = deviceStateController;
        isDefaultDisplay = displayContent.isDefaultDisplay;
        mCompatPolicyForImmersiveApps = initImmersiveAppCompatPolicy(service, displayContent);

@@ -1137,6 +1143,15 @@ public class DisplayRotation {
        int sensorRotation = mOrientationListener != null
                ? mOrientationListener.getProposedRotation() // may be -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;
        if (sensorRotation < 0) {
            sensorRotation = lastRotation;
Loading