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

Commit 55c6443b authored by Eghosa Ewansiha-Vlachavas's avatar Eghosa Ewansiha-Vlachavas
Browse files

Fully disable SCM when users pick fullscreen in settings

Prevent an app from entering SCM on fold/unfold transitions or in
multi-window mode.

Fix: 308739958
Test: atest WmTests:SizeCompatTests#testShouldCreateCompatDisplayUserAspectRatioFullscreenOverride
atest WmTests:LetterboxUiControllerTest

Change-Id: If69b85bf1f0f2a4853a3cdc34c18562ab519d172
parent 22daeee1
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -8185,6 +8185,12 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
     *         aspect ratio.
     */
    boolean shouldCreateCompatDisplayInsets() {
        if (mLetterboxUiController.shouldApplyUserFullscreenOverride()) {
            // If the user has forced the applications aspect ratio to be fullscreen, don't use size
            // compatibility mode in any situation. The user has been warned and therefore accepts
            // the risk of the application misbehaving.
            return false;
        }
        switch (supportsSizeChanges()) {
            case SIZE_CHANGES_SUPPORTED_METADATA:
            case SIZE_CHANGES_SUPPORTED_OVERRIDE:
+7 −5
Original line number Diff line number Diff line
@@ -254,7 +254,9 @@ final class LetterboxUiController {
    // Counter for ActivityRecord#setRequestedOrientation
    private int mSetOrientationRequestCounter = 0;

    // The min aspect ratio override set by user
    // The min aspect ratio override set by user. Stores the last selected aspect ratio after
    // {@link #shouldApplyUserFullscreenOverride} or {@link #shouldApplyUserMinAspectRatioOverride}
    // have been invoked.
    @PackageManager.UserMinAspectRatio
    private int mUserAspectRatio = USER_MIN_ASPECT_RATIO_UNSET;

@@ -661,7 +663,9 @@ final class LetterboxUiController {

    @ScreenOrientation
    int overrideOrientationIfNeeded(@ScreenOrientation int candidate) {
        if (shouldApplyUserFullscreenOverride()) {
        if (shouldApplyUserFullscreenOverride()
                && mActivityRecord.mDisplayContent != null
                && mActivityRecord.mDisplayContent.getIgnoreOrientationRequest()) {
            Slog.v(TAG, "Requested orientation " + screenOrientationToString(candidate) + " for "
                    + mActivityRecord + " is overridden to "
                    + screenOrientationToString(SCREEN_ORIENTATION_USER)
@@ -1171,9 +1175,7 @@ final class LetterboxUiController {
    boolean shouldApplyUserFullscreenOverride() {
        if (FALSE.equals(mBooleanPropertyAllowUserAspectRatioOverride)
                || FALSE.equals(mBooleanPropertyAllowUserAspectRatioFullscreenOverride)
                || !mLetterboxConfiguration.isUserAppAspectRatioFullscreenEnabled()
                || mActivityRecord.mDisplayContent == null
                || !mActivityRecord.mDisplayContent.getIgnoreOrientationRequest()) {
                || !mLetterboxConfiguration.isUserAppAspectRatioFullscreenEnabled()) {
            return false;
        }

+22 −8
Original line number Diff line number Diff line
@@ -787,21 +787,43 @@ public class LetterboxUiControllerTest extends WindowTestsBase {
    public void testOverrideOrientationIfNeeded_userFullscreenOverride_returnsUser() {
        spyOn(mController);
        doReturn(true).when(mController).shouldApplyUserFullscreenOverride();
        mDisplayContent.setIgnoreOrientationRequest(true);

        assertEquals(SCREEN_ORIENTATION_USER, mController.overrideOrientationIfNeeded(
                /* candidate */ SCREEN_ORIENTATION_UNSPECIFIED));
    }
    @Test
    public void testOverrideOrientationIfNeeded_respectOrientationRequestOverUserFullScreen() {
        spyOn(mController);
        doReturn(true).when(mController).shouldApplyUserFullscreenOverride();
        mDisplayContent.setIgnoreOrientationRequest(false);

        assertNotEquals(SCREEN_ORIENTATION_USER, mController.overrideOrientationIfNeeded(
                /* candidate */ SCREEN_ORIENTATION_UNSPECIFIED));
    }

    @Test
    @EnableCompatChanges({OVERRIDE_UNDEFINED_ORIENTATION_TO_PORTRAIT, OVERRIDE_ANY_ORIENTATION})
    public void testOverrideOrientationIfNeeded_userFullScreenOverrideOverSystem_returnsUser() {
        spyOn(mController);
        doReturn(true).when(mController).shouldApplyUserFullscreenOverride();
        mDisplayContent.setIgnoreOrientationRequest(true);

        assertEquals(SCREEN_ORIENTATION_USER, mController.overrideOrientationIfNeeded(
                /* candidate */ SCREEN_ORIENTATION_PORTRAIT));
    }

    @Test
    @EnableCompatChanges({OVERRIDE_UNDEFINED_ORIENTATION_TO_PORTRAIT, OVERRIDE_ANY_ORIENTATION})
    public void testOverrideOrientationIfNeeded_respectOrientationReqOverUserFullScreenAndSystem() {
        spyOn(mController);
        doReturn(true).when(mController).shouldApplyUserFullscreenOverride();
        mDisplayContent.setIgnoreOrientationRequest(false);

        assertNotEquals(SCREEN_ORIENTATION_USER, mController.overrideOrientationIfNeeded(
                /* candidate */ SCREEN_ORIENTATION_PORTRAIT));
    }

    @Test
    public void testOverrideOrientationIfNeeded_userFullScreenOverrideDisabled_returnsUnchanged() {
        spyOn(mController);
@@ -871,14 +893,6 @@ public class LetterboxUiControllerTest extends WindowTestsBase {
        assertFalse(mController.shouldApplyUserFullscreenOverride());
    }

    @Test
    public void testShouldApplyUserFullscreenOverride_disabledIgnoreOrientationRequest() {
        prepareActivityThatShouldApplyUserFullscreenOverride();
        mDisplayContent.setIgnoreOrientationRequest(false);

        assertFalse(mController.shouldApplyUserFullscreenOverride());
    }

    @Test
    public void testShouldApplyUserFullscreenOverride_returnsTrue() {
        prepareActivityThatShouldApplyUserFullscreenOverride();
+22 −0
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import static android.content.pm.PackageManager.USER_MIN_ASPECT_RATIO_16_9;
import static android.content.pm.PackageManager.USER_MIN_ASPECT_RATIO_3_2;
import static android.content.pm.PackageManager.USER_MIN_ASPECT_RATIO_4_3;
import static android.content.pm.PackageManager.USER_MIN_ASPECT_RATIO_DISPLAY_SIZE;
import static android.content.pm.PackageManager.USER_MIN_ASPECT_RATIO_FULLSCREEN;
import static android.content.pm.PackageManager.USER_MIN_ASPECT_RATIO_SPLIT_SCREEN;
import static android.content.res.Configuration.ORIENTATION_LANDSCAPE;
import static android.content.res.Configuration.ORIENTATION_PORTRAIT;
@@ -1300,6 +1301,27 @@ public class SizeCompatTests extends WindowTestsBase {
        assertTrue(activity.shouldCreateCompatDisplayInsets());
    }

    @Test
    public void testShouldCreateCompatDisplayUserAspectRatioFullscreenOverride() {
        setUpDisplaySizeWithApp(1000, 2500);

        // Make the task root resizable.
        mActivity.info.resizeMode = RESIZE_MODE_RESIZEABLE;

        // Create an activity on the same task.
        final ActivityRecord activity = buildActivityRecord(/* supportsSizeChanges= */false,
                RESIZE_MODE_UNRESIZEABLE, ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

        // Simulate the user selecting the fullscreen user aspect ratio override
        spyOn(activity.mWmService.mLetterboxConfiguration);
        spyOn(activity.mLetterboxUiController);
        doReturn(true).when(activity.mWmService.mLetterboxConfiguration)
                .isUserAppAspectRatioFullscreenEnabled();
        doReturn(USER_MIN_ASPECT_RATIO_FULLSCREEN).when(activity.mLetterboxUiController)
                .getUserMinAspectRatioOverrideCode();
        assertFalse(activity.shouldCreateCompatDisplayInsets());
    }

    @Test
    @EnableCompatChanges({ActivityInfo.NEVER_SANDBOX_DISPLAY_APIS})
    public void testNeverSandboxDisplayApis_configEnabled_sandboxingNotApplied() {