Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9889c37a authored by Mina Granic's avatar Mina Granic Committed by Android (Google) Code Review
Browse files

Merge "Use opt-out instead of opt-in approach for camera compat." into main

parents 2b5170fb eff8d78c
Loading
Loading
Loading
Loading
+27 −0
Original line number Diff line number Diff line
@@ -1346,6 +1346,33 @@ public class ActivityInfo extends ComponentInfo implements Parcelable {
    public static final long OVERRIDE_CAMERA_COMPAT_ENABLE_FREEFORM_WINDOWING_TREATMENT =
            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:
+3 −1
Original line number Diff line number Diff line
@@ -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);
+59 −7
Original line number Diff line number Diff line
@@ -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);
@@ -306,6 +340,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() {
+18 −2
Original line number Diff line number Diff line
@@ -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);
@@ -174,6 +179,17 @@ public class CameraCompatFreeformPolicyTests extends WindowTestsBase {
        assertTrue(mCameraCompatFreeformPolicy.isCameraRunningAndWindowingModeEligible(mActivity));
    }

    @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() {