From 98b78583300ccdb29123404ae8bc80685b45f5d7 Mon Sep 17 00:00:00 2001 From: Galia Peycheva Date: Wed, 3 Feb 2021 15:09:54 +0100 Subject: [PATCH] Make window blur behind public API This CL makes the blur behind functionality a public API. As part of this change, we change its previous name (windowBackgroundBlurRadius) to windowBlurBehindRadius. This avoids a name clash with the Window background blur, which only blurs the area of the window. Blur behind blurs everything behind the window (similar behaviour to the dim). This CL exposes WM.LP.blurBehindRadius and, in addition, undeprecates an old flag - FLAG_BLUR_BEHIND. FLAG_BLUR_BEHIND enables the blur behind and blurBehindRadius specifies how dense the blur will be. In addition, we expose two xml attributes on the Window - windowBlurBehindEnable and windowBlurBehindRadius. The usage is similar to the dim api. Bug: 167166562 Bug: 177524486 Test: m && test app Change-Id: If2fcde644c5bcca112495ca99ee66bae909877db --- core/api/current.txt | 21 ++++++++------ core/java/android/view/WindowManager.java | 29 ++++++++++--------- .../android/internal/policy/PhoneWindow.java | 11 +++++-- core/res/res/values/attrs.xml | 14 ++++++--- core/res/res/values/public.xml | 4 +-- .../com/android/server/wm/WindowState.java | 7 +++-- 6 files changed, 54 insertions(+), 32 deletions(-) diff --git a/core/api/current.txt b/core/api/current.txt index a7521227c39e7..a803e880109a2 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -572,7 +572,7 @@ package android { field public static final int dropDownWidth = 16843362; // 0x1010262 field public static final int duplicateParentState = 16842985; // 0x10100e9 field public static final int duration = 16843160; // 0x1010198 - field public static final int edgeEffectType = 16844322; // 0x1010622 + field public static final int edgeEffectType = 16844323; // 0x1010623 field public static final int editTextBackground = 16843602; // 0x1010352 field public static final int editTextColor = 16843601; // 0x1010351 field public static final int editTextPreferenceStyle = 16842898; // 0x1010092 @@ -658,7 +658,7 @@ package android { field @Deprecated public static final int fontProviderCerts = 16844125; // 0x101055d field @Deprecated public static final int fontProviderPackage = 16844119; // 0x1010557 field @Deprecated public static final int fontProviderQuery = 16844113; // 0x1010551 - field public static final int fontProviderSystemFontFamily = 16844321; // 0x1010621 + field public static final int fontProviderSystemFontFamily = 16844322; // 0x1010622 field public static final int fontStyle = 16844095; // 0x101053f field public static final int fontVariationSettings = 16844144; // 0x1010570 field public static final int fontWeight = 16844083; // 0x1010533 @@ -723,7 +723,7 @@ package android { field public static final int gwpAsanMode = 16844310; // 0x1010616 field public static final int hand_hour = 16843011; // 0x1010103 field public static final int hand_minute = 16843012; // 0x1010104 - field public static final int hand_second = 16844323; // 0x1010623 + field public static final int hand_second = 16844324; // 0x1010624 field public static final int handle = 16843354; // 0x101025a field public static final int handleProfiling = 16842786; // 0x1010022 field public static final int hapticFeedbackEnabled = 16843358; // 0x101025e @@ -1058,11 +1058,11 @@ package android { field public static final int parentActivityName = 16843687; // 0x10103a7 field @Deprecated public static final int password = 16843100; // 0x101015c field public static final int path = 16842794; // 0x101002a - field public static final int pathAdvancedPattern = 16844319; // 0x101061f + field public static final int pathAdvancedPattern = 16844320; // 0x1010620 field public static final int pathData = 16843781; // 0x1010405 field public static final int pathPattern = 16842796; // 0x101002c field public static final int pathPrefix = 16842795; // 0x101002b - field public static final int pathSuffix = 16844317; // 0x101061d + field public static final int pathSuffix = 16844318; // 0x101061e field public static final int patternPathData = 16843978; // 0x10104ca field public static final int permission = 16842758; // 0x1010006 field public static final int permissionFlags = 16843719; // 0x10103c7 @@ -1155,7 +1155,7 @@ package android { field public static final int reqNavigation = 16843306; // 0x101022a field public static final int reqTouchScreen = 16843303; // 0x1010227 field public static final int requestLegacyExternalStorage = 16844291; // 0x1010603 - field public static final int requireDeviceScreenOn = 16844316; // 0x101061c + field public static final int requireDeviceScreenOn = 16844317; // 0x101061d field public static final int requireDeviceUnlock = 16843756; // 0x10103ec field public static final int required = 16843406; // 0x101028e field public static final int requiredAccountType = 16843734; // 0x10103d6 @@ -1296,10 +1296,10 @@ package android { field public static final int spotShadowAlpha = 16843967; // 0x10104bf field public static final int src = 16843033; // 0x1010119 field public static final int ssp = 16843747; // 0x10103e3 - field public static final int sspAdvancedPattern = 16844320; // 0x1010620 + field public static final int sspAdvancedPattern = 16844321; // 0x1010621 field public static final int sspPattern = 16843749; // 0x10103e5 field public static final int sspPrefix = 16843748; // 0x10103e4 - field public static final int sspSuffix = 16844318; // 0x101061e + field public static final int sspSuffix = 16844319; // 0x101061f field public static final int stackFromBottom = 16843005; // 0x10100fd field public static final int stackViewStyle = 16843838; // 0x101043e field public static final int starStyle = 16842882; // 0x1010082 @@ -1610,6 +1610,8 @@ package android { field public static final int windowAnimationStyle = 16842926; // 0x10100ae field public static final int windowBackground = 16842836; // 0x1010054 field public static final int windowBackgroundFallback = 16844035; // 0x1010503 + field public static final int windowBlurBehindEnabled = 16844316; // 0x101061c + field public static final int windowBlurBehindRadius = 16844315; // 0x101061b field public static final int windowClipToOutline = 16843947; // 0x10104ab field public static final int windowCloseOnTouchOutside = 16843611; // 0x101035b field public static final int windowContentOverlay = 16842841; // 0x1010059 @@ -49617,7 +49619,7 @@ package android.view { field public static final int FLAGS_CHANGED = 4; // 0x4 field public static final int FLAG_ALLOW_LOCK_WHILE_SCREEN_ON = 1; // 0x1 field public static final int FLAG_ALT_FOCUSABLE_IM = 131072; // 0x20000 - field @Deprecated public static final int FLAG_BLUR_BEHIND = 4; // 0x4 + field public static final int FLAG_BLUR_BEHIND = 4; // 0x4 field public static final int FLAG_DIM_BEHIND = 2; // 0x2 field @Deprecated public static final int FLAG_DISMISS_KEYGUARD = 4194304; // 0x400000 field @Deprecated public static final int FLAG_DITHER = 4096; // 0x1000 @@ -49708,6 +49710,7 @@ package android.view { field @Deprecated public static final int TYPE_TOAST = 2005; // 0x7d5 field public static final int TYPE_WALLPAPER = 2013; // 0x7dd field public float alpha; + field public int blurBehindRadius; field public float buttonBrightness; field public float dimAmount; field public int flags; diff --git a/core/java/android/view/WindowManager.java b/core/java/android/view/WindowManager.java index 63f1eedf1c500..9e87c95a8a75a 100644 --- a/core/java/android/view/WindowManager.java +++ b/core/java/android/view/WindowManager.java @@ -1511,9 +1511,7 @@ public interface WindowManager extends ViewManager { * Use {@link #dimAmount} to control the amount of dim. */ public static final int FLAG_DIM_BEHIND = 0x00000002; - /** Window flag: blur everything behind this window. - * @deprecated Blurring is no longer supported. */ - @Deprecated + /** Window flag: enable blur behind for this window. */ public static final int FLAG_BLUR_BEHIND = 0x00000004; /** Window flag: this window won't ever get key input focus, so the @@ -3233,11 +3231,16 @@ public interface WindowManager extends ViewManager { public boolean preferMinimalPostProcessing = false; /** - * Indicates that this window wants to have blurred content behind it. + * Specifies the amount of blur to be used to blur everything behind the window. + * The effect is similar to the dimAmount, but instead of dimming, the content behind + * will be blurred. * - * @hide + * The blur behind radius range starts at 0, which means no blur, and increases until 150 + * for the densest blur. + * + * @see #FLAG_BLUR_BEHIND */ - public int backgroundBlurRadius = 0; + public int blurBehindRadius = 0; /** * The color mode requested by this window. The target display may @@ -3626,7 +3629,7 @@ public interface WindowManager extends ViewManager { out.writeInt(mFitInsetsSides); out.writeBoolean(mFitInsetsIgnoringVisibility); out.writeBoolean(preferMinimalPostProcessing); - out.writeInt(backgroundBlurRadius); + out.writeInt(blurBehindRadius); if (providesInsetsTypes != null) { out.writeInt(providesInsetsTypes.length); out.writeIntArray(providesInsetsTypes); @@ -3695,7 +3698,7 @@ public interface WindowManager extends ViewManager { mFitInsetsSides = in.readInt(); mFitInsetsIgnoringVisibility = in.readBoolean(); preferMinimalPostProcessing = in.readBoolean(); - backgroundBlurRadius = in.readInt(); + blurBehindRadius = in.readInt(); int insetsTypesLength = in.readInt(); if (insetsTypesLength > 0) { providesInsetsTypes = new int[insetsTypesLength]; @@ -3940,8 +3943,8 @@ public interface WindowManager extends ViewManager { changes |= MINIMAL_POST_PROCESSING_PREFERENCE_CHANGED; } - if (backgroundBlurRadius != o.backgroundBlurRadius) { - backgroundBlurRadius = o.backgroundBlurRadius; + if (blurBehindRadius != o.blurBehindRadius) { + blurBehindRadius = o.blurBehindRadius; changes |= BACKGROUND_BLUR_RADIUS_CHANGED; } @@ -4108,9 +4111,9 @@ public interface WindowManager extends ViewManager { sb.append(" preferMinimalPostProcessing="); sb.append(preferMinimalPostProcessing); } - if (backgroundBlurRadius != 0) { - sb.append(" backgroundBlurRadius="); - sb.append(backgroundBlurRadius); + if (blurBehindRadius != 0) { + sb.append(" blurBehindRadius="); + sb.append(blurBehindRadius); } sb.append(System.lineSeparator()); sb.append(prefix).append(" fl=").append( diff --git a/core/java/com/android/internal/policy/PhoneWindow.java b/core/java/com/android/internal/policy/PhoneWindow.java index 141dc79f4c932..5df175e8aee5e 100644 --- a/core/java/com/android/internal/policy/PhoneWindow.java +++ b/core/java/com/android/internal/policy/PhoneWindow.java @@ -2540,8 +2540,15 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback { } } - params.backgroundBlurRadius = a.getDimensionPixelSize( - R.styleable.Window_windowBackgroundBlurRadius, 0); + if (a.getBoolean(R.styleable.Window_windowBlurBehindEnabled, false)) { + if ((getForcedWindowFlags() & WindowManager.LayoutParams.FLAG_BLUR_BEHIND) == 0) { + params.flags |= WindowManager.LayoutParams.FLAG_BLUR_BEHIND; + } + + params.blurBehindRadius = a.getDimensionPixelSize( + android.R.styleable.Window_windowBlurBehindRadius, 0); + } + if (params.windowAnimations == 0) { params.windowAnimations = a.getResourceId( diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml index 13539e9306f97..1435d3e153942 100644 --- a/core/res/res/values/attrs.xml +++ b/core/res/res/values/attrs.xml @@ -87,6 +87,14 @@ theme does not set this value, meaning it is based on whether the window is floating. --> + + + + + + @@ -1973,6 +1981,8 @@ + + @@ -2190,10 +2200,6 @@ the decor view. --> - - - - - + + diff --git a/services/core/java/com/android/server/wm/WindowState.java b/services/core/java/com/android/server/wm/WindowState.java index c6985915de688..661118ff1990b 100644 --- a/services/core/java/com/android/server/wm/WindowState.java +++ b/services/core/java/com/android/server/wm/WindowState.java @@ -45,6 +45,7 @@ import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW; import static android.view.WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW; import static android.view.WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON; import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM; +import static android.view.WindowManager.LayoutParams.FLAG_BLUR_BEHIND; import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND; import static android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD; import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS; @@ -5269,7 +5270,7 @@ class WindowState extends WindowContainer implements WindowManagerP if (!mAnimatingExit && mAppDied) { mIsDimming = true; getDimmer().dimAbove(getSyncTransaction(), this, DEFAULT_DIM_AMOUNT_DEAD_WINDOW); - } else if (((mAttrs.flags & FLAG_DIM_BEHIND) != 0 || mAttrs.backgroundBlurRadius != 0) + } else if (((mAttrs.flags & FLAG_DIM_BEHIND) != 0 || (mAttrs.flags & FLAG_BLUR_BEHIND) != 0) && isVisibleNow() && !mHidden) { // Only show the Dimmer when the following is satisfied: // 1. The window has the flag FLAG_DIM_BEHIND or background blur is requested @@ -5278,8 +5279,10 @@ class WindowState extends WindowContainer implements WindowManagerP // 4. The WS is not hidden. mIsDimming = true; final float dimAmount = (mAttrs.flags & FLAG_DIM_BEHIND) != 0 ? mAttrs.dimAmount : 0; + final int blurRadius = + (mAttrs.flags & FLAG_BLUR_BEHIND) != 0 ? mAttrs.blurBehindRadius : 0; getDimmer().dimBelow( - getSyncTransaction(), this, mAttrs.dimAmount, mAttrs.backgroundBlurRadius); + getSyncTransaction(), this, mAttrs.dimAmount, mAttrs.blurBehindRadius); } }