From f83b52cc13a1d36953f2ae37081fc3c866008090 Mon Sep 17 00:00:00 2001 From: Galia Peycheva Date: Fri, 22 Jan 2021 13:50:16 +0000 Subject: [PATCH] Revert "Make BackgroundBlurDrawable a SystemApi" Revert "Add permission check for blurs in SurfaceFlinger" Revert "Remove public usages of FLAG_BLUR_BEHIND" Revert "Add pid and uid to SF::setClientStateLocked" Revert "Add USE_BACKGROUND_BLUR to cts expected permissions" Revert submission 13350963-blur_system_api Reason for revert: This topic made blurs a system api. API council voted against that and we will instead aim to make it public for S. None of these changes are relevant in that case. Reverted Changes: I3683db296:Remove public usages of FLAG_BLUR_BEHIND I23b21b603:Add USE_BACKGROUND_BLUR to cts expected permission... Id21f03793:Add pid and uid to SF::setClientStateLocked If5d8344a5:Add permission for blur SystemApi I70d1e1715:Add permission check for blurs in SurfaceFlinger Icf98c3607:Make window background blurs SystemApi I0b881ec6e:Make BackgroundBlurDrawable a SystemApi Bug: 177523043 Test: m Change-Id: Iee4b89b06508c7dc3b7266452bb0b987f8670fac Merged-In: Iee4b89b06508c7dc3b7266452bb0b987f8670fac --- core/api/system-current.txt | 12 -- core/java/android/view/View.java | 20 ---- core/java/android/view/ViewRootImpl.java | 17 ++- .../drawable/BackgroundBlurDrawable.java | 107 +++++------------- .../android/graphics/drawable/Drawable.java | 18 --- 5 files changed, 35 insertions(+), 139 deletions(-) rename {graphics/java/android => core/java/com/android/internal}/graphics/drawable/BackgroundBlurDrawable.java (79%) diff --git a/core/api/system-current.txt b/core/api/system-current.txt index 683bc844d2644..0ae22f86c3cb1 100644 --- a/core/api/system-current.txt +++ b/core/api/system-current.txt @@ -2759,18 +2759,6 @@ package android.debug { } -package android.graphics.drawable { - - public final class BackgroundBlurDrawable extends android.graphics.drawable.Drawable { - ctor @RequiresPermission(android.Manifest.permission.USE_BACKGROUND_BLUR) public BackgroundBlurDrawable(); - method public void setBlurRadius(int); - method public void setColor(@ColorInt int); - method public void setCornerRadius(float); - method public void setCornerRadius(float, float, float, float); - } - -} - package android.graphics.fonts { public class FontManager { diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index 9a412fcd436ab..1adae9db9ecc0 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -9806,20 +9806,6 @@ public class View implements Drawable.Callback, KeyEvent.Callback, } } - private void notifyAttachForDrawables() { - if (mBackground != null) mBackground.onAttached(this); - if (mForegroundInfo != null && mForegroundInfo.mDrawable != null) { - mForegroundInfo.mDrawable.onAttached(this); - } - } - - private void notifyDetachForDrawables() { - if (mBackground != null) mBackground.onDetached(this); - if (mForegroundInfo != null && mForegroundInfo.mDrawable != null) { - mForegroundInfo.mDrawable.onDetached(this); - } - } - private void setNotifiedContentCaptureAppeared() { mPrivateFlags4 |= PFLAG4_NOTIFIED_CONTENT_CAPTURE_APPEARED; mPrivateFlags4 &= ~PFLAG4_NOTIFIED_CONTENT_CAPTURE_DISAPPEARED; @@ -20671,7 +20657,6 @@ public class View implements Drawable.Callback, KeyEvent.Callback, notifyEnterOrExitForAutoFillIfNeeded(true); notifyAppearedOrDisappearedForContentCaptureIfNeeded(true); - notifyAttachForDrawables(); } @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) @@ -20721,7 +20706,6 @@ public class View implements Drawable.Callback, KeyEvent.Callback, notifyEnterOrExitForAutoFillIfNeeded(false); notifyAppearedOrDisappearedForContentCaptureIfNeeded(false); - notifyDetachForDrawables(); } /** @@ -23859,7 +23843,6 @@ public class View implements Drawable.Callback, KeyEvent.Callback, if (mBackground != null) { if (isAttachedToWindow()) { mBackground.setVisible(false, false); - mBackground.onDetached(this); } mBackground.setCallback(null); unscheduleDrawable(mBackground); @@ -23909,7 +23892,6 @@ public class View implements Drawable.Callback, KeyEvent.Callback, background.setState(getDrawableState()); } if (isAttachedToWindow()) { - background.onAttached(this); background.setVisible(getWindowVisibility() == VISIBLE && isShown(), false); } @@ -24142,7 +24124,6 @@ public class View implements Drawable.Callback, KeyEvent.Callback, if (mForegroundInfo.mDrawable != null) { if (isAttachedToWindow()) { mForegroundInfo.mDrawable.setVisible(false, false); - mForegroundInfo.mDrawable.onDetached(this); } mForegroundInfo.mDrawable.setCallback(null); unscheduleDrawable(mForegroundInfo.mDrawable); @@ -24160,7 +24141,6 @@ public class View implements Drawable.Callback, KeyEvent.Callback, } applyForegroundTint(); if (isAttachedToWindow()) { - foreground.onAttached(this); foreground.setVisible(getWindowVisibility() == VISIBLE && isShown(), false); } // Set callback last, since the view may still be initializing. diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java index 844fc267c3cb3..5e3599d40dff1 100644 --- a/core/java/android/view/ViewRootImpl.java +++ b/core/java/android/view/ViewRootImpl.java @@ -115,7 +115,6 @@ import android.graphics.RecordingCanvas; import android.graphics.Rect; import android.graphics.Region; import android.graphics.RenderNode; -import android.graphics.drawable.BackgroundBlurDrawable; import android.graphics.drawable.Drawable; import android.graphics.drawable.GradientDrawable; import android.hardware.display.DisplayManager; @@ -187,6 +186,7 @@ import android.window.ClientWindowFrames; import com.android.internal.R; import com.android.internal.annotations.GuardedBy; import com.android.internal.annotations.VisibleForTesting; +import com.android.internal.graphics.drawable.BackgroundBlurDrawable; import com.android.internal.inputmethod.InputMethodDebug; import com.android.internal.os.IResultReceiver; import com.android.internal.os.SomeArgs; @@ -671,14 +671,6 @@ public final class ViewRootImpl implements ViewParent, private final BackgroundBlurDrawable.Aggregator mBlurRegionAggregator = new BackgroundBlurDrawable.Aggregator(this); - /** - * @return {@link BackgroundBlurDrawable.Aggregator} for this instance. - */ - @NonNull - public BackgroundBlurDrawable.Aggregator getBlurRegionAggregator() { - return mBlurRegionAggregator; - } - /** * @return {@link ImeFocusController} for this instance. */ @@ -10084,6 +10076,13 @@ public final class ViewRootImpl implements ViewParent, } } + /** + * Creates a background blur drawable for the backing {@link Surface}. + */ + public BackgroundBlurDrawable createBackgroundBlurDrawable() { + return mBlurRegionAggregator.createBackgroundBlurDrawable(mContext); + } + @Override public void onDescendantUnbufferedRequested() { mUnbufferedInputSource = mView.mUnbufferedInputSource; diff --git a/graphics/java/android/graphics/drawable/BackgroundBlurDrawable.java b/core/java/com/android/internal/graphics/drawable/BackgroundBlurDrawable.java similarity index 79% rename from graphics/java/android/graphics/drawable/BackgroundBlurDrawable.java rename to core/java/com/android/internal/graphics/drawable/BackgroundBlurDrawable.java index 7e75c5beec8bb..96dac565eb3dc 100644 --- a/graphics/java/android/graphics/drawable/BackgroundBlurDrawable.java +++ b/core/java/com/android/internal/graphics/drawable/BackgroundBlurDrawable.java @@ -14,13 +14,12 @@ * limitations under the License. */ -package android.graphics.drawable; +package com.android.internal.graphics.drawable; import android.annotation.ColorInt; import android.annotation.NonNull; import android.annotation.Nullable; -import android.annotation.RequiresPermission; -import android.annotation.SystemApi; +import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.ColorFilter; @@ -31,71 +30,59 @@ import android.graphics.PorterDuff; import android.graphics.PorterDuffXfermode; import android.graphics.Rect; import android.graphics.RenderNode; +import android.graphics.drawable.Drawable; import android.util.ArrayMap; import android.util.Log; import android.view.SurfaceControl; -import android.view.View; import android.view.ViewRootImpl; +import com.android.internal.R; + /** * A drawable that keeps track of a blur region, pokes a hole under it, and propagates its state * to SurfaceFlinger. - * - * @hide */ -@SystemApi public final class BackgroundBlurDrawable extends Drawable { + private static final String TAG = BackgroundBlurDrawable.class.getSimpleName(); private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG); + private final Aggregator mAggregator; private final RenderNode mRenderNode; private final Paint mPaint = new Paint(); private final Path mRectPath = new Path(); private final float[] mTmpRadii = new float[8]; private final SurfaceControl.BlurRegion mBlurRegion = new SurfaceControl.BlurRegion(); - private Aggregator mAggregator; - // This will be called from a thread pool. private final RenderNode.PositionUpdateListener mPositionUpdateListener = new RenderNode.PositionUpdateListener() { @Override public void positionChanged(long frameNumber, int left, int top, int right, int bottom) { - if (mAggregator == null) { + synchronized (mAggregator) { mBlurRegion.rect.set(left, top, right, bottom); - } else { - synchronized (mAggregator) { - mBlurRegion.rect.set(left, top, right, bottom); - mAggregator.onBlurRegionUpdated(BackgroundBlurDrawable.this, mBlurRegion); - } + mAggregator.onBlurRegionUpdated(BackgroundBlurDrawable.this, mBlurRegion); } } @Override public void positionLost(long frameNumber) { - if (mAggregator == null) { + synchronized (mAggregator) { mBlurRegion.rect.setEmpty(); - } else { - synchronized (mAggregator) { - mBlurRegion.rect.setEmpty(); - mAggregator.onBlurRegionUpdated(BackgroundBlurDrawable.this, mBlurRegion); - } + mAggregator.onBlurRegionUpdated(BackgroundBlurDrawable.this, mBlurRegion); } } }; - @RequiresPermission(android.Manifest.permission.USE_BACKGROUND_BLUR) - public BackgroundBlurDrawable() { + private BackgroundBlurDrawable(Aggregator aggregator) { + mAggregator = aggregator; mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC)); mPaint.setColor(Color.TRANSPARENT); mRenderNode = new RenderNode("BackgroundBlurDrawable"); mRenderNode.addPositionUpdateListener(mPositionUpdateListener); } - /** - * @hide - */ @Override public void draw(@NonNull Canvas canvas) { if (mRectPath.isEmpty() || !isVisible() || getAlpha() == 0) { @@ -113,9 +100,6 @@ public final class BackgroundBlurDrawable extends Drawable { mPaint.setColor(color); } - /** - * @hide - */ @Override public boolean setVisible(boolean visible, boolean restart) { boolean changed = super.setVisible(visible, restart); @@ -125,9 +109,6 @@ public final class BackgroundBlurDrawable extends Drawable { return changed; } - /** - * @hide - */ @Override public void setAlpha(int alpha) { mBlurRegion.alpha = alpha / 255f; @@ -158,12 +139,12 @@ public final class BackgroundBlurDrawable extends Drawable { */ public void setCornerRadius(float cornerRadiusTL, float cornerRadiusTR, float cornerRadiusBL, float cornerRadiusBR) { - maybeRunSynchronized(() -> { + synchronized (mAggregator) { mBlurRegion.cornerRadiusTL = cornerRadiusTL; mBlurRegion.cornerRadiusTR = cornerRadiusTR; mBlurRegion.cornerRadiusBL = cornerRadiusBL; mBlurRegion.cornerRadiusBR = cornerRadiusBR; - }); + } updatePath(); invalidateSelf(); } @@ -176,13 +157,12 @@ public final class BackgroundBlurDrawable extends Drawable { } private void updatePath() { - maybeRunSynchronized(() -> { + synchronized (mAggregator) { mTmpRadii[0] = mTmpRadii[1] = mBlurRegion.cornerRadiusTL; mTmpRadii[2] = mTmpRadii[3] = mBlurRegion.cornerRadiusTR; mTmpRadii[4] = mTmpRadii[5] = mBlurRegion.cornerRadiusBL; mTmpRadii[6] = mTmpRadii[7] = mBlurRegion.cornerRadiusBR; - }); - + } mRectPath.reset(); if (getAlpha() == 0 || !isVisible()) { return; @@ -192,62 +172,19 @@ public final class BackgroundBlurDrawable extends Drawable { Path.Direction.CW); } - /** - * @hide - */ @Override public void setColorFilter(@Nullable ColorFilter colorFilter) { throw new IllegalArgumentException("not implemented"); } - /** - * @hide - */ @Override public int getOpacity() { return PixelFormat.TRANSLUCENT; } - /** - * @hide - */ - @Override - public void onAttached(@NonNull View v) { - super.onAttached(v); - mAggregator = v.getViewRootImpl().getBlurRegionAggregator(); - } - - /** - * @hide - */ - @Override - public void onDetached(@NonNull View v) { - super.onDetached(v); - mAggregator = null; - } - - /** - * The Aggregator is called from the RenderThread to aggregate all blur regions and send them - * to SurfaceFlinger. Since the BackgroundBlurDrawable could be updated at any time from the - * main thread, we need to synchronize the two threads. The BackgroundBlurDrawable may be - * instantiated before the ViewRootImpl is created, i.e. before the Aggregator is created. - * In that case, updates are not synchronized. - */ - private void maybeRunSynchronized(Runnable r) { - if (mAggregator == null) { - r.run(); - } else { - synchronized (mAggregator) { - r.run(); - } - } - } - /** * Responsible for keeping track of all blur regions of a {@link ViewRootImpl} and posting a * message when it's time to propagate them. - * - * @hide */ public static final class Aggregator { @@ -261,6 +198,16 @@ public final class BackgroundBlurDrawable extends Drawable { mViewRoot = viewRoot; } + /** + * Creates a blur region with default radius. + */ + public BackgroundBlurDrawable createBackgroundBlurDrawable(Context context) { + BackgroundBlurDrawable drawable = new BackgroundBlurDrawable(this); + drawable.setBlurRadius(context.getResources().getDimensionPixelSize( + R.dimen.default_background_blur_radius)); + return drawable; + } + /** * Called from RenderThread only, already locked. * @param drawable diff --git a/graphics/java/android/graphics/drawable/Drawable.java b/graphics/java/android/graphics/drawable/Drawable.java index 7f22dc271507e..28b3b04b827d9 100644 --- a/graphics/java/android/graphics/drawable/Drawable.java +++ b/graphics/java/android/graphics/drawable/Drawable.java @@ -1464,24 +1464,6 @@ public abstract class Drawable { mVisible = attrs.getBoolean(visibleAttr, mVisible); } - /** - * Notifies the drawable that it has been attached. - * - * @param v The view that it is attached to - * @hide - */ - public void onAttached(View v) { - } - - /** - * Notifies the drawable that it has been detached. - * - * @param v The view that it is detached from - * @hide - */ - public void onDetached(View v) { - } - /** * Sets the source override density for this Drawable. If non-zero, this density is to be used * for any calls to {@link Resources#getDrawableForDensity(int, int, Theme)} or