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

Commit 0234b39b authored by Massimo Carli's avatar Massimo Carli Committed by Automerger Merge Worker
Browse files

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

parents abf4e614 b6c7f91c
Loading
Loading
Loading
Loading
+18 −4
Original line number Original line Diff line number Diff line
@@ -1126,11 +1126,25 @@ final class LetterboxUiController {
        return computeAspectRatio(bounds);
        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() {
    boolean shouldApplyUserMinAspectRatioOverride() {
        if (FALSE.equals(mBooleanPropertyAllowUserAspectRatioOverride)
        if (!shouldEnableUserAspectRatioSettings()) {
                || !mLetterboxConfiguration.isUserAppAspectRatioSettingsEnabled()
                || mActivityRecord.mDisplayContent == null
                || !mActivityRecord.mDisplayContent.getIgnoreOrientationRequest()) {
            return false;
            return false;
        }
        }


+3 −3
Original line number Original line 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
        // User Aspect Ratio Settings is enabled if the app is not in SCM
        info.topActivityEligibleForUserAspectRatioButton =
        info.topActivityEligibleForUserAspectRatioButton = top != null
                mWmService.mLetterboxConfiguration.isUserAppAspectRatioSettingsEnabled()
                && !info.topActivityInSizeCompat
                        && top != null && !info.topActivityInSizeCompat;
                && top.mLetterboxUiController.shouldEnableUserAspectRatioSettings();
        info.topActivityBoundsLetterboxed = top != null && top.areBoundsLetterboxed();
        info.topActivityBoundsLetterboxed = top != null && top.areBoundsLetterboxed();
    }
    }


+48 −2
Original line number Original line Diff line number Diff line
@@ -861,6 +861,39 @@ public class LetterboxUiControllerTest extends WindowTestsBase {
        assertTrue(mController.shouldApplyUserFullscreenOverride());
        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
    @Test
    public void testShouldApplyUserMinAspectRatioOverride_falseProperty_returnsFalse()
    public void testShouldApplyUserMinAspectRatioOverride_falseProperty_returnsFalse()
            throws Exception {
            throws Exception {
@@ -898,13 +931,26 @@ public class LetterboxUiControllerTest extends WindowTestsBase {
        assertTrue(mController.shouldApplyUserMinAspectRatioOverride());
        assertTrue(mController.shouldApplyUserMinAspectRatioOverride());
    }
    }


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

        assertFalse(mController.shouldApplyUserMinAspectRatioOverride());
    }

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


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

    private void prepareActivityThatShouldApplyUserFullscreenOverride() {
    private void prepareActivityThatShouldApplyUserFullscreenOverride() {
        spyOn(mController);
        spyOn(mController);
        doReturn(true).when(mLetterboxConfiguration).isUserAppAspectRatioFullscreenEnabled();
        doReturn(true).when(mLetterboxConfiguration).isUserAppAspectRatioFullscreenEnabled();
+15 −13
Original line number Original line Diff line number Diff line
@@ -571,26 +571,28 @@ public class TaskTests extends WindowTestsBase {
        final Task task = rootTask.getBottomMostTask();
        final Task task = rootTask.getBottomMostTask();
        final ActivityRecord root = task.getTopNonFinishingActivity();
        final ActivityRecord root = task.getTopNonFinishingActivity();
        spyOn(mWm.mLetterboxConfiguration);
        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);
        spyOn(root);
        doReturn(task).when(root).getOrganizedTask();
        spyOn(root.mLetterboxUiController);
        // When the flag is enabled and the top activity is not in size compat mode.

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

        // The button should be eligible to be displayed
        assertTrue(task.getTaskInfo().topActivityEligibleForUserAspectRatioButton);
        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
        // When in size compat mode the button is not enabled
        doReturn(true).when(root).inSizeCompatMode();
        doReturn(true).when(root).inSizeCompatMode();
        assertFalse(task.getTaskInfo().topActivityEligibleForUserAspectRatioButton);
        assertFalse(task.getTaskInfo().topActivityEligibleForUserAspectRatioButton);
        doReturn(false).when(root).inSizeCompatMode();
    }
    }


    /**
    /**