diff options
4 files changed, 107 insertions, 10 deletions
diff --git a/core/java/android/content/pm/ActivityInfo.java b/core/java/android/content/pm/ActivityInfo.java index e6450606d450..fd59ea9d18fb 100644 --- a/core/java/android/content/pm/ActivityInfo.java +++ b/core/java/android/content/pm/ActivityInfo.java @@ -1347,6 +1347,33 @@ public class ActivityInfo extends ComponentInfo implements Parcelable { 314961188L; /** + * Excludes the packages the override is applied to from the camera compatibility treatment for + * fixed-orientation apps, which simulates running on a portrait device, in the orientation + * requested by the app. + * + * <p>This treatment aims to mitigate camera issues on large screens, like stretched or sideways + * previews. It simulates running on a portrait device by: + * <ul> + * <li>Letterboxing the app window, + * <li>Cropping the camera buffer to match the app's requested orientation, + * <li>Setting the camera sensor orientation to portrait. + * <li>Setting the display rotation to match the app's requested orientation, given portrait + * natural orientation, + * <li>Refreshes the activity to trigger new camera setup, with sandboxed values. + * </ul> + * + * <p>By setting this override to {@code true}, it disables the camera compatibility treatment + * which simulates app's requested orientation. + * + * @hide + */ + @ChangeId + @Overridable + @Disabled + public static final long OVERRIDE_CAMERA_COMPAT_DISABLE_SIMULATE_REQUESTED_ORIENTATION = + 398195815L; // buganizer id + + /** * This change id forces the packages it is applied to sandbox {@link android.view.View} API to * an activity bounds for: * diff --git a/services/core/java/com/android/server/wm/AppCompatCameraOverrides.java b/services/core/java/com/android/server/wm/AppCompatCameraOverrides.java index 5eed54704f36..cb82f480d73b 100644 --- a/services/core/java/com/android/server/wm/AppCompatCameraOverrides.java +++ b/services/core/java/com/android/server/wm/AppCompatCameraOverrides.java @@ -18,6 +18,7 @@ package com.android.server.wm; import static android.content.pm.ActivityInfo.OVERRIDE_CAMERA_COMPAT_DISABLE_FORCE_ROTATION; import static android.content.pm.ActivityInfo.OVERRIDE_CAMERA_COMPAT_DISABLE_REFRESH; +import static android.content.pm.ActivityInfo.OVERRIDE_CAMERA_COMPAT_DISABLE_SIMULATE_REQUESTED_ORIENTATION; import static android.content.pm.ActivityInfo.OVERRIDE_CAMERA_COMPAT_ENABLE_FREEFORM_WINDOWING_TREATMENT; import static android.content.pm.ActivityInfo.OVERRIDE_CAMERA_COMPAT_ENABLE_REFRESH_VIA_PAUSE; import static android.content.pm.ActivityInfo.OVERRIDE_MIN_ASPECT_RATIO_ONLY_FOR_CAMERA; @@ -183,9 +184,10 @@ class AppCompatCameraOverrides { private boolean shouldEnableCameraCompatFreeformTreatmentForApp() { if (mCameraCompatAllowOrientationTreatmentOptProp != null) { + // OptProp is not-null iff the opt-out flag is on. return mCameraCompatAllowOrientationTreatmentOptProp .shouldEnableWithOptOutOverrideAndProperty(isChangeEnabled(mActivityRecord, - OVERRIDE_CAMERA_COMPAT_ENABLE_FREEFORM_WINDOWING_TREATMENT)); + OVERRIDE_CAMERA_COMPAT_DISABLE_SIMULATE_REQUESTED_ORIENTATION)); } else { return isChangeEnabled(mActivityRecord, OVERRIDE_CAMERA_COMPAT_ENABLE_FREEFORM_WINDOWING_TREATMENT); diff --git a/services/tests/wmtests/src/com/android/server/wm/AppCompatCameraOverridesTest.java b/services/tests/wmtests/src/com/android/server/wm/AppCompatCameraOverridesTest.java index d4be7f812cb5..51da5115c95a 100644 --- a/services/tests/wmtests/src/com/android/server/wm/AppCompatCameraOverridesTest.java +++ b/services/tests/wmtests/src/com/android/server/wm/AppCompatCameraOverridesTest.java @@ -18,6 +18,7 @@ package com.android.server.wm; import static android.content.pm.ActivityInfo.OVERRIDE_CAMERA_COMPAT_DISABLE_FORCE_ROTATION; import static android.content.pm.ActivityInfo.OVERRIDE_CAMERA_COMPAT_DISABLE_REFRESH; +import static android.content.pm.ActivityInfo.OVERRIDE_CAMERA_COMPAT_DISABLE_SIMULATE_REQUESTED_ORIENTATION; import static android.content.pm.ActivityInfo.OVERRIDE_CAMERA_COMPAT_ENABLE_FREEFORM_WINDOWING_TREATMENT; import static android.content.pm.ActivityInfo.OVERRIDE_CAMERA_COMPAT_ENABLE_REFRESH_VIA_PAUSE; import static android.content.pm.ActivityInfo.OVERRIDE_MIN_ASPECT_RATIO_ONLY_FOR_CAMERA; @@ -231,6 +232,7 @@ public class AppCompatCameraOverridesTest extends WindowTestsBase { @Test @EnableFlags(FLAG_ENABLE_CAMERA_COMPAT_FOR_DESKTOP_WINDOWING) + @DisableFlags(FLAG_ENABLE_CAMERA_COMPAT_FOR_DESKTOP_WINDOWING_OPT_OUT) public void testShouldApplyCameraCompatFreeformTreatment_notEnabledByOverride_returnsFalse() { runTestScenario((robot) -> { robot.activity().createActivityWithComponentInNewTask(); @@ -240,21 +242,19 @@ public class AppCompatCameraOverridesTest extends WindowTestsBase { } @Test - @EnableCompatChanges({OVERRIDE_CAMERA_COMPAT_ENABLE_FREEFORM_WINDOWING_TREATMENT}) + @EnableCompatChanges({OVERRIDE_CAMERA_COMPAT_DISABLE_SIMULATE_REQUESTED_ORIENTATION}) @EnableFlags({FLAG_ENABLE_CAMERA_COMPAT_FOR_DESKTOP_WINDOWING, FLAG_ENABLE_CAMERA_COMPAT_FOR_DESKTOP_WINDOWING_OPT_OUT}) - public void testShouldApplyCameraCompatFreeformTreatment_propertyFalse_returnsFalse() { + public void testShouldApplyCameraCompatFreeformTreatment_disablePropertyOn_returnsFalse() { runTestScenario((robot) -> { robot.activity().createActivityWithComponentInNewTask(); - robot.prop().disable(PROPERTY_CAMERA_COMPAT_ALLOW_SIMULATE_REQUESTED_ORIENTATION); - robot.checkShouldApplyFreeformTreatmentForCameraCompat(false); }); } @Test - @EnableCompatChanges({OVERRIDE_CAMERA_COMPAT_ENABLE_FREEFORM_WINDOWING_TREATMENT}) + @EnableCompatChanges(OVERRIDE_CAMERA_COMPAT_ENABLE_FREEFORM_WINDOWING_TREATMENT) @EnableFlags(FLAG_ENABLE_CAMERA_COMPAT_FOR_DESKTOP_WINDOWING) @DisableFlags(FLAG_ENABLE_CAMERA_COMPAT_FOR_DESKTOP_WINDOWING_OPT_OUT) public void testShouldApplyCameraCompatFreeformTreatment_optOutFlagNotEnabled_optOutIgnored() { @@ -262,15 +262,31 @@ public class AppCompatCameraOverridesTest extends WindowTestsBase { robot.activity().createActivityWithComponentInNewTask(); robot.prop().disable(PROPERTY_CAMERA_COMPAT_ALLOW_SIMULATE_REQUESTED_ORIENTATION); + robot.activity().createActivityWithComponentInNewTask(); robot.checkShouldApplyFreeformTreatmentForCameraCompat(true); }); } @Test - @EnableCompatChanges({OVERRIDE_CAMERA_COMPAT_ENABLE_FREEFORM_WINDOWING_TREATMENT}) + @EnableFlags({FLAG_ENABLE_CAMERA_COMPAT_FOR_DESKTOP_WINDOWING, + FLAG_ENABLE_CAMERA_COMPAT_FOR_DESKTOP_WINDOWING_OPT_OUT}) + public void testShouldApplyCameraCompatFreeformTreatment_optedOutViaProperty_returnsFalse() { + runTestScenario((robot) -> { + robot.activity().createActivityWithComponentInNewTask(); + + robot.prop().disable(PROPERTY_CAMERA_COMPAT_ALLOW_SIMULATE_REQUESTED_ORIENTATION); + robot.activity().createActivityWithComponentInNewTask(); + + robot.checkShouldApplyFreeformTreatmentForCameraCompat(false); + }); + } + + @Test + @EnableCompatChanges(OVERRIDE_CAMERA_COMPAT_ENABLE_FREEFORM_WINDOWING_TREATMENT) @EnableFlags(FLAG_ENABLE_CAMERA_COMPAT_FOR_DESKTOP_WINDOWING) - public void testShouldApplyCameraCompatFreeformTreatment_overrideAndFlagEnabled_returnsTrue() { + @DisableFlags(FLAG_ENABLE_CAMERA_COMPAT_FOR_DESKTOP_WINDOWING_OPT_OUT) + public void testShouldApplyCameraCompatFreeformTreatment_optInAndFlagEnabled_returnsTrue() { runTestScenario((robot) -> { robot.activity().createActivityWithComponentInNewTask(); @@ -278,6 +294,22 @@ public class AppCompatCameraOverridesTest extends WindowTestsBase { }); } + + @Test + @EnableFlags({FLAG_ENABLE_CAMERA_COMPAT_FOR_DESKTOP_WINDOWING, + FLAG_ENABLE_CAMERA_COMPAT_FOR_DESKTOP_WINDOWING_OPT_OUT}) + public void testShouldApplyCameraCompatFreeformTreatment_notOptedOut_flagEnabled_returnsTrue() { + runTestScenario((robot) -> { + robot.conf().enableCameraCompatTreatment(true); + robot.applyOnActivity((a) -> { + a.createActivityWithComponentInNewTask(); + robot.prop().enable(PROPERTY_CAMERA_COMPAT_ALLOW_SIMULATE_REQUESTED_ORIENTATION); + }); + + robot.checkShouldApplyFreeformTreatmentForCameraCompat(true); + }); + } + @Test @EnableFlags(FLAG_ENABLE_CAMERA_COMPAT_FOR_DESKTOP_WINDOWING) public void testShouldApplyCameraCompatFreeformTreatment_enabledByShellCommand_returnsTrue() { @@ -294,6 +326,8 @@ public class AppCompatCameraOverridesTest extends WindowTestsBase { @EnableCompatChanges({OVERRIDE_ORIENTATION_ONLY_FOR_CAMERA, OVERRIDE_MIN_ASPECT_RATIO_ONLY_FOR_CAMERA, OVERRIDE_CAMERA_COMPAT_ENABLE_FREEFORM_WINDOWING_TREATMENT}) + @EnableFlags(FLAG_ENABLE_CAMERA_COMPAT_FOR_DESKTOP_WINDOWING) + @DisableFlags(FLAG_ENABLE_CAMERA_COMPAT_FOR_DESKTOP_WINDOWING_OPT_OUT) public void testShouldRecomputeConfigurationForFreeformTreatment() { runTestScenario((robot) -> { robot.conf().enableCameraCompatSplitScreenAspectRatio(true); @@ -307,6 +341,24 @@ public class AppCompatCameraOverridesTest extends WindowTestsBase { } @Test + @EnableCompatChanges({OVERRIDE_ORIENTATION_ONLY_FOR_CAMERA, + OVERRIDE_MIN_ASPECT_RATIO_ONLY_FOR_CAMERA}) + @EnableFlags({FLAG_ENABLE_CAMERA_COMPAT_FOR_DESKTOP_WINDOWING, + FLAG_ENABLE_CAMERA_COMPAT_FOR_DESKTOP_WINDOWING_OPT_OUT}) + public void testShouldRecomputeConfigurationForFreeformTreatmentWithOptOutMechanism() { + runTestScenario((robot) -> { + robot.conf().enableCameraCompatSplitScreenAspectRatio(true); + robot.conf().enableCameraCompatTreatment(true); + robot.applyOnActivity((a) -> { + a.createActivityWithComponentInNewTask(); + robot.prop().enable(PROPERTY_CAMERA_COMPAT_ALLOW_SIMULATE_REQUESTED_ORIENTATION); + }); + + robot.checkShouldApplyFreeformTreatmentForCameraCompat(true); + }); + } + + @Test @EnableCompatChanges({OVERRIDE_MIN_ASPECT_RATIO_ONLY_FOR_CAMERA}) public void shouldOverrideMinAspectRatioForCamera_overrideEnabled_returnsTrue() { runTestScenario((robot) -> { diff --git a/services/tests/wmtests/src/com/android/server/wm/CameraCompatFreeformPolicyTests.java b/services/tests/wmtests/src/com/android/server/wm/CameraCompatFreeformPolicyTests.java index 560725241853..50876c7a6758 100644 --- a/services/tests/wmtests/src/com/android/server/wm/CameraCompatFreeformPolicyTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/CameraCompatFreeformPolicyTests.java @@ -25,6 +25,7 @@ import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM; import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; import static android.app.servertransaction.ActivityLifecycleItem.ON_PAUSE; import static android.app.servertransaction.ActivityLifecycleItem.ON_STOP; +import static android.content.pm.ActivityInfo.OVERRIDE_CAMERA_COMPAT_DISABLE_SIMULATE_REQUESTED_ORIENTATION; import static android.content.pm.ActivityInfo.OVERRIDE_CAMERA_COMPAT_ENABLE_FREEFORM_WINDOWING_TREATMENT; import static android.content.pm.ActivityInfo.RESIZE_MODE_RESIZEABLE; import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_FULL_USER; @@ -42,6 +43,7 @@ import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn; import static com.android.dx.mockito.inline.extended.ExtendedMockito.when; import static com.android.server.wm.AppCompatConfiguration.MIN_FIXED_ORIENTATION_LETTERBOX_ASPECT_RATIO; import static com.android.window.flags.Flags.FLAG_ENABLE_CAMERA_COMPAT_FOR_DESKTOP_WINDOWING; +import static com.android.window.flags.Flags.FLAG_ENABLE_CAMERA_COMPAT_FOR_DESKTOP_WINDOWING_OPT_OUT; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -134,8 +136,10 @@ public class CameraCompatFreeformPolicyTests extends WindowTestsBase { } @Test - @EnableFlags(FLAG_ENABLE_CAMERA_COMPAT_FOR_DESKTOP_WINDOWING) - public void testIsCameraRunningAndWindowingModeEligible_overrideDisabled_returnsFalse() { + @EnableFlags({FLAG_ENABLE_CAMERA_COMPAT_FOR_DESKTOP_WINDOWING, + FLAG_ENABLE_CAMERA_COMPAT_FOR_DESKTOP_WINDOWING_OPT_OUT}) + @EnableCompatChanges({OVERRIDE_CAMERA_COMPAT_DISABLE_SIMULATE_REQUESTED_ORIENTATION}) + public void testIsCameraRunningAndWindowingModeEligible_disabledViaOverride_returnsFalse() { configureActivity(SCREEN_ORIENTATION_PORTRAIT); mCameraAvailabilityCallback.onCameraOpened(CAMERA_ID_1, TEST_PACKAGE_1); @@ -165,6 +169,7 @@ public class CameraCompatFreeformPolicyTests extends WindowTestsBase { @Test @EnableFlags(FLAG_ENABLE_CAMERA_COMPAT_FOR_DESKTOP_WINDOWING) + @DisableFlags(FLAG_ENABLE_CAMERA_COMPAT_FOR_DESKTOP_WINDOWING_OPT_OUT) @EnableCompatChanges({OVERRIDE_CAMERA_COMPAT_ENABLE_FREEFORM_WINDOWING_TREATMENT}) public void testIsCameraRunningAndWindowingModeEligible_optInFreeformCameraRunning_true() { configureActivity(SCREEN_ORIENTATION_PORTRAIT); @@ -175,6 +180,17 @@ public class CameraCompatFreeformPolicyTests extends WindowTestsBase { } @Test + @EnableFlags({FLAG_ENABLE_CAMERA_COMPAT_FOR_DESKTOP_WINDOWING, + FLAG_ENABLE_CAMERA_COMPAT_FOR_DESKTOP_WINDOWING_OPT_OUT}) + public void testIsCameraRunningAndWindowingModeEligible_freeformCameraRunning_true() { + configureActivity(SCREEN_ORIENTATION_PORTRAIT); + + onCameraOpened(CAMERA_ID_1, TEST_PACKAGE_1); + + assertTrue(mCameraCompatFreeformPolicy.isCameraRunningAndWindowingModeEligible(mActivity)); + } + + @Test @EnableFlags(FLAG_ENABLE_CAMERA_COMPAT_FOR_DESKTOP_WINDOWING) public void testIsFreeformLetterboxingForCameraAllowed_overrideDisabled_returnsFalse() { configureActivity(SCREEN_ORIENTATION_PORTRAIT); |