Merge "[6/n] Camera Compat: Fix the toast gating condition." into tm-qpr-dev

This commit is contained in:
Mariia Sandrikova
2023-02-08 21:36:31 +00:00
committed by Android (Google) Code Review
2 changed files with 44 additions and 11 deletions

View File

@@ -250,10 +250,7 @@ final class DisplayRotationCompatPolicy {
} }
ActivityRecord topActivity = mDisplayContent.topRunningActivity( ActivityRecord topActivity = mDisplayContent.topRunningActivity(
/* considerKeyguardState= */ true); /* considerKeyguardState= */ true);
if (topActivity == null if (!isTreatmentEnabledForActivity(topActivity)) {
// Checking windowing mode on activity level because we don't want to
// show toast in case of activity embedding.
|| topActivity.getWindowingMode() != WINDOWING_MODE_FULLSCREEN) {
return; return;
} }
showToast(R.string.display_rotation_camera_compat_toast_after_rotation); showToast(R.string.display_rotation_camera_compat_toast_after_rotation);
@@ -309,21 +306,28 @@ final class DisplayRotationCompatPolicy {
} }
boolean isActivityEligibleForOrientationOverride(@NonNull ActivityRecord activity) { 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. * Whether camera compat treatment is applicable for the given activity.
* *
* <p>Conditions that need to be met: * <p>Conditions that need to be met:
* <ul> * <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 is in fullscreen
* <li>The activity has fixed orientation but not "locked" or "nosensor" one. * <li>The activity has fixed orientation but not "locked" or "nosensor" one.
* </ul> * </ul>
*/ */
boolean isTreatmentEnabledForActivity(@Nullable ActivityRecord activity) { 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 && activity.getRequestedConfigurationOrientation() != ORIENTATION_UNDEFINED
// "locked" and "nosensor" values are often used by camera apps that can't // "locked" and "nosensor" values are often used by camera apps that can't
// handle dynamic changes so we shouldn't force rotate them. // handle dynamic changes so we shouldn't force rotate them.
@@ -331,8 +335,10 @@ final class DisplayRotationCompatPolicy {
&& activity.getOverrideOrientation() != SCREEN_ORIENTATION_LOCKED; && activity.getOverrideOrientation() != SCREEN_ORIENTATION_LOCKED;
} }
private boolean isCameraActiveInFullscreen(@NonNull ActivityRecord activity) { private boolean isCameraActive(@NonNull ActivityRecord activity, boolean mustBeFullscreen) {
return !activity.inMultiWindowMode() // 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) && mCameraIdPackageBiMap.containsPackageName(activity.packageName)
&& activity.mLetterboxUiController.shouldForceRotateForCameraCompat(); && 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 // Checking that the whole app is in multi-window mode as we shouldn't show toast
// for the activity embedding case. // 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); 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); 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 @Test
public void testOnScreenRotationAnimationFinished_treatmentNotEnabled_doNotShowToast() { public void testOnScreenRotationAnimationFinished_treatmentNotEnabled_doNotShowToast() {
when(mLetterboxConfiguration.isCameraCompatTreatmentEnabled( when(mLetterboxConfiguration.isCameraCompatTreatmentEnabled(
@@ -172,7 +186,7 @@ public final class DisplayRotationCompatPolicyTests extends WindowTestsBase {
@Test @Test
public void testOnScreenRotationAnimationFinished_notFullscreen_doNotShowToast() { public void testOnScreenRotationAnimationFinished_notFullscreen_doNotShowToast() {
configureActivity(SCREEN_ORIENTATION_PORTRAIT); configureActivity(SCREEN_ORIENTATION_PORTRAIT);
doReturn(WINDOWING_MODE_MULTI_WINDOW).when(mActivity).getWindowingMode(); doReturn(true).when(mActivity).inMultiWindowMode();
spyOn(mDisplayRotationCompatPolicy); spyOn(mDisplayRotationCompatPolicy);
mCameraAvailabilityCallback.onCameraOpened(CAMERA_ID_1, TEST_PACKAGE_1); 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); 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 @Test
public void testOnScreenRotationAnimationFinished_showToast() { public void testOnScreenRotationAnimationFinished_showToast() {
configureActivity(SCREEN_ORIENTATION_PORTRAIT); configureActivity(SCREEN_ORIENTATION_PORTRAIT);