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

Commit b6c7f91c authored by Massimo Carli's avatar Massimo Carli Committed by Android (Google) Code Review
Browse files

Merge "Hide resize button when device is folded" into udc-qpr-dev

parents d30aeb2f e470213a
Loading
Loading
Loading
Loading
+18 −4
Original line number Diff line number Diff line
@@ -1126,11 +1126,25 @@ final class LetterboxUiController {
        return computeAspectRatio(bounds);
    }

    /**
     * Whether we should enable users to resize the current app.
     */
    boolean shouldEnableUserAspectRatioSettings() {
        // We use mBooleanPropertyAllowUserAspectRatioOverride to allow apps to opt-out which has
        // effect only if explicitly false. If mBooleanPropertyAllowUserAspectRatioOverride is null,
        // the current app doesn't opt-out so the first part of the predicate is true.
        return !FALSE.equals(mBooleanPropertyAllowUserAspectRatioOverride)
                && mLetterboxConfiguration.isUserAppAspectRatioSettingsEnabled()
                && mActivityRecord.mDisplayContent != null
                && mActivityRecord.mDisplayContent.getIgnoreOrientationRequest();
    }

    /**
     * Whether we should apply the user aspect ratio override to the min aspect ratio for the
     * current app.
     */
    boolean shouldApplyUserMinAspectRatioOverride() {
        if (FALSE.equals(mBooleanPropertyAllowUserAspectRatioOverride)
                || !mLetterboxConfiguration.isUserAppAspectRatioSettingsEnabled()
                || mActivityRecord.mDisplayContent == null
                || !mActivityRecord.mDisplayContent.getIgnoreOrientationRequest()) {
        if (!shouldEnableUserAspectRatioSettings()) {
            return false;
        }

+3 −3
Original line number Diff line number Diff line
@@ -3476,9 +3476,9 @@ class Task extends TaskFragment {
            }
        }
        // User Aspect Ratio Settings is enabled if the app is not in SCM
        info.topActivityEligibleForUserAspectRatioButton =
                mWmService.mLetterboxConfiguration.isUserAppAspectRatioSettingsEnabled()
                        && top != null && !info.topActivityInSizeCompat;
        info.topActivityEligibleForUserAspectRatioButton = top != null
                && !info.topActivityInSizeCompat
                && top.mLetterboxUiController.shouldEnableUserAspectRatioSettings();
        info.topActivityBoundsLetterboxed = top != null && top.areBoundsLetterboxed();
    }

+48 −2
Original line number Diff line number Diff line
@@ -861,6 +861,39 @@ public class LetterboxUiControllerTest extends WindowTestsBase {
        assertTrue(mController.shouldApplyUserFullscreenOverride());
    }

    @Test
    public void testShouldEnableUserAspectRatioSettings_falseProperty_returnsFalse()
            throws Exception {
        prepareActivityThatShouldApplyUserMinAspectRatioOverride();
        mockThatProperty(PROPERTY_COMPAT_ALLOW_USER_ASPECT_RATIO_OVERRIDE, /* value */ false);

        mController = new LetterboxUiController(mWm, mActivity);

        assertFalse(mController.shouldEnableUserAspectRatioSettings());
    }

    @Test
    public void testShouldEnableUserAspectRatioSettings_trueProperty_returnsTrue()
            throws Exception {
        prepareActivityThatShouldApplyUserMinAspectRatioOverride();
        mockThatProperty(PROPERTY_COMPAT_ALLOW_USER_ASPECT_RATIO_OVERRIDE, /* value */ true);

        mController = new LetterboxUiController(mWm, mActivity);

        assertTrue(mController.shouldEnableUserAspectRatioSettings());
    }

    @Test
    public void testShouldEnableUserAspectRatioSettings_noIgnoreOrientaion_returnsFalse()
            throws Exception {
        prepareActivityForShouldApplyUserMinAspectRatioOverride(/* orientationRequest */ false);
        mockThatProperty(PROPERTY_COMPAT_ALLOW_USER_ASPECT_RATIO_OVERRIDE, /* value */ true);

        mController = new LetterboxUiController(mWm, mActivity);

        assertFalse(mController.shouldEnableUserAspectRatioSettings());
    }

    @Test
    public void testShouldApplyUserMinAspectRatioOverride_falseProperty_returnsFalse()
            throws Exception {
@@ -898,13 +931,26 @@ public class LetterboxUiControllerTest extends WindowTestsBase {
        assertTrue(mController.shouldApplyUserMinAspectRatioOverride());
    }

    private void prepareActivityThatShouldApplyUserMinAspectRatioOverride() {
    @Test
    public void testShouldApplyUserMinAspectRatioOverride_noIgnoreOrientationreturnsFalse() {
        prepareActivityForShouldApplyUserMinAspectRatioOverride(/* orientationRequest */ false);

        assertFalse(mController.shouldApplyUserMinAspectRatioOverride());
    }

    private void prepareActivityForShouldApplyUserMinAspectRatioOverride(
            boolean orientationRequest) {
        spyOn(mController);
        doReturn(true).when(mLetterboxConfiguration).isUserAppAspectRatioSettingsEnabled();
        doReturn(orientationRequest).when(
                mLetterboxConfiguration).isUserAppAspectRatioSettingsEnabled();
        mDisplayContent.setIgnoreOrientationRequest(true);
        doReturn(USER_MIN_ASPECT_RATIO_3_2).when(mController).getUserMinAspectRatioOverrideCode();
    }

    private void prepareActivityThatShouldApplyUserMinAspectRatioOverride() {
        prepareActivityForShouldApplyUserMinAspectRatioOverride(/* orientationRequest */ true);
    }

    private void prepareActivityThatShouldApplyUserFullscreenOverride() {
        spyOn(mController);
        doReturn(true).when(mLetterboxConfiguration).isUserAppAspectRatioFullscreenEnabled();
+15 −13
Original line number Diff line number Diff line
@@ -571,26 +571,28 @@ public class TaskTests extends WindowTestsBase {
        final Task task = rootTask.getBottomMostTask();
        final ActivityRecord root = task.getTopNonFinishingActivity();
        spyOn(mWm.mLetterboxConfiguration);

        // When device config flag is disabled the button is not enabled
        doReturn(false).when(mWm.mLetterboxConfiguration)
                .isUserAppAspectRatioSettingsEnabled();
        doReturn(false).when(mWm.mLetterboxConfiguration)
                .isTranslucentLetterboxingEnabled();
        assertFalse(task.getTaskInfo().topActivityEligibleForUserAspectRatioButton);

        // The flag is enabled
        doReturn(true).when(mWm.mLetterboxConfiguration)
                .isUserAppAspectRatioSettingsEnabled();
        spyOn(root);
        doReturn(task).when(root).getOrganizedTask();
        // When the flag is enabled and the top activity is not in size compat mode.
        spyOn(root.mLetterboxUiController);

        doReturn(true).when(root.mLetterboxUiController)
                .shouldEnableUserAspectRatioSettings();
        doReturn(false).when(root).inSizeCompatMode();
        doReturn(task).when(root).getOrganizedTask();

        // The button should be eligible to be displayed
        assertTrue(task.getTaskInfo().topActivityEligibleForUserAspectRatioButton);

        // When shouldApplyUserMinAspectRatioOverride is disable the button is not enabled
        doReturn(false).when(root.mLetterboxUiController)
                .shouldEnableUserAspectRatioSettings();
        assertFalse(task.getTaskInfo().topActivityEligibleForUserAspectRatioButton);
        doReturn(true).when(root.mLetterboxUiController)
                .shouldEnableUserAspectRatioSettings();

        // When in size compat mode the button is not enabled
        doReturn(true).when(root).inSizeCompatMode();
        assertFalse(task.getTaskInfo().topActivityEligibleForUserAspectRatioButton);
        doReturn(false).when(root).inSizeCompatMode();
    }

    /**