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

Commit bd93cad1 authored by Kshitish Vyas's avatar Kshitish Vyas Committed by Android (Google) Code Review
Browse files

Merge "Disable fullscreen override while camera is active." into 24D1-dev

parents 65461abc 8792703e
Loading
Loading
Loading
Loading
+16 −14
Original line number Diff line number Diff line
@@ -610,7 +610,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)
@@ -645,7 +651,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));
@@ -1131,17 +1143,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();

@@ -1159,7 +1160,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
@@ -867,7 +867,7 @@ public class LetterboxUiControllerTest extends WindowTestsBase {
                /* candidate */ SCREEN_ORIENTATION_UNSPECIFIED));
    }
    @Test
    public void testOverrideOrientationIfNeeded_fullscreenOverride_cameraActivity_unchanged() {
    public void testOverrideOrientationIfNeeded_userFullscreenOverride_cameraActivity_noChange() {
        doReturn(true).when(mLetterboxConfiguration).isCameraCompatTreatmentEnabled();
        doReturn(true).when(mLetterboxConfiguration)
                .isCameraCompatTreatmentEnabledAtBuildTime();
@@ -875,9 +875,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(
@@ -1015,7 +1037,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);
@@ -1063,7 +1085,7 @@ public class LetterboxUiControllerTest extends WindowTestsBase {
    }

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

        assertFalse(mController.shouldApplyUserMinAspectRatioOverride());