[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
This commit is contained in:
Mariia Sandrikova
2023-02-07 19:22:46 +00:00
parent 02cdf72ad3
commit 3e7f0dc19c
2 changed files with 44 additions and 11 deletions

View File

@@ -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);
}
}

View File

@@ -146,6 +146,20 @@ public final class DisplayRotationCompatPolicyTests extends WindowTestsBase {
R.string.display_rotation_camera_compat_toast_in_split_screen);
}
@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(
@@ -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);
@@ -183,6 +197,18 @@ public final class DisplayRotationCompatPolicyTests extends WindowTestsBase {
R.string.display_rotation_camera_compat_toast_after_rotation);
}
@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);