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

Commit 3b819523 authored by Mariia Sandrikova's avatar Mariia Sandrikova Committed by Automerger Merge Worker
Browse files

Merge "Added OnSetRequestedOrientation callback" into tm-qpr-dev am: d9f955a5

parents cc6f05f4 d9f955a5
Loading
Loading
Loading
Loading
+2 −0
Original line number Original line Diff line number Diff line
@@ -7869,6 +7869,8 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A


        mAtmService.getTaskChangeNotificationController().notifyActivityRequestedOrientationChanged(
        mAtmService.getTaskChangeNotificationController().notifyActivityRequestedOrientationChanged(
                task.mTaskId, requestedOrientation);
                task.mTaskId, requestedOrientation);

        mDisplayContent.getDisplayRotation().onSetRequestedOrientation();
    }
    }


    /*
    /*
+22 −0
Original line number Original line Diff line number Diff line
@@ -97,6 +97,8 @@ public class DisplayRotation {
    // config changes and unexpected jumps while folding the device to closed state.
    // config changes and unexpected jumps while folding the device to closed state.
    private static final int FOLDING_RECOMPUTE_CONFIG_DELAY_MS = 800;
    private static final int FOLDING_RECOMPUTE_CONFIG_DELAY_MS = 800;


    private static final int ROTATION_UNDEFINED = -1;

    private static class RotationAnimationPair {
    private static class RotationAnimationPair {
        @AnimRes
        @AnimRes
        int mEnter;
        int mEnter;
@@ -184,6 +186,12 @@ public class DisplayRotation {
     */
     */
    private int mShowRotationSuggestions;
    private int mShowRotationSuggestions;


    /**
     * The most recent {@link Surface.Rotation} choice shown to the user for confirmation, or
     * {@link #ROTATION_UNDEFINED}
     */
    private int mRotationChoiceShownToUserForConfirmation = ROTATION_UNDEFINED;

    private static final int ALLOW_ALL_ROTATIONS_UNDEFINED = -1;
    private static final int ALLOW_ALL_ROTATIONS_UNDEFINED = -1;
    private static final int ALLOW_ALL_ROTATIONS_DISABLED = 0;
    private static final int ALLOW_ALL_ROTATIONS_DISABLED = 0;
    private static final int ALLOW_ALL_ROTATIONS_ENABLED = 1;
    private static final int ALLOW_ALL_ROTATIONS_ENABLED = 1;
@@ -861,6 +869,7 @@ public class DisplayRotation {


    @VisibleForTesting
    @VisibleForTesting
    void setUserRotation(int userRotationMode, int userRotation) {
    void setUserRotation(int userRotationMode, int userRotation) {
        mRotationChoiceShownToUserForConfirmation = ROTATION_UNDEFINED;
        if (isDefaultDisplay) {
        if (isDefaultDisplay) {
            // We'll be notified via settings listener, so we don't need to update internal values.
            // We'll be notified via settings listener, so we don't need to update internal values.
            final ContentResolver res = mContext.getContentResolver();
            final ContentResolver res = mContext.getContentResolver();
@@ -1568,6 +1577,17 @@ public class DisplayRotation {
        return shouldUpdateRotation;
        return shouldUpdateRotation;
    }
    }


    /**
     * Called from {@link ActivityRecord#setRequestedOrientation(int)}
     */
    void onSetRequestedOrientation() {
        if (mCompatPolicyForImmersiveApps == null
                || mRotationChoiceShownToUserForConfirmation == ROTATION_UNDEFINED) {
            return;
        }
        mOrientationListener.onProposedRotationChanged(mRotationChoiceShownToUserForConfirmation);
    }

    void dump(String prefix, PrintWriter pw) {
    void dump(String prefix, PrintWriter pw) {
        pw.println(prefix + "DisplayRotation");
        pw.println(prefix + "DisplayRotation");
        pw.println(prefix + "  mCurrentAppOrientation="
        pw.println(prefix + "  mCurrentAppOrientation="
@@ -1966,9 +1986,11 @@ public class DisplayRotation {
            // Send interaction power boost to improve redraw performance.
            // Send interaction power boost to improve redraw performance.
            mService.mPowerManagerInternal.setPowerBoost(Boost.INTERACTION, 0);
            mService.mPowerManagerInternal.setPowerBoost(Boost.INTERACTION, 0);
            if (isRotationChoiceAllowed(rotation)) {
            if (isRotationChoiceAllowed(rotation)) {
                mRotationChoiceShownToUserForConfirmation = rotation;
                final boolean isValid = isValidRotationChoice(rotation);
                final boolean isValid = isValidRotationChoice(rotation);
                sendProposedRotationChangeToStatusBarInternal(rotation, isValid);
                sendProposedRotationChangeToStatusBarInternal(rotation, isValid);
            } else {
            } else {
                mRotationChoiceShownToUserForConfirmation = ROTATION_UNDEFINED;
                mService.updateRotation(false /* alwaysSendConfiguration */,
                mService.updateRotation(false /* alwaysSendConfiguration */,
                        false /* forceRelayout */);
                        false /* forceRelayout */);
            }
            }
+6 −0
Original line number Original line Diff line number Diff line
@@ -588,12 +588,18 @@ public class ActivityRecordTests extends WindowTestsBase {
                throw new IllegalStateException("Orientation in new config should be either"
                throw new IllegalStateException("Orientation in new config should be either"
                        + "landscape or portrait.");
                        + "landscape or portrait.");
        }
        }

        final DisplayRotation displayRotation = activity.mDisplayContent.getDisplayRotation();
        spyOn(displayRotation);

        activity.setRequestedOrientation(requestedOrientation);
        activity.setRequestedOrientation(requestedOrientation);


        final ActivityConfigurationChangeItem expected =
        final ActivityConfigurationChangeItem expected =
                ActivityConfigurationChangeItem.obtain(newConfig);
                ActivityConfigurationChangeItem.obtain(newConfig);
        verify(mAtm.getLifecycleManager()).scheduleTransaction(eq(activity.app.getThread()),
        verify(mAtm.getLifecycleManager()).scheduleTransaction(eq(activity.app.getThread()),
                eq(activity.token), eq(expected));
                eq(activity.token), eq(expected));

        verify(displayRotation).onSetRequestedOrientation();
    }
    }


    @Test
    @Test
+37 −2
Original line number Original line Diff line number Diff line
@@ -68,6 +68,7 @@ import android.view.DisplayAddress;
import android.view.Surface;
import android.view.Surface;
import android.view.WindowManager;
import android.view.WindowManager;


import androidx.annotation.Nullable;
import androidx.test.filters.SmallTest;
import androidx.test.filters.SmallTest;


import com.android.internal.util.test.FakeSettingsProvider;
import com.android.internal.util.test.FakeSettingsProvider;
@@ -137,6 +138,8 @@ public class DisplayRotationTests {


    private DeviceStateController mDeviceStateController;
    private DeviceStateController mDeviceStateController;
    private DisplayRotation mTarget;
    private DisplayRotation mTarget;
    @Nullable
    private DisplayRotationImmersiveAppCompatPolicy mDisplayRotationImmersiveAppCompatPolicyMock;


    @BeforeClass
    @BeforeClass
    public static void setUpOnce() {
    public static void setUpOnce() {
@@ -161,7 +164,7 @@ public class DisplayRotationTests {
        LocalServices.removeServiceForTest(StatusBarManagerInternal.class);
        LocalServices.removeServiceForTest(StatusBarManagerInternal.class);
        mMockStatusBarManagerInternal = mock(StatusBarManagerInternal.class);
        mMockStatusBarManagerInternal = mock(StatusBarManagerInternal.class);
        LocalServices.addService(StatusBarManagerInternal.class, mMockStatusBarManagerInternal);
        LocalServices.addService(StatusBarManagerInternal.class, mMockStatusBarManagerInternal);

        mDisplayRotationImmersiveAppCompatPolicyMock = null;
        mBuilder = new DisplayRotationBuilder();
        mBuilder = new DisplayRotationBuilder();
    }
    }


@@ -573,6 +576,38 @@ public class DisplayRotationTests {
        verify(mMockStatusBarManagerInternal).onProposedRotationChanged(Surface.ROTATION_90, true);
        verify(mMockStatusBarManagerInternal).onProposedRotationChanged(Surface.ROTATION_90, true);
    }
    }


    @Test
    public void testNotifiesChoiceWhenSensorUpdates_immersiveApp() throws Exception {
        mDisplayRotationImmersiveAppCompatPolicyMock = mock(
                DisplayRotationImmersiveAppCompatPolicy.class);
        when(mDisplayRotationImmersiveAppCompatPolicyMock.isRotationLockEnforced(
                Surface.ROTATION_90)).thenReturn(true);

        mBuilder.build();
        configureDisplayRotation(SCREEN_ORIENTATION_PORTRAIT, false, false);

        thawRotation();

        enableOrientationSensor();

        mOrientationSensorListener.onSensorChanged(createSensorEvent(Surface.ROTATION_90));
        assertTrue(waitForUiHandler());

        verify(mMockStatusBarManagerInternal).onProposedRotationChanged(Surface.ROTATION_90, true);

        // An imaginary ActivityRecord.setRequestedOrientation call disables immersive mode:
        when(mDisplayRotationImmersiveAppCompatPolicyMock.isRotationLockEnforced(
                Surface.ROTATION_90)).thenReturn(false);

        // And then ActivityRecord.setRequestedOrientation calls onSetRequestedOrientation.
        mTarget.onSetRequestedOrientation();

        // onSetRequestedOrientation should lead to a second call to
        // mOrientationListener.onProposedRotationChanged
        // but now, instead of notifying mMockStatusBarManagerInternal, it calls updateRotation:
        verify(sMockWm).updateRotation(false, false);
    }

    @Test
    @Test
    public void testAllowAllRotations_allowsUpsideDownSuggestion()
    public void testAllowAllRotations_allowsUpsideDownSuggestion()
            throws Exception {
            throws Exception {
@@ -1354,7 +1389,7 @@ public class DisplayRotationTests {
                @Override
                @Override
                DisplayRotationImmersiveAppCompatPolicy initImmersiveAppCompatPolicy(
                DisplayRotationImmersiveAppCompatPolicy initImmersiveAppCompatPolicy(
                        WindowManagerService service, DisplayContent displayContent) {
                        WindowManagerService service, DisplayContent displayContent) {
                    return null;
                    return mDisplayRotationImmersiveAppCompatPolicyMock;
                }
                }


                @Override
                @Override