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

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

Merge "Add a config to allow OEMs to disable camera compat simulate requested...

Merge "Add a config to allow OEMs to disable camera compat simulate requested orientation treatment." into main
parents 5bcb14fd aa232875
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -6501,6 +6501,13 @@
        is enabled and activity is connected to the camera in fullscreen. -->
    <bool name="config_isWindowManagerCameraCompatSplitScreenAspectRatioEnabled">false</bool>

    <!-- Whether camera compat treatment which simulates app's requested orientation is enabled. The
        purpose of the treatment is to mitigate issues caused by orientation mismatch between camera
        buffer and an app window. This includes letterboxing fixed orientation activities connected
        to the camera, cropping the camera buffer (rotate-and-crop) and sandboxing display rotation
        to match what the apps most likely expect in their requested orientation. -->
    <bool name="config_isCameraCompatSimulateRequestedOrientationTreatmentEnabled">true</bool>

    <!-- Which aspect ratio to use when camera compat treatment is enabled and an activity eligible
        for treatment is connected to the camera. -->
    <item name="config_windowManagerCameraCompatAspectRatio" format="float" type="dimen">1.0</item>
+1 −0
Original line number Diff line number Diff line
@@ -4961,6 +4961,7 @@
  <java-symbol type="bool" name="config_isCompatFakeFocusEnabled" />
  <java-symbol type="bool" name="config_isWindowManagerCameraCompatTreatmentEnabled" />
  <java-symbol type="bool" name="config_isWindowManagerCameraCompatSplitScreenAspectRatioEnabled" />
  <java-symbol type="bool" name="config_isCameraCompatSimulateRequestedOrientationTreatmentEnabled" />
  <java-symbol type="dimen" name="config_windowManagerCameraCompatAspectRatio" />
  <java-symbol type="bool" name="config_skipActivityRelaunchWhenDocking" />

+17 −13
Original line number Diff line number Diff line
@@ -77,23 +77,25 @@ class AppCompatCameraOverrides {
                PROPERTY_COMPAT_ALLOW_MIN_ASPECT_RATIO_OVERRIDE);
        final BooleanSupplier isCameraCompatForceRotateTreatmentEnabled = AppCompatUtils.asLazy(
                mAppCompatConfiguration::isCameraCompatForceRotateTreatmentEnabled);
        final BooleanSupplier isCameraCompatSimulateRequestedOrientationTreatmentEnabled =
                AppCompatUtils.asLazy(mAppCompatConfiguration
                        ::isCameraCompatSimulateRequestedOrientationTreatmentEnabled);
        final BooleanSupplier isAnyCameraCompatTreatmentEnabled = AppCompatUtils.asLazy(
                mAppCompatConfiguration::isAnyCameraCompatTreatmentEnabled);

        mCameraCompatAllowRefreshOptProp = optPropBuilder.create(
                PROPERTY_CAMERA_COMPAT_ALLOW_REFRESH,
                // TODO(b/425491882): check if any camera compat treatment is available.
                isCameraCompatForceRotateTreatmentEnabled);
                isAnyCameraCompatTreatmentEnabled);
        mCameraCompatEnableRefreshViaPauseOptProp = optPropBuilder.create(
                PROPERTY_CAMERA_COMPAT_ENABLE_REFRESH_VIA_PAUSE,
                // TODO(b/425491882): check if any camera compat treatment is available.
                isCameraCompatForceRotateTreatmentEnabled);
                isAnyCameraCompatTreatmentEnabled);
        mCameraCompatAllowForceRotationOptProp = optPropBuilder.create(
                PROPERTY_CAMERA_COMPAT_ALLOW_FORCE_ROTATION,
                isCameraCompatForceRotateTreatmentEnabled);
        mCameraCompatAllowOrientationTreatmentOptProp =
                Flags.enableCameraCompatForDesktopWindowingOptOut() ? optPropBuilder.create(
                PROPERTY_CAMERA_COMPAT_ALLOW_SIMULATE_REQUESTED_ORIENTATION,
                        // TODO(b/425491882): check if simulate requested orientation camera compat
                        //  treatment is available.
                        isCameraCompatForceRotateTreatmentEnabled) : null;
                        isCameraCompatSimulateRequestedOrientationTreatmentEnabled) : null;
    }

    /**
@@ -183,14 +185,16 @@ class AppCompatCameraOverrides {
     */
    boolean shouldApplyFreeformTreatmentForCameraCompat() {
        return DesktopModeFlags.ENABLE_CAMERA_COMPAT_SIMULATE_REQUESTED_ORIENTATION.isTrue()
                && (shouldEnableCameraCompatFreeformTreatmentForApp()
                || shouldEnableCameraCompatFreeformTreatmentForAllApps());
                && (shouldEnableCameraCompatSimulateRequestedOrientationTreatmentForApp()
                || shouldForceEnableCameraCompatSimulateRequestedOrientationTreatment());
    }

    private boolean shouldEnableCameraCompatFreeformTreatmentForApp() {
    private boolean shouldEnableCameraCompatSimulateRequestedOrientationTreatmentForApp() {
        if (mCameraCompatAllowOrientationTreatmentOptProp != null) {
            // OptProp is not-null iff the opt-out flag is on.
            return mCameraCompatAllowOrientationTreatmentOptProp
            return mAppCompatConfiguration
                    .isCameraCompatSimulateRequestedOrientationTreatmentEnabled()
                    && mCameraCompatAllowOrientationTreatmentOptProp
                    .shouldEnableWithOptOutOverrideAndProperty(isChangeEnabled(mActivityRecord,
                            OVERRIDE_CAMERA_COMPAT_DISABLE_SIMULATE_REQUESTED_ORIENTATION));
        } else {
@@ -205,9 +209,9 @@ class AppCompatCameraOverrides {
     *
     * <p>This can be enabled via adb only.
     */
    private boolean shouldEnableCameraCompatFreeformTreatmentForAllApps() {
    private boolean shouldForceEnableCameraCompatSimulateRequestedOrientationTreatment() {
        return mActivityRecord.mWmService.mAppCompatConfiguration
                .isCameraCompatFreeformWindowingTreatmentEnabled();
                .isCameraCompatSimReqOrientationTreatmentForceEnabled();
    }

    boolean isOverrideOrientationOnlyForCameraEnabled() {
+3 −1
Original line number Diff line number Diff line
@@ -56,7 +56,9 @@ class AppCompatCameraPolicy {
                .isCameraCompatForceRotateTreatmentEnabledAtBuildTime();
        final boolean needsCameraCompatFreeformPolicy =
                DesktopModeFlags.ENABLE_CAMERA_COMPAT_SIMULATE_REQUESTED_ORIENTATION.isTrue()
                        && DesktopModeHelper.canEnterDesktopMode(wmService.mContext);
                        && DesktopModeHelper.canEnterDesktopMode(wmService.mContext)
                        && wmService.mAppCompatConfiguration
                        .isCameraCompatSimulateRequestedOrientationTreatmentEnabled();
        if (needsDisplayRotationCompatPolicy || needsCameraCompatFreeformPolicy) {
            final AppCompatCameraStateSource cameraStateListenerDelegate =
                    new AppCompatCameraStateSource();
+47 −9
Original line number Diff line number Diff line
@@ -290,6 +290,13 @@ final class AppCompatConfiguration {
    // is enabled and activity is connected to the camera in fullscreen.
    private final boolean mIsCameraCompatSplitScreenAspectRatioEnabled;

    // Whether camera compat treatment that simulates requested orientation is enabled.
    // The purpose of the treatment is to mitigate issues caused by orientation mismatch between the
    // camera buffer and the app window. This includes letterboxing fixed orientation activities
    // connected to the camera, cropping the camera buffer (rotate-and-crop) and sandboxing display
    // rotation to match what the apps most likely expect in their requested orientation
    private final boolean mIsCameraCompatSimulateRequestedOrientationTreatmentEnabled;

    // Which aspect ratio to use when camera compat treatment is enabled and an activity eligible
    // for treatment is connected to the camera.
    private float mCameraCompatAspectRatio;
@@ -305,9 +312,11 @@ final class AppCompatConfiguration {
    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;
    // This has the same effect as enabling the treatment via
    // `mIsCameraCompatSimulateRequestedOrientationTreatmentEnabled`, and removing all opt-out
    // overrides and properties for this treatment.
    // This property is only settable via adb, and should be used for testing only.
    private boolean mIsCameraCompatSimulateRequestedOrientationTreatmentForceEnabled = false;

    // Whether should ignore app requested orientation in response to an app
    // calling Activity#setRequestedOrientation. See
@@ -372,6 +381,9 @@ final class AppCompatConfiguration {
                        .config_letterboxIsDisplayAspectRatioForFixedOrientationLetterboxEnabled);
        mIsCameraCompatSplitScreenAspectRatioEnabled = mContext.getResources().getBoolean(
                R.bool.config_isWindowManagerCameraCompatSplitScreenAspectRatioEnabled);
        mIsCameraCompatSimulateRequestedOrientationTreatmentEnabled = mContext.getResources()
                .getBoolean(R.bool
                        .config_isCameraCompatSimulateRequestedOrientationTreatmentEnabled);
        mCameraCompatAspectRatio = mContext.getResources().getFloat(
                R.dimen.config_windowManagerCameraCompatAspectRatio);
        mIsPolicyForIgnoringRequestedOrientationEnabled = mContext.getResources().getBoolean(
@@ -1355,28 +1367,54 @@ final class AppCompatConfiguration {
                .config_windowManagerCameraCompatAspectRatio);
    }

    /**
     * Whether the camera compatibility treatment which simulates requested orientation is allowed
     * on this device.
     *
     * <p>For the treatment to activate, the following conditions also need to be met:
     * <ul>
     *     <li>OEM has not opted-out the app for the given device model via per-app override.
     *     <li>App has not opted-out via manifest property.
     *     <li>Camera is active for the package.
     *     <li>The activity is in freeform windowing mode.
     *     <li>The activity has fixed orientation but not "locked" or "nosensor".
     * </ul>
     */
    boolean isCameraCompatSimulateRequestedOrientationTreatmentEnabled() {
        return mIsCameraCompatSimulateRequestedOrientationTreatmentEnabled;
    }

    /**
     * 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;
    void setIsCameraCompatSimReqOrientationTreatmentForceEnabled(boolean enabled) {
        mIsCameraCompatSimulateRequestedOrientationTreatmentForceEnabled = enabled;
    }

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

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

    /**
     * Whether any camera compat treatment is enabled, for the purpose of enabling common camera
     * compat components.
     */
    boolean isAnyCameraCompatTreatmentEnabled() {
        return isCameraCompatForceRotateTreatmentEnabled()
                || isCameraCompatSimulateRequestedOrientationTreatmentEnabled();
    }

    /**
Loading