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

Commit a68a090c authored by Nick Chameyev's avatar Nick Chameyev Committed by Android (Google) Code Review
Browse files

Merge "Do not turn on HALF_FOLDED rotation override when it is disabled" into main

parents 580cdfe1 aa40ea26
Loading
Loading
Loading
Loading
+27 −17
Original line number Diff line number Diff line
@@ -1920,30 +1920,40 @@ public class DisplayRotation {
                mDeviceStateEnum = newState;
                return;
            }
            if (newState == DeviceStateController.DeviceStateEnum.HALF_FOLDED
                    && mDeviceStateEnum != DeviceStateController.DeviceStateEnum.HALF_FOLDED) {
                // The device has transitioned to HALF_FOLDED state: save the current rotation and
                // update the device rotation.

            final DeviceStateController.DeviceStateEnum oldState = mDeviceStateEnum;
            mDeviceStateEnum = newState;

            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(
                        REVERSION_TYPE_HALF_FOLD);
                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 {
                mInHalfFoldTransition = true;
                mDeviceStateEnum = newState;
            }

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

        boolean shouldIgnoreSensorRotation() {
            return mShouldIgnoreSensorRotation;
+16 −1
Original line number 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.assertTrue;
import static org.mockito.Mockito.clearInvocations;
import static org.mockito.Mockito.never;

import android.app.WindowConfiguration;
import android.content.ContentResolver;
@@ -1160,6 +1161,20 @@ public class DisplayRotationTests {
                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
    public void sensorRotation_locked_halfFolded_configOff_rotationUnchanged() throws Exception {
        mBuilder.setIsFoldable(true);
@@ -1182,7 +1197,7 @@ public class DisplayRotationTests {
        // ... half-fold -> still no rotation
        mTarget.foldStateChanged(DeviceStateController.DeviceStateEnum.HALF_FOLDED);
        assertTrue(waitForUiHandler());
        verify(sMockWm).updateRotation(false, false);
        verify(sMockWm, never()).updateRotation(false, false);
        assertTrue(waitForUiHandler());
        assertEquals(Surface.ROTATION_270, mTarget.rotationForOrientation(
                SCREEN_ORIENTATION_UNSPECIFIED, Surface.ROTATION_0));