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

Commit c0ebca48 authored by Mina Granic's avatar Mina Granic
Browse files

Disable fullscreen override while camera is active.

Bug: 340818342
Test: atest WmTests:LetterboxUiControllerTest
Change-Id: Id35cacee8d1306043cc96d4fa90f2eaf3377fa0c
parent 2e63bd90
Loading
Loading
Loading
Loading
+16 −14
Original line number Diff line number Diff line
@@ -556,7 +556,13 @@ final class LetterboxUiController {
        final DisplayContent displayContent = mActivityRecord.mDisplayContent;
        final boolean isIgnoreOrientationRequestEnabled = displayContent != null
                && displayContent.getIgnoreOrientationRequest();
        if (shouldApplyUserFullscreenOverride() && isIgnoreOrientationRequestEnabled) {
        if (shouldApplyUserFullscreenOverride() && isIgnoreOrientationRequestEnabled
                // Do not override orientation to fullscreen for camera activities.
                // Fixed-orientation activities are rarely tested in other orientations, and it
                // often results in sideways or stretched previews. As the camera compat treatment
                // targets fixed-orientation activities, overriding the orientation disables the
                // treatment.
                && !mActivityRecord.isCameraActive()) {
            Slog.v(TAG, "Requested orientation " + screenOrientationToString(candidate) + " for "
                    + mActivityRecord + " is overridden to "
                    + screenOrientationToString(SCREEN_ORIENTATION_USER)
@@ -591,7 +597,13 @@ final class LetterboxUiController {
        // mUserAspectRatio is always initialized first in shouldApplyUserFullscreenOverride(),
        // which will always come first before this check as user override > device
        // manufacturer override.
        if (isSystemOverrideToFullscreenEnabled() && isIgnoreOrientationRequestEnabled) {
        if (isSystemOverrideToFullscreenEnabled() && isIgnoreOrientationRequestEnabled
                // Do not override orientation to fullscreen for camera activities.
                // Fixed-orientation activities are rarely tested in other orientations, and it
                // often results in sideways or stretched previews. As the camera compat treatment
                // targets fixed-orientation activities, overriding the orientation disables the
                // treatment.
                && !mActivityRecord.isCameraActive()) {
            Slog.v(TAG, "Requested orientation  " + screenOrientationToString(candidate) + " for "
                    + mActivityRecord + " is overridden to "
                    + screenOrientationToString(SCREEN_ORIENTATION_USER));
@@ -1096,17 +1108,6 @@ final class LetterboxUiController {
    }

    boolean shouldApplyUserFullscreenOverride() {
        // Do not override orientation to fullscreen for camera activities.
        // Fixed-orientation activities are rarely tested in other orientations, and it often
        // results in sideways or stretched previews. As the camera compat treatment targets
        // fixed-orientation activities, overriding the orientation disables the treatment.
        final DisplayContent displayContent = mActivityRecord.mDisplayContent;
        if (displayContent != null && displayContent.mDisplayRotationCompatPolicy != null
                && displayContent.mDisplayRotationCompatPolicy
                .isCameraActive(mActivityRecord, /* mustBeFullscreen= */ true)) {
            return false;
        }

        if (isUserFullscreenOverrideEnabled()) {
            mUserAspectRatio = getUserMinAspectRatioOverrideCode();

@@ -1124,7 +1125,8 @@ final class LetterboxUiController {
    }

    boolean hasFullscreenOverride() {
        return isSystemOverrideToFullscreenEnabled() || shouldApplyUserFullscreenOverride();
        // `mUserAspectRatio` is always initialized first in `shouldApplyUserFullscreenOverride()`.
        return shouldApplyUserFullscreenOverride() || isSystemOverrideToFullscreenEnabled();
    }

    float getUserMinAspectRatio() {
+26 −4
Original line number Diff line number Diff line
@@ -909,7 +909,7 @@ public class LetterboxUiControllerTest extends WindowTestsBase {
    }

    @Test
    public void testOverrideOrientationIfNeeded_fullscreenOverride_cameraActivity_unchanged() {
    public void testOverrideOrientationIfNeeded_userFullscreenOverride_cameraActivity_noChange() {
        doReturn(true).when(mLetterboxConfiguration).isCameraCompatTreatmentEnabled();
        doReturn(true).when(mLetterboxConfiguration)
                .isCameraCompatTreatmentEnabledAtBuildTime();
@@ -917,9 +917,31 @@ public class LetterboxUiControllerTest extends WindowTestsBase {
        // Recreate DisplayContent with DisplayRotationCompatPolicy
        mActivity = setUpActivityWithComponent();
        mController = new LetterboxUiController(mWm, mActivity);
        spyOn(mController);
        doReturn(true).when(mController).shouldApplyUserFullscreenOverride();

        spyOn(mDisplayContent.mDisplayRotationCompatPolicy);
        doReturn(true).when(mDisplayContent.mDisplayRotationCompatPolicy)
                .isCameraActive(mActivity, /* mustBeFullscreen= */ true);

        doReturn(false).when(mDisplayContent.mDisplayRotationCompatPolicy)
        assertEquals(SCREEN_ORIENTATION_PORTRAIT, mController.overrideOrientationIfNeeded(
                /* candidate */ SCREEN_ORIENTATION_PORTRAIT));
    }

    @Test
    public void testOverrideOrientationIfNeeded_systemFullscreenOverride_cameraActivity_noChange() {
        doReturn(true).when(mLetterboxConfiguration).isCameraCompatTreatmentEnabled();
        doReturn(true).when(mLetterboxConfiguration)
                .isCameraCompatTreatmentEnabledAtBuildTime();

        // Recreate DisplayContent with DisplayRotationCompatPolicy
        mActivity = setUpActivityWithComponent();
        mController = new LetterboxUiController(mWm, mActivity);
        spyOn(mController);
        doReturn(true).when(mController).isSystemOverrideToFullscreenEnabled();

        spyOn(mDisplayContent.mDisplayRotationCompatPolicy);
        doReturn(true).when(mDisplayContent.mDisplayRotationCompatPolicy)
                .isCameraActive(mActivity, /* mustBeFullscreen= */ true);

        assertEquals(SCREEN_ORIENTATION_PORTRAIT, mController.overrideOrientationIfNeeded(
@@ -1057,7 +1079,7 @@ public class LetterboxUiControllerTest extends WindowTestsBase {
    }

    @Test
    public void testShouldEnableUserAspectRatioSettings_noIgnoreOrientaion_returnsFalse()
    public void testShouldEnableUserAspectRatioSettings_noIgnoreOrientation_returnsFalse()
            throws Exception {
        prepareActivityForShouldApplyUserMinAspectRatioOverride(/* orientationRequest */ false);
        mockThatProperty(PROPERTY_COMPAT_ALLOW_USER_ASPECT_RATIO_OVERRIDE, /* value */ true);
@@ -1105,7 +1127,7 @@ public class LetterboxUiControllerTest extends WindowTestsBase {
    }

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

        assertFalse(mController.shouldApplyUserMinAspectRatioOverride());