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

Commit 680f91d9 authored by Mina Granic's avatar Mina Granic
Browse files

Add adb commands to enable camera compat for all apps.

These commands will be used to make camera compat testing easier.

Flag: com.android.window.flags.enable_camera_compat_for_desktop_windowing
Test: atest WmTests:AppCompatCameraOverridesTest
Bug: 29732968
Change-Id: I6287508be0be4280a824623c08dcf964e7ce9c50
parent 222c7b1e
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -164,12 +164,14 @@ class AppCompatCameraOverrides {
     * <p>The treatment is enabled when the following conditions are met:
     * <ul>
     * <li>Feature flag gating the camera compatibility free-form treatment is enabled.
     * <li>Activity is opted in by the device manufacturer with override.
     * <li>Activity is opted-in using per-app override, or the treatment is enabled for all apps.
     * </ul>
     */
    boolean shouldApplyFreeformTreatmentForCameraCompat() {
        return Flags.enableCameraCompatForDesktopWindowing() && isChangeEnabled(mActivityRecord,
                OVERRIDE_CAMERA_COMPAT_ENABLE_FREEFORM_WINDOWING_TREATMENT);
        return Flags.enableCameraCompatForDesktopWindowing() && (isChangeEnabled(mActivityRecord,
                OVERRIDE_CAMERA_COMPAT_ENABLE_FREEFORM_WINDOWING_TREATMENT)
                || mActivityRecord.mWmService.mAppCompatConfiguration
                    .isCameraCompatFreeformWindowingTreatmentEnabled());
    }

    boolean isOverrideOrientationOnlyForCameraEnabled() {
+29 −0
Original line number Diff line number Diff line
@@ -304,6 +304,11 @@ final class AppCompatConfiguration {
    // See RefreshCallbackItem for context.
    private boolean mIsCameraCompatRefreshCycleThroughStopEnabled = true;

    // Whether camera compat freeform treatment should be enabled for all eligible activities.
    // This has the same effect as enabling the per-app override
    // ActivityInfo.OVERRIDE_CAMERA_COMPAT_ENABLE_FREEFORM_WINDOWING_TREATMENT for every app.
    private boolean mIsCameraCompatFreeformWindowingTreatmentEnabled = false;

    // Whether should ignore app requested orientation in response to an app
    // calling Activity#setRequestedOrientation. See
    // LetterboxUiController#shouldIgnoreRequestedOrientation for details.
@@ -1350,6 +1355,30 @@ final class AppCompatConfiguration {
                .config_windowManagerCameraCompatAspectRatio);
    }

    /**
     * Sets whether the camera compatibility treatment in freeform windowing mode is enabled for
     * all fixed-orientation apps when using camera.
     */
    void setIsCameraCompatFreeformWindowingTreatmentEnabled(boolean enabled) {
        mIsCameraCompatFreeformWindowingTreatmentEnabled = enabled;
    }

    /**
     * Whether the camera compatibility treatment in freeform windowing mode is enabled for all
     * fixed-orientation apps when using camera.
     */
    boolean isCameraCompatFreeformWindowingTreatmentEnabled() {
        return mIsCameraCompatFreeformWindowingTreatmentEnabled;
    }

    /**
     * Resets whether the camera compatibility treatment in freeform windowing mode is enabled for
     * all fixed-orientation apps when using camera.
     */
    void resetIsCameraCompatFreeformWindowingTreatmentEnabled() {
        mIsCameraCompatFreeformWindowingTreatmentEnabled = false;
    }

    /**
     * Checks whether rotation compat policy for immersive apps that prevents auto rotation
     * into non-optimal screen orientation while in fullscreen is enabled at build time. This is
+19 −2
Original line number Diff line number Diff line
@@ -1166,6 +1166,10 @@ public class WindowManagerShellCommand extends ShellCommand {
                case "--cameraCompatAspectRatio":
                    runSetCameraCompatAspectRatio(pw);
                    break;
                case "--isCameraCompatFreeformWindowingTreatmentEnabled":
                    runSetBooleanFlag(pw, mAppCompatConfiguration
                            ::setIsCameraCompatFreeformWindowingTreatmentEnabled);
                    break;
                default:
                    getErrPrintWriter().println(
                            "Error: Unrecognized letterbox style option: " + arg);
@@ -1260,6 +1264,10 @@ public class WindowManagerShellCommand extends ShellCommand {
                    case "cameraCompatAspectRatio":
                        mAppCompatConfiguration.resetCameraCompatAspectRatio();
                        break;
                    case "isCameraCompatFreeformWindowingTreatmentEnabled":
                        mAppCompatConfiguration
                                .resetIsCameraCompatFreeformWindowingTreatmentEnabled();
                        break;
                    default:
                        getErrPrintWriter().println(
                                "Error: Unrecognized letterbox style option: " + arg);
@@ -1371,6 +1379,7 @@ public class WindowManagerShellCommand extends ShellCommand {
            mAppCompatConfiguration.resetCameraCompatRefreshEnabled();
            mAppCompatConfiguration.resetCameraCompatRefreshCycleThroughStopEnabled();
            mAppCompatConfiguration.resetCameraCompatAspectRatio();
            mAppCompatConfiguration.resetIsCameraCompatFreeformWindowingTreatmentEnabled();
        }
    }

@@ -1445,6 +1454,10 @@ public class WindowManagerShellCommand extends ShellCommand {
                    + mAppCompatConfiguration.isUserAppAspectRatioSettingsEnabled());
            pw.println("Is the fullscreen option in user aspect ratio settings enabled: "
                    + mAppCompatConfiguration.isUserAppAspectRatioFullscreenEnabled());
            pw.println("Default aspect ratio for camera compat freeform: "
                    + mAppCompatConfiguration.getCameraCompatAspectRatio());
            pw.println("Is camera compatibility freeform treatment enabled for all apps: "
                    + mAppCompatConfiguration.isCameraCompatFreeformWindowingTreatmentEnabled());
        }
        return 0;
    }
@@ -1705,6 +1718,9 @@ public class WindowManagerShellCommand extends ShellCommand {
        pw.println("        freeform camera compat mode. If aspectRatio <= "
                + AppCompatConfiguration.MIN_FIXED_ORIENTATION_LETTERBOX_ASPECT_RATIO);
        pw.println("        it will be ignored.");
        pw.println("      --isCameraCompatFreeformWindowingTreatmentEnabled [true|1|false|0]");
        pw.println("        Whether camera compat treatment is enabled in freeform mode for all");
        pw.println("        eligible apps.");
        pw.println("  reset-letterbox-style [aspectRatio|cornerRadius|backgroundType");
        pw.println("      |backgroundColor|wallpaperBlurRadius|wallpaperDarkScrimAlpha");
        pw.println("      |horizontalPositionMultiplier|verticalPositionMultiplier");
@@ -1714,7 +1730,8 @@ public class WindowManagerShellCommand extends ShellCommand {
        pw.println("      |persistentPositionMultiplierForHorizontalReachability");
        pw.println("      |persistentPositionMultiplierForVerticalReachability");
        pw.println("      |defaultPositionMultiplierForVerticalReachability");
        pw.println("      |cameraCompatAspectRatio]");
        pw.println("      |cameraCompatAspectRatio");
        pw.println("      |isCameraCompatFreeformWindowingTreatmentEnabled]");
        pw.println("    Resets overrides to default values for specified properties separated");
        pw.println("    by space, e.g. 'reset-letterbox-style aspectRatio cornerRadius'.");
        pw.println("    If no arguments provided, all values will be reset.");
+17 −0
Original line number Diff line number Diff line
@@ -248,6 +248,18 @@ public class AppCompatCameraOverridesTest extends WindowTestsBase {
        });
    }

    @Test
    @EnableFlags(FLAG_ENABLE_CAMERA_COMPAT_FOR_DESKTOP_WINDOWING)
    public void testShouldApplyCameraCompatFreeformTreatment_enabledByShellCommand_returnsTrue() {
        runTestScenario((robot) -> {
            robot.activity().createActivityWithComponentInNewTask();

            robot.setCameraCompatTreatmentEnabledViaShellCommand(true);

            robot.checkShouldApplyFreeformTreatmentForCameraCompat(true);
        });
    }

    @Test
    @EnableCompatChanges({OVERRIDE_ORIENTATION_ONLY_FOR_CAMERA,
            OVERRIDE_MIN_ASPECT_RATIO_ONLY_FOR_CAMERA,
@@ -350,6 +362,11 @@ public class AppCompatCameraOverridesTest extends WindowTestsBase {
            spyOn(displayContent.mAppCompatCameraPolicy);
        }

        void setCameraCompatTreatmentEnabledViaShellCommand(boolean enabled) {
            activity().top().mWmService.mAppCompatConfiguration
                    .setIsCameraCompatFreeformWindowingTreatmentEnabled(enabled);
        }

        void checkShouldRefreshActivityForCameraCompat(boolean expected) {
            Assert.assertEquals(getAppCompatCameraOverrides()
                    .shouldRefreshActivityForCameraCompat(), expected);