Use toolkit instead of renderscript in SystemUI

Bug: 273768759
Test: Visual comparison of media artwork before and after change.
Change-Id: I8f4a4ce673248bbb26f67e071f08f559daf67cdb
diff --git a/packages/SystemUI/Android.bp b/packages/SystemUI/Android.bp
index cd0fbea..beade79 100644
--- a/packages/SystemUI/Android.bp
+++ b/packages/SystemUI/Android.bp
@@ -177,6 +177,7 @@
         "lottie",
         "LowLightDreamLib",
         "motion_tool_lib",
+        "renderscript_toolkit",
     ],
     manifest: "AndroidManifest.xml",
 
@@ -270,6 +271,7 @@
         "WindowManager-Shell",
         "LowLightDreamLib",
         "motion_tool_lib",
+        "renderscript_toolkit",
         "androidx.core_core-animation-testing-nodeps",
     ],
 }
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/MediaArtworkProcessor.kt b/packages/SystemUI/src/com/android/systemui/statusbar/MediaArtworkProcessor.kt
index 750272d..dd713ae 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/MediaArtworkProcessor.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/MediaArtworkProcessor.kt
@@ -21,20 +21,17 @@
 import android.graphics.Canvas
 import android.graphics.Point
 import android.graphics.Rect
-import android.renderscript.Allocation
-import android.renderscript.Element
-import android.renderscript.RenderScript
-import android.renderscript.ScriptIntrinsicBlur
 import android.util.Log
 import android.util.MathUtils
 import com.android.internal.graphics.ColorUtils
 import com.android.systemui.dagger.SysUISingleton
 import com.android.systemui.statusbar.notification.MediaNotificationProcessor
+import com.google.android.renderscript.Toolkit
 import javax.inject.Inject
 
 private const val TAG = "MediaArtworkProcessor"
 private const val COLOR_ALPHA = (255 * 0.7f).toInt()
-private const val BLUR_RADIUS = 25f
+private const val BLUR_RADIUS = 25
 private const val DOWNSAMPLE = 6
 
 @SysUISingleton
@@ -47,10 +44,6 @@
         if (mArtworkCache != null) {
             return mArtworkCache
         }
-        val renderScript = RenderScript.create(context)
-        val blur = ScriptIntrinsicBlur.create(renderScript, Element.U8_4(renderScript))
-        var input: Allocation? = null
-        var output: Allocation? = null
         var inBitmap: Bitmap? = null
         try {
             @Suppress("DEPRECATION")
@@ -66,18 +59,8 @@
                 inBitmap = oldIn.copy(Bitmap.Config.ARGB_8888, false /* isMutable */)
                 oldIn.recycle()
             }
-            val outBitmap = Bitmap.createBitmap(inBitmap.width, inBitmap.height,
-                    Bitmap.Config.ARGB_8888)
 
-            input = Allocation.createFromBitmap(renderScript, inBitmap,
-                    Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_GRAPHICS_TEXTURE)
-            output = Allocation.createFromBitmap(renderScript, outBitmap)
-
-            blur.setRadius(BLUR_RADIUS)
-            blur.setInput(input)
-            blur.forEach(output)
-            output.copyTo(outBitmap)
-
+            val outBitmap = Toolkit.blur(inBitmap, BLUR_RADIUS)
             val swatch = MediaNotificationProcessor.findBackgroundSwatch(artwork)
 
             val canvas = Canvas(outBitmap)
@@ -87,9 +70,6 @@
             Log.e(TAG, "error while processing artwork", ex)
             return null
         } finally {
-            input?.destroy()
-            output?.destroy()
-            blur.destroy()
             inBitmap?.recycle()
         }
     }
@@ -98,4 +78,4 @@
         mArtworkCache?.recycle()
         mArtworkCache = null
     }
-}
\ No newline at end of file
+}