diff options
| author | 2023-02-07 19:22:46 +0000 | |
|---|---|---|
| committer | 2023-02-08 15:19:25 +0000 | |
| commit | 3e7f0dc19cdad099ad53a904cc15f32109e431b5 (patch) | |
| tree | c856f3c3f9af23e600a1b5b5de650fa4729fe51b | |
| parent | 02cdf72ad3b162d9c42c52b0ad5ea2d35de594cb (diff) | |
[6/n] Camera Compat: Fix the toast gating condition.
Before this change, the toast was shown for all activities that have active camera connection. Now it is limited to activities with fixed orientation that are eligible for force rotation.
Test: atest WmTests:DisplayRotationCompatPolicyTests
Fix: 267763989
Change-Id: Ic5774f70f7c74d26d2242e4849e3383b8b62d489
| -rw-r--r-- | services/core/java/com/android/server/wm/DisplayRotationCompatPolicy.java | 27 | ||||
| -rw-r--r-- | services/tests/wmtests/src/com/android/server/wm/DisplayRotationCompatPolicyTests.java | 28 |
2 files changed, 44 insertions, 11 deletions
diff --git a/services/core/java/com/android/server/wm/DisplayRotationCompatPolicy.java b/services/core/java/com/android/server/wm/DisplayRotationCompatPolicy.java index e04900c94f15..47bdba34ee24 100644 --- a/services/core/java/com/android/server/wm/DisplayRotationCompatPolicy.java +++ b/services/core/java/com/android/server/wm/DisplayRotationCompatPolicy.java @@ -250,10 +250,7 @@ final class DisplayRotationCompatPolicy { } ActivityRecord topActivity = mDisplayContent.topRunningActivity( /* considerKeyguardState= */ true); - if (topActivity == null - // Checking windowing mode on activity level because we don't want to - // show toast in case of activity embedding. - || topActivity.getWindowingMode() != WINDOWING_MODE_FULLSCREEN) { + if (!isTreatmentEnabledForActivity(topActivity)) { return; } showToast(R.string.display_rotation_camera_compat_toast_after_rotation); @@ -309,21 +306,28 @@ final class DisplayRotationCompatPolicy { } boolean isActivityEligibleForOrientationOverride(@NonNull ActivityRecord activity) { - return isTreatmentEnabledForDisplay() && isCameraActiveInFullscreen(activity); + return isTreatmentEnabledForDisplay() + && isCameraActive(activity, /* mustBeFullscreen */ true); } + /** * Whether camera compat treatment is applicable for the given activity. * * <p>Conditions that need to be met: * <ul> - * <li>{@link #isCameraActiveForPackage} is {@code true} for the activity. + * <li>Camera is active for the package. * <li>The activity is in fullscreen * <li>The activity has fixed orientation but not "locked" or "nosensor" one. * </ul> */ boolean isTreatmentEnabledForActivity(@Nullable ActivityRecord activity) { - return activity != null && isCameraActiveInFullscreen(activity) + return isTreatmentEnabledForActivity(activity, /* mustBeFullscreen */ true); + } + + private boolean isTreatmentEnabledForActivity(@Nullable ActivityRecord activity, + boolean mustBeFullscreen) { + return activity != null && isCameraActive(activity, mustBeFullscreen) && activity.getRequestedConfigurationOrientation() != ORIENTATION_UNDEFINED // "locked" and "nosensor" values are often used by camera apps that can't // handle dynamic changes so we shouldn't force rotate them. @@ -331,8 +335,10 @@ final class DisplayRotationCompatPolicy { && activity.getOverrideOrientation() != SCREEN_ORIENTATION_LOCKED; } - private boolean isCameraActiveInFullscreen(@NonNull ActivityRecord activity) { - return !activity.inMultiWindowMode() + private boolean isCameraActive(@NonNull ActivityRecord activity, boolean mustBeFullscreen) { + // Checking windowing mode on activity level because we don't want to + // apply treatment in case of activity embedding. + return (!mustBeFullscreen || !activity.inMultiWindowMode()) && mCameraIdPackageBiMap.containsPackageName(activity.packageName) && activity.mLetterboxUiController.shouldForceRotateForCameraCompat(); } @@ -385,7 +391,8 @@ final class DisplayRotationCompatPolicy { } // Checking that the whole app is in multi-window mode as we shouldn't show toast // for the activity embedding case. - if (topActivity.getTask().getWindowingMode() == WINDOWING_MODE_MULTI_WINDOW) { + if (topActivity.getTask().getWindowingMode() == WINDOWING_MODE_MULTI_WINDOW + && isTreatmentEnabledForActivity(topActivity, /* mustBeFullscreen */ false)) { showToast(R.string.display_rotation_camera_compat_toast_in_split_screen); } } diff --git a/services/tests/wmtests/src/com/android/server/wm/DisplayRotationCompatPolicyTests.java b/services/tests/wmtests/src/com/android/server/wm/DisplayRotationCompatPolicyTests.java index 4954e89c1ffd..c2b3783b7311 100644 --- a/services/tests/wmtests/src/com/android/server/wm/DisplayRotationCompatPolicyTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/DisplayRotationCompatPolicyTests.java @@ -147,6 +147,20 @@ public final class DisplayRotationCompatPolicyTests extends WindowTestsBase { } @Test + public void testOpenedCameraInSplitScreen_orientationNotFixed_doNotShowToast() { + configureActivity(SCREEN_ORIENTATION_UNSPECIFIED); + spyOn(mTask); + spyOn(mDisplayRotationCompatPolicy); + doReturn(WINDOWING_MODE_MULTI_WINDOW).when(mActivity).getWindowingMode(); + doReturn(WINDOWING_MODE_MULTI_WINDOW).when(mTask).getWindowingMode(); + + mCameraAvailabilityCallback.onCameraOpened(CAMERA_ID_1, TEST_PACKAGE_1); + + verify(mDisplayRotationCompatPolicy, never()).showToast( + R.string.display_rotation_camera_compat_toast_in_split_screen); + } + + @Test public void testOnScreenRotationAnimationFinished_treatmentNotEnabled_doNotShowToast() { when(mLetterboxConfiguration.isCameraCompatTreatmentEnabled( /* checkDeviceConfig */ anyBoolean())) @@ -172,7 +186,7 @@ public final class DisplayRotationCompatPolicyTests extends WindowTestsBase { @Test public void testOnScreenRotationAnimationFinished_notFullscreen_doNotShowToast() { configureActivity(SCREEN_ORIENTATION_PORTRAIT); - doReturn(WINDOWING_MODE_MULTI_WINDOW).when(mActivity).getWindowingMode(); + doReturn(true).when(mActivity).inMultiWindowMode(); spyOn(mDisplayRotationCompatPolicy); mCameraAvailabilityCallback.onCameraOpened(CAMERA_ID_1, TEST_PACKAGE_1); @@ -184,6 +198,18 @@ public final class DisplayRotationCompatPolicyTests extends WindowTestsBase { } @Test + public void testOnScreenRotationAnimationFinished_orientationNotFixed_doNotShowToast() { + configureActivity(SCREEN_ORIENTATION_UNSPECIFIED); + mCameraAvailabilityCallback.onCameraOpened(CAMERA_ID_1, TEST_PACKAGE_1); + spyOn(mDisplayRotationCompatPolicy); + + mDisplayRotationCompatPolicy.onScreenRotationAnimationFinished(); + + verify(mDisplayRotationCompatPolicy, never()).showToast( + R.string.display_rotation_camera_compat_toast_after_rotation); + } + + @Test public void testOnScreenRotationAnimationFinished_showToast() { configureActivity(SCREEN_ORIENTATION_PORTRAIT); mCameraAvailabilityCallback.onCameraOpened(CAMERA_ID_1, TEST_PACKAGE_1); |