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

Commit 8b125e37 authored by Graciela Wissen Putri's avatar Graciela Wissen Putri
Browse files

Ignore aspect ratio if override to fullscreen

We should not apply aspect ratio if app has been overridden to
fullscreen by either device user or manufacturer.

Bug: 330887629
Test: atest SizeCompatTests
Change-Id: I64ec750d8807e8aab43c6524a1755d371afc5d7d
parent 0d383316
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -8519,7 +8519,9 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
            }
        // If activity in fullscreen mode is letterboxed because of fixed orientation then bounds
        // are already calculated in resolveFixedOrientationConfiguration.
        } else if (!isLetterboxedForFixedOrientationAndAspectRatio()) {
        // Don't apply aspect ratio if app is overridden to fullscreen by device user/manufacturer.
        } else if (!isLetterboxedForFixedOrientationAndAspectRatio()
                && !mLetterboxUiController.hasFullscreenOverride()) {
            resolveAspectRatioRestriction(newParentConfiguration);
        }

+4 −0
Original line number Diff line number Diff line
@@ -1216,6 +1216,10 @@ final class LetterboxUiController {
                    || mUserAspectRatio == USER_MIN_ASPECT_RATIO_FULLSCREEN);
    }

    boolean hasFullscreenOverride() {
        return isSystemOverrideToFullscreenEnabled() || shouldApplyUserFullscreenOverride();
    }

    float getUserMinAspectRatio() {
        switch (mUserAspectRatio) {
            case USER_MIN_ASPECT_RATIO_DISPLAY_SIZE:
+86 −0
Original line number Diff line number Diff line
@@ -2325,6 +2325,92 @@ public class SizeCompatTests extends WindowTestsBase {
        assertFitted();
    }

    @Test
    public void testUserOverrideFullscreenForLandscapeDisplay() {
        final int displayWidth = 1600;
        final int displayHeight = 1400;
        setUpDisplaySizeWithApp(displayWidth, displayHeight);
        mActivity.mDisplayContent.setIgnoreOrientationRequest(true /* ignoreOrientationRequest */);
        spyOn(mActivity.mWmService.mLetterboxConfiguration);
        doReturn(true).when(mActivity.mWmService.mLetterboxConfiguration)
                .isUserAppAspectRatioFullscreenEnabled();

        // Set user aspect ratio override
        spyOn(mActivity.mLetterboxUiController);
        doReturn(USER_MIN_ASPECT_RATIO_FULLSCREEN).when(mActivity.mLetterboxUiController)
                .getUserMinAspectRatioOverrideCode();

        prepareMinAspectRatio(mActivity, 16 / 9f, SCREEN_ORIENTATION_PORTRAIT);

        final Rect bounds = mActivity.getBounds();

        // bounds should be fullscreen
        assertEquals(displayHeight, bounds.height());
        assertEquals(displayWidth, bounds.width());
    }

    @Test
    public void testUserOverrideFullscreenForPortraitDisplay() {
        final int displayWidth = 1400;
        final int displayHeight = 1600;
        setUpDisplaySizeWithApp(displayWidth, displayHeight);
        mActivity.mDisplayContent.setIgnoreOrientationRequest(true /* ignoreOrientationRequest */);
        spyOn(mActivity.mWmService.mLetterboxConfiguration);
        doReturn(true).when(mActivity.mWmService.mLetterboxConfiguration)
                .isUserAppAspectRatioFullscreenEnabled();

        // Set user aspect ratio override
        spyOn(mActivity.mLetterboxUiController);
        doReturn(USER_MIN_ASPECT_RATIO_FULLSCREEN).when(mActivity.mLetterboxUiController)
                .getUserMinAspectRatioOverrideCode();

        prepareMinAspectRatio(mActivity, 16 / 9f, SCREEN_ORIENTATION_LANDSCAPE);

        final Rect bounds = mActivity.getBounds();

        // bounds should be fullscreen
        assertEquals(displayHeight, bounds.height());
        assertEquals(displayWidth, bounds.width());
    }

    @Test
    public void testSystemFullscreenOverrideForLandscapeDisplay() {
        final int displayWidth = 1600;
        final int displayHeight = 1400;
        setUpDisplaySizeWithApp(displayWidth, displayHeight);
        mActivity.mDisplayContent.setIgnoreOrientationRequest(true /* ignoreOrientationRequest */);
        spyOn(mActivity.mLetterboxUiController);
        doReturn(true).when(mActivity.mLetterboxUiController)
                .isSystemOverrideToFullscreenEnabled();

        prepareMinAspectRatio(mActivity, 16 / 9f, SCREEN_ORIENTATION_PORTRAIT);

        final Rect bounds = mActivity.getBounds();

        // bounds should be fullscreen
        assertEquals(displayHeight, bounds.height());
        assertEquals(displayWidth, bounds.width());
    }

    @Test
    public void testSystemFullscreenOverrideForPortraitDisplay() {
        final int displayWidth = 1400;
        final int displayHeight = 1600;
        setUpDisplaySizeWithApp(displayWidth, displayHeight);
        mActivity.mDisplayContent.setIgnoreOrientationRequest(true /* ignoreOrientationRequest */);
        spyOn(mActivity.mLetterboxUiController);
        doReturn(true).when(mActivity.mLetterboxUiController)
                .isSystemOverrideToFullscreenEnabled();

        prepareMinAspectRatio(mActivity, 16 / 9f, SCREEN_ORIENTATION_LANDSCAPE);

        final Rect bounds = mActivity.getBounds();

        // bounds should be fullscreen
        assertEquals(displayHeight, bounds.height());
        assertEquals(displayWidth, bounds.width());
    }

    @Test
    public void testUserOverrideSplitScreenAspectRatioForLandscapeDisplay() {
        final int displayWidth = 1600;