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

Commit aa40ea26 authored by Nick Chameyev's avatar Nick Chameyev
Browse files

Do not turn on HALF_FOLDED rotation override when it is disabled

Currently, even if HALF_FOLDED rotation unlock
override is disabled through device configuration,
we still enable HALF_FOLDED override slot in
DisplayRotationReversionController.

We never disable it because we check if this functionality
is enabled when reverting slot (but not for enabling the slot).
This could cause other slots to misbehave as isAnyOverrideActive()
will always return true after moving to 'half folded' state
at least once.

Bug: 435043283
Flag: EXEMPT bugfix
Test: atest DisplayRotationTests
Test: manually check by going to half folded state
  => half_folded override slot is disabled
Change-Id: Ia002b28add106c786d6c5d204f8f35cde4d30436
parent e8976188
Loading
Loading
Loading
Loading
+27 −17
Original line number Original line Diff line number Diff line
@@ -1920,30 +1920,40 @@ public class DisplayRotation {
                mDeviceStateEnum = newState;
                mDeviceStateEnum = newState;
                return;
                return;
            }
            }
            if (newState == DeviceStateController.DeviceStateEnum.HALF_FOLDED

                    && mDeviceStateEnum != DeviceStateController.DeviceStateEnum.HALF_FOLDED) {
            final DeviceStateController.DeviceStateEnum oldState = mDeviceStateEnum;
                // The device has transitioned to HALF_FOLDED state: save the current rotation and
            mDeviceStateEnum = newState;
                // update the device rotation.

            handleDeviceStateChangeForHalfFoldOverride(oldState, newState);

            // Alert the activity of possible new bounds.
            UiThread.getHandler().removeCallbacks(mActivityBoundsUpdateCallback);
            UiThread.getHandler().postDelayed(mActivityBoundsUpdateCallback,
                    FOLDING_RECOMPUTE_CONFIG_DELAY_MS);
        }

        private void handleDeviceStateChangeForHalfFoldOverride(
                DeviceStateController.DeviceStateEnum oldState,
                DeviceStateController.DeviceStateEnum newState) {
            if (!mAllowHalfFoldAutoRotationOverride) return;

            final boolean switchingToHalfFolded =
                    newState == DeviceStateController.DeviceStateEnum.HALF_FOLDED
                    && mDeviceStateEnum != DeviceStateController.DeviceStateEnum.HALF_FOLDED;
            if (switchingToHalfFolded) {
                // The device has transitioned to HALF_FOLDED state: save the current rotation
                // and update the device rotation.
                mDisplayContent.getRotationReversionController().beforeOverrideApplied(
                mDisplayContent.getRotationReversionController().beforeOverrideApplied(
                        REVERSION_TYPE_HALF_FOLD);
                        REVERSION_TYPE_HALF_FOLD);
                mHalfFoldSavedRotation = mRotation;
                mHalfFoldSavedRotation = mRotation;
                mDeviceStateEnum = newState;
                // Now mFoldState is set to HALF_FOLDED, the overrideFrozenRotation function will
                // return true, so rotation is unlocked.
                mService.updateRotation(false /* alwaysSendConfiguration */,
                        false /* forceRelayout */);
            } else {
            } else {
                mInHalfFoldTransition = true;
                mInHalfFoldTransition = true;
                mDeviceStateEnum = newState;
            }

            // Tell the device to update its orientation.
            // Tell the device to update its orientation.
            mService.updateRotation(false /* alwaysSendConfiguration */,
            mService.updateRotation(false /* alwaysSendConfiguration */,
                    false /* forceRelayout */);
                    false /* forceRelayout */);
        }
        }
            // Alert the activity of possible new bounds.
            UiThread.getHandler().removeCallbacks(mActivityBoundsUpdateCallback);
            UiThread.getHandler().postDelayed(mActivityBoundsUpdateCallback,
                    FOLDING_RECOMPUTE_CONFIG_DELAY_MS);
        }


        boolean shouldIgnoreSensorRotation() {
        boolean shouldIgnoreSensorRotation() {
            return mShouldIgnoreSensorRotation;
            return mShouldIgnoreSensorRotation;
+16 −1
Original line number Original line Diff line number Diff line
@@ -53,6 +53,7 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.clearInvocations;
import static org.mockito.Mockito.clearInvocations;
import static org.mockito.Mockito.never;


import android.app.WindowConfiguration;
import android.app.WindowConfiguration;
import android.content.ContentResolver;
import android.content.ContentResolver;
@@ -1160,6 +1161,20 @@ public class DisplayRotationTests {
                SCREEN_ORIENTATION_UNSPECIFIED, Surface.ROTATION_0));
                SCREEN_ORIENTATION_UNSPECIFIED, Surface.ROTATION_0));
    }
    }


    @Test
    public void testHalfFoldOverrideDisabled_halfFolded_rotationOverrideIsNotApplied() throws Exception {
        mBuilder.setSupportHalfFoldAutoRotateOverride(false);
        mBuilder.build();
        configureDisplayRotation(SCREEN_ORIENTATION_LANDSCAPE, false, false);
        enableOrientationSensor();
        mTarget.foldStateChanged(DeviceStateController.DeviceStateEnum.OPEN);
        freezeRotation(Surface.ROTATION_270);

        mTarget.foldStateChanged(DeviceStateController.DeviceStateEnum.HALF_FOLDED);

        verify(mMockDisplayRotationReversionController, never()).beforeOverrideApplied(anyInt());
    }

    @Test
    @Test
    public void sensorRotation_locked_halfFolded_configOff_rotationUnchanged() throws Exception {
    public void sensorRotation_locked_halfFolded_configOff_rotationUnchanged() throws Exception {
        mBuilder.setIsFoldable(true);
        mBuilder.setIsFoldable(true);
@@ -1182,7 +1197,7 @@ public class DisplayRotationTests {
        // ... half-fold -> still no rotation
        // ... half-fold -> still no rotation
        mTarget.foldStateChanged(DeviceStateController.DeviceStateEnum.HALF_FOLDED);
        mTarget.foldStateChanged(DeviceStateController.DeviceStateEnum.HALF_FOLDED);
        assertTrue(waitForUiHandler());
        assertTrue(waitForUiHandler());
        verify(sMockWm).updateRotation(false, false);
        verify(sMockWm, never()).updateRotation(false, false);
        assertTrue(waitForUiHandler());
        assertTrue(waitForUiHandler());
        assertEquals(Surface.ROTATION_270, mTarget.rotationForOrientation(
        assertEquals(Surface.ROTATION_270, mTarget.rotationForOrientation(
                SCREEN_ORIENTATION_UNSPECIFIED, Surface.ROTATION_0));
                SCREEN_ORIENTATION_UNSPECIFIED, Surface.ROTATION_0));