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

Commit 497a4510 authored by Massimo Carli's avatar Massimo Carli Committed by Automerger Merge Worker
Browse files

Merge "[3/n] Improve LetterboxConfiguration readability" into udc-qpr-dev am: 671bd95e

parents e28eb1a2 671bd95e
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -1214,8 +1214,7 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
        mDisplayRotationCompatPolicy =
                // Not checking DeviceConfig value here to allow enabling via DeviceConfig
                // without the need to restart the device.
                mWmService.mLetterboxConfiguration.isCameraCompatTreatmentEnabled(
                            /* checkDeviceConfig */ false)
                mWmService.mLetterboxConfiguration.isCameraCompatTreatmentEnabledAtBuildTime()
                        ? new DisplayRotationCompatPolicy(this) : null;
        mRotationReversionController = new DisplayRotationReversionController(this);

+1 −2
Original line number Diff line number Diff line
@@ -336,8 +336,7 @@ final class DisplayRotationCompatPolicy {
     * </ul>
     */
    private boolean isTreatmentEnabledForDisplay() {
        return mWmService.mLetterboxConfiguration.isCameraCompatTreatmentEnabled(
                    /* checkDeviceConfig */ true)
        return mWmService.mLetterboxConfiguration.isCameraCompatTreatmentEnabled()
                && mDisplayContent.getIgnoreOrientationRequest()
                // TODO(b/225928882): Support camera compat rotation for external displays
                && mDisplayContent.getDisplay().getType() == TYPE_INTERNAL;
+2 −3
Original line number Diff line number Diff line
@@ -44,7 +44,7 @@ final class DisplayRotationImmersiveAppCompatPolicy {
            @NonNull final DisplayRotation displayRotation,
            @NonNull final DisplayContent displayContent) {
        if (!letterboxConfiguration
                .isDisplayRotationImmersiveAppCompatPolicyEnabled(/* checkDeviceConfig */ false)) {
                .isDisplayRotationImmersiveAppCompatPolicyEnabledAtBuildTime()) {
            return null;
        }

@@ -87,8 +87,7 @@ final class DisplayRotationImmersiveAppCompatPolicy {
     * @return {@code true}, if there is a need to lock screen rotation, {@code false} otherwise.
     */
    boolean isRotationLockEnforced(@Surface.Rotation final int proposedRotation) {
        if (!mLetterboxConfiguration.isDisplayRotationImmersiveAppCompatPolicyEnabled(
                /* checkDeviceConfig */ true)) {
        if (!mLetterboxConfiguration.isDisplayRotationImmersiveAppCompatPolicyEnabled()) {
            return false;
        }
        synchronized (mDisplayContent.mWmService.mGlobalLock) {
+28 −16
Original line number Diff line number Diff line
@@ -1125,15 +1125,19 @@ final class LetterboxConfiguration {
    }

    /**
     * Whether camera compatibility treatment is enabled.
     *
     * @param checkDeviceConfig whether it should check both build time flag and a dynamic property
     *        from {@link DeviceConfig} or only build time flag value.
     * @return Whether camera compatibility treatment is currently enabled.
     */
    boolean isCameraCompatTreatmentEnabled(boolean checkDeviceConfig) {
        return mDeviceConfig.isBuildTimeFlagEnabled(KEY_ENABLE_CAMERA_COMPAT_TREATMENT)
                    && (!checkDeviceConfig
                    || mDeviceConfig.getFlagValue(KEY_ENABLE_CAMERA_COMPAT_TREATMENT));
    boolean isCameraCompatTreatmentEnabled() {
        return mDeviceConfig.getFlagValue(KEY_ENABLE_CAMERA_COMPAT_TREATMENT);
    }

    /**
     * @return Whether camera compatibility treatment is enabled at build time. This is used when
     * we need to safely initialize a component before the {@link DeviceConfig} flag value is
     * available.
     */
    boolean isCameraCompatTreatmentEnabledAtBuildTime() {
        return mDeviceConfig.isBuildTimeFlagEnabled(KEY_ENABLE_CAMERA_COMPAT_TREATMENT);
    }

    /** Whether camera compatibility refresh is enabled. */
@@ -1179,20 +1183,28 @@ final class LetterboxConfiguration {

    /**
     * Checks whether rotation compat policy for immersive apps that prevents auto rotation
     * into non-optimal screen orientation while in fullscreen is enabled.
     * into non-optimal screen orientation while in fullscreen is enabled at build time. This is
     * used when we need to safely initialize a component before the {@link DeviceConfig} flag
     * value is available.
     *
     * <p>This is needed because immersive apps, such as games, are often not optimized for all
     * orientations and can have a poor UX when rotated. Additionally, some games rely on sensors
     * for the gameplay so users can trigger such rotations accidentally when auto rotation is on.
     *
     * @param checkDeviceConfig whether it should check both build time flag and a dynamic property
     *        from {@link DeviceConfig} or only build time flag value.
     */
    boolean isDisplayRotationImmersiveAppCompatPolicyEnabled(final boolean checkDeviceConfig) {
    boolean isDisplayRotationImmersiveAppCompatPolicyEnabledAtBuildTime() {
        return mDeviceConfig.isBuildTimeFlagEnabled(
                    KEY_ENABLE_DISPLAY_ROTATION_IMMERSIVE_APP_COMPAT_POLICY) && (!checkDeviceConfig
                    || mDeviceConfig.getFlagValue(
                    KEY_ENABLE_DISPLAY_ROTATION_IMMERSIVE_APP_COMPAT_POLICY));
                KEY_ENABLE_DISPLAY_ROTATION_IMMERSIVE_APP_COMPAT_POLICY);
    }

    /**
     * Checks whether rotation compat policy for immersive apps that prevents auto rotation
     * into non-optimal screen orientation while in fullscreen is currently enabled.
     *
     * <p>This is needed because immersive apps, such as games, are often not optimized for all
     * orientations and can have a poor UX when rotated. Additionally, some games rely on sensors
     * for the gameplay so users can trigger such rotations accidentally when auto rotation is on.
     */
    boolean isDisplayRotationImmersiveAppCompatPolicyEnabled() {
        return mDeviceConfig.getFlagValue(KEY_ENABLE_DISPLAY_ROTATION_IMMERSIVE_APP_COMPAT_POLICY);
    }
}
+6 −9
Original line number Diff line number Diff line
@@ -294,18 +294,15 @@ final class LetterboxUiController {
                        PROPERTY_COMPAT_ENABLE_FAKE_FOCUS);
        mBooleanPropertyCameraCompatAllowForceRotation =
                readComponentProperty(packageManager, mActivityRecord.packageName,
                        () -> mLetterboxConfiguration.isCameraCompatTreatmentEnabled(
                                /* checkDeviceConfig */ true),
                        () -> mLetterboxConfiguration.isCameraCompatTreatmentEnabled(),
                        PROPERTY_CAMERA_COMPAT_ALLOW_FORCE_ROTATION);
        mBooleanPropertyCameraCompatAllowRefresh =
                readComponentProperty(packageManager, mActivityRecord.packageName,
                        () -> mLetterboxConfiguration.isCameraCompatTreatmentEnabled(
                                /* checkDeviceConfig */ true),
                        () -> mLetterboxConfiguration.isCameraCompatTreatmentEnabled(),
                        PROPERTY_CAMERA_COMPAT_ALLOW_REFRESH);
        mBooleanPropertyCameraCompatEnableRefreshViaPause =
                readComponentProperty(packageManager, mActivityRecord.packageName,
                        () -> mLetterboxConfiguration.isCameraCompatTreatmentEnabled(
                                /* checkDeviceConfig */ true),
                        () -> mLetterboxConfiguration.isCameraCompatTreatmentEnabled(),
                        PROPERTY_CAMERA_COMPAT_ENABLE_REFRESH_VIA_PAUSE);

        mBooleanPropertyAllowOrientationOverride =
@@ -697,7 +694,7 @@ final class LetterboxUiController {
    boolean shouldRefreshActivityForCameraCompat() {
        return shouldEnableWithOptOutOverrideAndProperty(
                /* gatingCondition */ () -> mLetterboxConfiguration
                        .isCameraCompatTreatmentEnabled(/* checkDeviceConfig */ true),
                        .isCameraCompatTreatmentEnabled(),
                mIsOverrideCameraCompatDisableRefreshEnabled,
                mBooleanPropertyCameraCompatAllowRefresh);
    }
@@ -719,7 +716,7 @@ final class LetterboxUiController {
    boolean shouldRefreshActivityViaPauseForCameraCompat() {
        return shouldEnableWithOverrideAndProperty(
                /* gatingCondition */ () -> mLetterboxConfiguration
                        .isCameraCompatTreatmentEnabled(/* checkDeviceConfig */ true),
                        .isCameraCompatTreatmentEnabled(),
                mIsOverrideCameraCompatEnableRefreshViaPauseEnabled,
                mBooleanPropertyCameraCompatEnableRefreshViaPause);
    }
@@ -738,7 +735,7 @@ final class LetterboxUiController {
    boolean shouldForceRotateForCameraCompat() {
        return shouldEnableWithOptOutOverrideAndProperty(
                /* gatingCondition */ () -> mLetterboxConfiguration
                        .isCameraCompatTreatmentEnabled(/* checkDeviceConfig */ true),
                        .isCameraCompatTreatmentEnabled(),
                mIsOverrideCameraCompatDisableForceRotationEnabled,
                mBooleanPropertyCameraCompatAllowForceRotation);
    }
Loading