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

Commit 9c84b517 authored by Massimo Carli's avatar Massimo Carli Committed by Android (Google) Code Review
Browse files

Merge "Enable blur letterbox wallpaper behind flags" into udc-qpr-dev

parents 54d58e5a 4d22091d
Loading
Loading
Loading
Loading
+0 −19
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
  ~ Copyright (C) 2022 The Android Open Source Project
  ~
  ~ Licensed under the Apache License, Version 2.0 (the "License");
  ~ you may not use this file except in compliance with the License.
  ~ You may obtain a copy of the License at
  ~
  ~      http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing, software
  ~ distributed under the License is distributed on an "AS IS" BASIS,
  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  ~ See the License for the specific language governing permissions and
  ~ limitations under the License.
  -->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:color="@color/system_neutral1_500" android:lStar="5" />
</selector>
+3 −3
Original line number Diff line number Diff line
@@ -5574,13 +5574,13 @@

    <!-- Blur radius for the Option 3 in R.integer.config_letterboxBackgroundType. Values < 0 are
        ignored and 0 is used. -->
    <dimen name="config_letterboxBackgroundWallpaperBlurRadius">31dp</dimen>
    <dimen name="config_letterboxBackgroundWallpaperBlurRadius">24dp</dimen>

    <!-- Alpha of a black translucent scrim showed over wallpaper letterbox background when
        the Option 3 is selected for R.integer.config_letterboxBackgroundType.
        Values < 0 or >= 1 are ignored and 0.0 (transparent) is used instead. -->
    <item name="config_letterboxBackgroundWallaperDarkScrimAlpha" format="float" type="dimen">
        0.5
        0.68
    </item>

    <!-- Corners appearance of the letterbox background.
@@ -5605,7 +5605,7 @@
            but isn't supported on the device or both dark scrim alpha and blur radius aren't
            provided.
     -->
    <color name="config_letterboxBackgroundColor">@color/letterbox_background</color>
    <color name="config_letterboxBackgroundColor">@color/system_on_secondary_fixed</color>

    <!-- Horizontal position of a center of the letterboxed app window.
        0 corresponds to the left side of the screen and 1 to the right side. If given value < 0
+65 −30
Original line number Diff line number Diff line
@@ -85,6 +85,13 @@ final class LetterboxConfiguration {
    // TODO(b/288142656): Enable user aspect ratio settings by default.
    private static final boolean DEFAULT_VALUE_ENABLE_USER_ASPECT_RATIO_SETTINGS = false;

    // Whether the letterbox wallpaper style is enabled by default
    private static final String KEY_ENABLE_LETTERBOX_BACKGROUND_WALLPAPER =
            "enable_letterbox_background_wallpaper";

    // TODO(b/290048978): Enable wallpaper as default letterbox background.
    private static final boolean DEFAULT_VALUE_ENABLE_LETTERBOX_BACKGROUND_WALLPAPER = false;

    /**
     * Override of aspect ratio for fixed orientation letterboxing that is set via ADB with
     * set-fixed-orientation-letterbox-aspect-ratio or via {@link
@@ -101,9 +108,16 @@ final class LetterboxConfiguration {

    /** Enum for Letterbox background type. */
    @Retention(RetentionPolicy.SOURCE)
    @IntDef({LETTERBOX_BACKGROUND_SOLID_COLOR, LETTERBOX_BACKGROUND_APP_COLOR_BACKGROUND,
            LETTERBOX_BACKGROUND_APP_COLOR_BACKGROUND_FLOATING, LETTERBOX_BACKGROUND_WALLPAPER})
    @IntDef({LETTERBOX_BACKGROUND_OVERRIDE_UNSET,
            LETTERBOX_BACKGROUND_SOLID_COLOR,
            LETTERBOX_BACKGROUND_APP_COLOR_BACKGROUND,
            LETTERBOX_BACKGROUND_APP_COLOR_BACKGROUND_FLOATING,
            LETTERBOX_BACKGROUND_WALLPAPER})
    @interface LetterboxBackgroundType {};

    /** No letterbox background style set. Using the one defined by DeviceConfig. */
    static final int LETTERBOX_BACKGROUND_OVERRIDE_UNSET = -1;

    /** Solid background using color specified in R.color.config_letterboxBackgroundColor. */
    static final int LETTERBOX_BACKGROUND_SOLID_COLOR = 0;

@@ -183,14 +197,14 @@ final class LetterboxConfiguration {
    @Nullable private Integer mLetterboxBackgroundColorResourceIdOverride;

    @LetterboxBackgroundType
    private int mLetterboxBackgroundType;
    private final int mLetterboxBackgroundType;

    // Blur radius for LETTERBOX_BACKGROUND_WALLPAPER option in mLetterboxBackgroundType.
    // Blur radius for LETTERBOX_BACKGROUND_WALLPAPER option from getLetterboxBackgroundType().
    // Values <= 0 are ignored and 0 is used instead.
    private int mLetterboxBackgroundWallpaperBlurRadius;
    private int mLetterboxBackgroundWallpaperBlurRadiusPx;

    // Alpha of a black scrim shown over wallpaper letterbox background when
    // LETTERBOX_BACKGROUND_WALLPAPER option is selected for mLetterboxBackgroundType.
    // LETTERBOX_BACKGROUND_WALLPAPER option is returned from getLetterboxBackgroundType().
    // Values < 0 or >= 1 are ignored and 0.0 (transparent) is used instead.
    private float mLetterboxBackgroundWallpaperDarkScrimAlpha;

@@ -252,6 +266,11 @@ final class LetterboxConfiguration {
    // Allows to enable user aspect ratio settings ignoring flags.
    private boolean mUserAppAspectRatioSettingsOverrideEnabled;

    // The override for letterbox background type in case it's different from
    // LETTERBOX_BACKGROUND_OVERRIDE_UNSET
    @LetterboxBackgroundType
    private int mLetterboxBackgroundTypeOverride = LETTERBOX_BACKGROUND_OVERRIDE_UNSET;

    // Whether we should use split screen aspect ratio for the activity when camera compat treatment
    // is enabled and activity is connected to the camera in fullscreen.
    private final boolean mIsCameraCompatSplitScreenAspectRatioEnabled;
@@ -294,10 +313,10 @@ final class LetterboxConfiguration {

        mFixedOrientationLetterboxAspectRatio = mContext.getResources().getFloat(
                R.dimen.config_fixedOrientationLetterboxAspectRatio);
        mLetterboxBackgroundType = readLetterboxBackgroundTypeFromConfig(mContext);
        mLetterboxActivityCornersRadius = mContext.getResources().getInteger(
                R.integer.config_letterboxActivityCornersRadius);
        mLetterboxBackgroundType = readLetterboxBackgroundTypeFromConfig(mContext);
        mLetterboxBackgroundWallpaperBlurRadius = mContext.getResources().getDimensionPixelSize(
        mLetterboxBackgroundWallpaperBlurRadiusPx = mContext.getResources().getDimensionPixelSize(
                R.dimen.config_letterboxBackgroundWallpaperBlurRadius);
        mLetterboxBackgroundWallpaperDarkScrimAlpha = mContext.getResources().getFloat(
                R.dimen.config_letterboxBackgroundWallaperDarkScrimAlpha);
@@ -359,6 +378,8 @@ final class LetterboxConfiguration {
                        DEFAULT_VALUE_ENABLE_USER_ASPECT_RATIO_SETTINGS,
                        mContext.getResources().getBoolean(
                                R.bool.config_appCompatUserAppAspectRatioSettingsIsEnabled))
                .addDeviceConfigEntry(KEY_ENABLE_LETTERBOX_BACKGROUND_WALLPAPER,
                        DEFAULT_VALUE_ENABLE_LETTERBOX_BACKGROUND_WALLPAPER, /* enabled */ true)
                .build();
    }

@@ -497,25 +518,39 @@ final class LetterboxConfiguration {
    }

    /**
     * Gets {@link LetterboxBackgroundType} specified in {@link
     * com.android.internal.R.integer.config_letterboxBackgroundType} or over via ADB command.
     * Gets {@link LetterboxBackgroundType} specified via ADB command or the default one.
     */
    @LetterboxBackgroundType
    int getLetterboxBackgroundType() {
        return mLetterboxBackgroundType;
        return mLetterboxBackgroundTypeOverride != LETTERBOX_BACKGROUND_OVERRIDE_UNSET
                ? mLetterboxBackgroundTypeOverride
                : getDefaultLetterboxBackgroundType();
    }

    /** Sets letterbox background type. */
    void setLetterboxBackgroundType(@LetterboxBackgroundType int backgroundType) {
        mLetterboxBackgroundType = backgroundType;
    /** Overrides the letterbox background type. */
    void setLetterboxBackgroundTypeOverride(@LetterboxBackgroundType int backgroundType) {
        mLetterboxBackgroundTypeOverride = backgroundType;
    }

    /**
     * Resets cletterbox background type to {@link
     * com.android.internal.R.integer.config_letterboxBackgroundType}.
     * Resets letterbox background type value depending on the
     * {@link #KEY_ENABLE_LETTERBOX_BACKGROUND_WALLPAPER} built time and runtime flags.
     *
     * <p>If enabled, the letterbox background type value is set toZ
     * {@link #LETTERBOX_BACKGROUND_WALLPAPER}. When disabled the letterbox background type value
     * comes from {@link R.integer.config_letterboxBackgroundType}.
     */
    void resetLetterboxBackgroundType() {
        mLetterboxBackgroundType = readLetterboxBackgroundTypeFromConfig(mContext);
        mLetterboxBackgroundTypeOverride = LETTERBOX_BACKGROUND_OVERRIDE_UNSET;
    }

    // Returns KEY_ENABLE_LETTERBOX_BACKGROUND_WALLPAPER if the DeviceConfig flag is enabled
    // or the value in com.android.internal.R.integer.config_letterboxBackgroundType if the flag
    // is disabled.
    @LetterboxBackgroundType
    private int getDefaultLetterboxBackgroundType() {
        return mDeviceConfig.getFlagValue(KEY_ENABLE_LETTERBOX_BACKGROUND_WALLPAPER)
                ? LETTERBOX_BACKGROUND_WALLPAPER : mLetterboxBackgroundType;
    }

    /** Returns a string representing the given {@link LetterboxBackgroundType}. */
@@ -548,7 +583,7 @@ final class LetterboxConfiguration {

    /**
     * Overrides alpha of a black scrim shown over wallpaper for {@link
     * #LETTERBOX_BACKGROUND_WALLPAPER} option in {@link mLetterboxBackgroundType}.
     * #LETTERBOX_BACKGROUND_WALLPAPER} option returned from {@link getLetterboxBackgroundType()}.
     *
     * <p>If given value is < 0 or >= 1, both it and a value of {@link
     * com.android.internal.R.dimen.config_letterboxBackgroundWallaperDarkScrimAlpha} are ignored
@@ -575,33 +610,33 @@ final class LetterboxConfiguration {
    }

    /**
     * Overrides blur radius for {@link #LETTERBOX_BACKGROUND_WALLPAPER} option in
     * {@link mLetterboxBackgroundType}.
     * Overrides blur radius for {@link #LETTERBOX_BACKGROUND_WALLPAPER} option from
     * {@link getLetterboxBackgroundType()}.
     *
     * <p> If given value <= 0, both it and a value of {@link
     * com.android.internal.R.dimen.config_letterboxBackgroundWallpaperBlurRadius} are ignored
     * and 0 is used instead.
     */
    void setLetterboxBackgroundWallpaperBlurRadius(int radius) {
        mLetterboxBackgroundWallpaperBlurRadius = radius;
    void setLetterboxBackgroundWallpaperBlurRadiusPx(int radius) {
        mLetterboxBackgroundWallpaperBlurRadiusPx = radius;
    }

    /**
     * Resets blur raidus for {@link #LETTERBOX_BACKGROUND_WALLPAPER} option in {@link
     * mLetterboxBackgroundType} to {@link
     * Resets blur raidus for {@link #LETTERBOX_BACKGROUND_WALLPAPER} option returned by {@link
     * getLetterboxBackgroundType()} to {@link
     * com.android.internal.R.dimen.config_letterboxBackgroundWallpaperBlurRadius}.
     */
    void resetLetterboxBackgroundWallpaperBlurRadius() {
        mLetterboxBackgroundWallpaperBlurRadius = mContext.getResources().getDimensionPixelSize(
    void resetLetterboxBackgroundWallpaperBlurRadiusPx() {
        mLetterboxBackgroundWallpaperBlurRadiusPx = mContext.getResources().getDimensionPixelSize(
                com.android.internal.R.dimen.config_letterboxBackgroundWallpaperBlurRadius);
    }

    /**
     * Gets blur raidus for {@link #LETTERBOX_BACKGROUND_WALLPAPER} option in {@link
     * mLetterboxBackgroundType}.
     * Gets blur raidus for {@link #LETTERBOX_BACKGROUND_WALLPAPER} option returned by {@link
     * getLetterboxBackgroundType()}.
     */
    int getLetterboxBackgroundWallpaperBlurRadius() {
        return mLetterboxBackgroundWallpaperBlurRadius;
    int getLetterboxBackgroundWallpaperBlurRadiusPx() {
        return mLetterboxBackgroundWallpaperBlurRadiusPx;
    }

    /*
+8 −8
Original line number Diff line number Diff line
@@ -894,7 +894,7 @@ final class LetterboxUiController {
                        this::shouldLetterboxHaveRoundedCorners,
                        this::getLetterboxBackgroundColor,
                        this::hasWallpaperBackgroundForLetterbox,
                        this::getLetterboxWallpaperBlurRadius,
                        this::getLetterboxWallpaperBlurRadiusPx,
                        this::getLetterboxWallpaperDarkScrimAlpha,
                        this::handleHorizontalDoubleTap,
                        this::handleVerticalDoubleTap,
@@ -1315,7 +1315,7 @@ final class LetterboxUiController {
            case LETTERBOX_BACKGROUND_WALLPAPER:
                if (hasWallpaperBackgroundForLetterbox()) {
                    // Color is used for translucent scrim that dims wallpaper.
                    return Color.valueOf(Color.BLACK);
                    return mLetterboxConfiguration.getLetterboxBackgroundColor();
                }
                Slog.w(TAG, "Wallpaper option is selected for letterbox background but "
                        + "blur is not supported by a device or not supported in the current "
@@ -1472,10 +1472,10 @@ final class LetterboxUiController {
                        // Don't use wallpaper as a background if letterboxed for display cutout.
                        && isLetterboxedNotForDisplayCutout(mainWindow)
                        // Check that dark scrim alpha or blur radius are provided
                        && (getLetterboxWallpaperBlurRadius() > 0
                        && (getLetterboxWallpaperBlurRadiusPx() > 0
                                || getLetterboxWallpaperDarkScrimAlpha() > 0)
                        // Check that blur is supported by a device if blur radius is provided.
                        && (getLetterboxWallpaperBlurRadius() <= 0
                        && (getLetterboxWallpaperBlurRadiusPx() <= 0
                                || isLetterboxWallpaperBlurSupported());
        if (mShowWallpaperForLetterboxBackground != wallpaperShouldBeShown) {
            mShowWallpaperForLetterboxBackground = wallpaperShouldBeShown;
@@ -1483,9 +1483,9 @@ final class LetterboxUiController {
        }
    }

    private int getLetterboxWallpaperBlurRadius() {
        int blurRadius = mLetterboxConfiguration.getLetterboxBackgroundWallpaperBlurRadius();
        return blurRadius < 0 ? 0 : blurRadius;
    private int getLetterboxWallpaperBlurRadiusPx() {
        int blurRadius = mLetterboxConfiguration.getLetterboxBackgroundWallpaperBlurRadiusPx();
        return Math.max(blurRadius, 0);
    }

    private float getLetterboxWallpaperDarkScrimAlpha() {
@@ -1535,7 +1535,7 @@ final class LetterboxUiController {
            pw.println(prefix + "  letterboxBackgroundWallpaperDarkScrimAlpha="
                    + getLetterboxWallpaperDarkScrimAlpha());
            pw.println(prefix + "  letterboxBackgroundWallpaperBlurRadius="
                    + getLetterboxWallpaperBlurRadius());
                    + getLetterboxWallpaperBlurRadiusPx());
        }

        pw.println(prefix + "  isHorizontalReachabilityEnabled="
+10 −7
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ import android.os.UserHandle;
import android.provider.Settings;
import android.util.DisplayMetrics;
import android.util.Pair;
import android.util.TypedValue;
import android.view.Display;
import android.view.IWindow;
import android.view.IWindowManager;
@@ -728,7 +729,7 @@ public class WindowManagerShellCommand extends ShellCommand {
            return -1;
        }
        synchronized (mInternal.mGlobalLock) {
            mLetterboxConfiguration.setLetterboxBackgroundType(backgroundType);
            mLetterboxConfiguration.setLetterboxBackgroundTypeOverride(backgroundType);
        }
        return 0;
    }
@@ -770,10 +771,10 @@ public class WindowManagerShellCommand extends ShellCommand {

    private int runSetLetterboxBackgroundWallpaperBlurRadius(PrintWriter pw)
            throws RemoteException {
        final int radius;
        final int radiusDp;
        try {
            String arg = getNextArgRequired();
            radius = Integer.parseInt(arg);
            radiusDp = Integer.parseInt(arg);
        } catch (NumberFormatException  e) {
            getErrPrintWriter().println("Error: blur radius format " + e);
            return -1;
@@ -783,7 +784,9 @@ public class WindowManagerShellCommand extends ShellCommand {
            return -1;
        }
        synchronized (mInternal.mGlobalLock) {
            mLetterboxConfiguration.setLetterboxBackgroundWallpaperBlurRadius(radius);
            final int radiusPx = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
                    radiusDp, mInternal.mContext.getResources().getDisplayMetrics());
            mLetterboxConfiguration.setLetterboxBackgroundWallpaperBlurRadiusPx(radiusPx);
        }
        return 0;
    }
@@ -1050,7 +1053,7 @@ public class WindowManagerShellCommand extends ShellCommand {
                        mLetterboxConfiguration.resetLetterboxBackgroundColor();
                        break;
                    case "wallpaperBlurRadius":
                        mLetterboxConfiguration.resetLetterboxBackgroundWallpaperBlurRadius();
                        mLetterboxConfiguration.resetLetterboxBackgroundWallpaperBlurRadiusPx();
                        break;
                    case "wallpaperDarkScrimAlpha":
                        mLetterboxConfiguration.resetLetterboxBackgroundWallpaperDarkScrimAlpha();
@@ -1188,7 +1191,7 @@ public class WindowManagerShellCommand extends ShellCommand {
            mLetterboxConfiguration.resetLetterboxActivityCornersRadius();
            mLetterboxConfiguration.resetLetterboxBackgroundType();
            mLetterboxConfiguration.resetLetterboxBackgroundColor();
            mLetterboxConfiguration.resetLetterboxBackgroundWallpaperBlurRadius();
            mLetterboxConfiguration.resetLetterboxBackgroundWallpaperBlurRadiusPx();
            mLetterboxConfiguration.resetLetterboxBackgroundWallpaperDarkScrimAlpha();
            mLetterboxConfiguration.resetLetterboxHorizontalPositionMultiplier();
            mLetterboxConfiguration.resetIsHorizontalReachabilityEnabled();
@@ -1262,7 +1265,7 @@ public class WindowManagerShellCommand extends ShellCommand {
            pw.println("    Background color: " + Integer.toHexString(
                    mLetterboxConfiguration.getLetterboxBackgroundColor().toArgb()));
            pw.println("    Wallpaper blur radius: "
                    + mLetterboxConfiguration.getLetterboxBackgroundWallpaperBlurRadius());
                    + mLetterboxConfiguration.getLetterboxBackgroundWallpaperBlurRadiusPx());
            pw.println("    Wallpaper dark scrim alpha: "
                    + mLetterboxConfiguration.getLetterboxBackgroundWallpaperDarkScrimAlpha());
            pw.println("Is letterboxing for translucent activities enabled: "
Loading