Removing croppiing functionality from FastBitmapDrawable

Bug: 183641907
Test: Manual
Change-Id: I0727250fe8da2c8f4f6ab5a05e2a45591f1691d1
diff --git a/iconloaderlib/src/com/android/launcher3/icons/FastBitmapDrawable.java b/iconloaderlib/src/com/android/launcher3/icons/FastBitmapDrawable.java
index ec930f8..a3f38e0 100644
--- a/iconloaderlib/src/com/android/launcher3/icons/FastBitmapDrawable.java
+++ b/iconloaderlib/src/com/android/launcher3/icons/FastBitmapDrawable.java
@@ -17,7 +17,6 @@
 package com.android.launcher3.icons;
 
 import android.animation.ObjectAnimator;
-import android.content.Context;
 import android.graphics.Bitmap;
 import android.graphics.Canvas;
 import android.graphics.Color;
@@ -25,7 +24,6 @@
 import android.graphics.ColorMatrix;
 import android.graphics.ColorMatrixColorFilter;
 import android.graphics.Paint;
-import android.graphics.Path;
 import android.graphics.PixelFormat;
 import android.graphics.Rect;
 import android.graphics.drawable.Drawable;
@@ -36,7 +34,6 @@
 
 import androidx.annotation.Nullable;
 
-
 public class FastBitmapDrawable extends Drawable {
 
     private static final Interpolator ACCEL = new AccelerateInterpolator();
@@ -60,8 +57,6 @@
     private boolean mIsPressed;
     private boolean mIsDisabled;
     float mDisabledAlpha = 1f;
-    private float mRoundedCornersRadius = 0f;
-    private final Path mClipPath = new Path();
 
     // Animator and properties for the fast bitmap drawable's scale
     private static final Property<FastBitmapDrawable, Float> SCALE
@@ -103,13 +98,6 @@
 
     @Override
     public final void draw(Canvas canvas) {
-        if (mRoundedCornersRadius > 0) {
-            float radius = mRoundedCornersRadius * mScale;
-            mClipPath.reset();
-            mClipPath.addRoundRect(0, 0, getIntrinsicWidth(), getIntrinsicHeight(),
-                    radius, radius, Path.Direction.CCW);
-            canvas.clipPath(mClipPath);
-        }
         if (mScale != 1f) {
             int count = canvas.save();
             Rect bounds = getBounds();
@@ -169,14 +157,6 @@
         return mScaleAnimation == null ? 1 : mScale;
     }
 
-    public void setRoundedCornersRadius(float radius) {
-        mRoundedCornersRadius = radius;
-    }
-
-    public float getRoundedCornersRadius() {
-        return mRoundedCornersRadius;
-    }
-
     @Override
     public int getIntrinsicWidth() {
         return mBitmap.getWidth();
diff --git a/iconloaderlib/src/com/android/launcher3/icons/IconProvider.java b/iconloaderlib/src/com/android/launcher3/icons/IconProvider.java
index 7749308..c0e1549 100644
--- a/iconloaderlib/src/com/android/launcher3/icons/IconProvider.java
+++ b/iconloaderlib/src/com/android/launcher3/icons/IconProvider.java
@@ -103,7 +103,7 @@
      * on the UI
      */
     public Drawable getIconForUI(ActivityInfo info, UserHandle user) {
-        Drawable icon = getIcon(info, user);
+        Drawable icon = getIcon(info);
         if (icon instanceof BitmapInfo.Extender) {
             ((Extender) icon).prepareToDrawOnUi();
         }
@@ -121,8 +121,10 @@
     /**
      * Loads the icon for the provided activity info
      */
-    public Drawable getIcon(ActivityInfo info, UserHandle user) {
-        return getIcon(info.applicationInfo.packageName, user, info, mContext.getPackageManager(),
+    public Drawable getIcon(ActivityInfo info) {
+        return getIcon(info.applicationInfo.packageName,
+                UserHandle.getUserHandleForUid(info.applicationInfo.uid),
+                info, mContext.getPackageManager(),
                 AI_LOADER);
     }
 
diff --git a/iconloaderlib/src/com/android/launcher3/icons/RoundDrawableWrapper.java b/iconloaderlib/src/com/android/launcher3/icons/RoundDrawableWrapper.java
new file mode 100644
index 0000000..e569c1e
--- /dev/null
+++ b/iconloaderlib/src/com/android/launcher3/icons/RoundDrawableWrapper.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2021 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.
+ */
+
+package com.android.launcher3.icons;
+
+import android.graphics.Canvas;
+import android.graphics.Path;
+import android.graphics.Rect;
+import android.graphics.RectF;
+import android.graphics.drawable.Drawable;
+import android.graphics.drawable.DrawableWrapper;
+
+/**
+ * A drawable which clips rounded corner around a child drawable
+ */
+public class RoundDrawableWrapper extends DrawableWrapper {
+
+    private final RectF mTempRect = new RectF();
+    private final Path mClipPath = new Path();
+    private final float mRoundedCornersRadius;
+
+    public RoundDrawableWrapper(Drawable dr, float radius) {
+        super(dr);
+        mRoundedCornersRadius = radius;
+    }
+
+    @Override
+    protected void onBoundsChange(Rect bounds) {
+        mTempRect.set(getBounds());
+        mClipPath.reset();
+        mClipPath.addRoundRect(mTempRect, mRoundedCornersRadius,
+                mRoundedCornersRadius, Path.Direction.CCW);
+        super.onBoundsChange(bounds);
+    }
+
+    @Override
+    public final void draw(Canvas canvas) {
+        int saveCount = canvas.save();
+        canvas.clipPath(mClipPath);
+        super.draw(canvas);
+        canvas.restoreToCount(saveCount);
+    }
+}