From 996ce09ed8ef4652c9d1babd0575fb920bee3ba6 Mon Sep 17 00:00:00 2001 From: Mina Granic Date: Thu, 16 May 2024 11:59:23 +0000 Subject: Do not apply fullscreen override 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. Fixes: 340818342 Test: atest WmTests:LetterboxUiControllerTest Change-Id: I23cc542158e8fe53b1b210409dfb96c45ff7462f --- .../com/android/server/wm/LetterboxUiController.java | 11 +++++++++++ .../android/server/wm/LetterboxUiControllerTest.java | 18 ++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/services/core/java/com/android/server/wm/LetterboxUiController.java b/services/core/java/com/android/server/wm/LetterboxUiController.java index 18225285a4a8..691176a794ae 100644 --- a/services/core/java/com/android/server/wm/LetterboxUiController.java +++ b/services/core/java/com/android/server/wm/LetterboxUiController.java @@ -1131,6 +1131,17 @@ 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(); diff --git a/services/tests/wmtests/src/com/android/server/wm/LetterboxUiControllerTest.java b/services/tests/wmtests/src/com/android/server/wm/LetterboxUiControllerTest.java index f559de8838a6..80f2ada34197 100644 --- a/services/tests/wmtests/src/com/android/server/wm/LetterboxUiControllerTest.java +++ b/services/tests/wmtests/src/com/android/server/wm/LetterboxUiControllerTest.java @@ -866,6 +866,24 @@ public class LetterboxUiControllerTest extends WindowTestsBase { assertEquals(SCREEN_ORIENTATION_USER, mController.overrideOrientationIfNeeded( /* candidate */ SCREEN_ORIENTATION_UNSPECIFIED)); } + @Test + public void testOverrideOrientationIfNeeded_fullscreenOverride_cameraActivity_unchanged() { + doReturn(true).when(mLetterboxConfiguration).isCameraCompatTreatmentEnabled(); + doReturn(true).when(mLetterboxConfiguration) + .isCameraCompatTreatmentEnabledAtBuildTime(); + + // Recreate DisplayContent with DisplayRotationCompatPolicy + mActivity = setUpActivityWithComponent(); + mController = new LetterboxUiController(mWm, mActivity); + spyOn(mDisplayContent.mDisplayRotationCompatPolicy); + + doReturn(false).when(mDisplayContent.mDisplayRotationCompatPolicy) + .isCameraActive(mActivity, /* mustBeFullscreen= */ true); + + assertEquals(SCREEN_ORIENTATION_PORTRAIT, mController.overrideOrientationIfNeeded( + /* candidate */ SCREEN_ORIENTATION_PORTRAIT)); + } + @Test public void testOverrideOrientationIfNeeded_respectOrientationRequestOverUserFullScreen() { spyOn(mController); -- cgit v1.2.3-59-g8ed1b