Set bg executor to inflate widgets asynchronously

AppWidgetHostView allows the caller to specify a background executor to
inflate RemoteViews on. This ensures expensive takss such as image
loading happen in the background.

Bug: 369210917
Test: verified on glanceable hub with various different widgets
Flag: EXEMPT bugfix
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:13f60bf537759f959bb944e7644d75813821ce4b)
Merged-In: Ic5225a0b3296548bd918ec70cab54887a64df937
Change-Id: Ic5225a0b3296548bd918ec70cab54887a64df937
diff --git a/packages/SystemUI/src/com/android/systemui/communal/util/WidgetViewFactory.kt b/packages/SystemUI/src/com/android/systemui/communal/util/WidgetViewFactory.kt
index ec03227..cafa74f 100644
--- a/packages/SystemUI/src/com/android/systemui/communal/util/WidgetViewFactory.kt
+++ b/packages/SystemUI/src/com/android/systemui/communal/util/WidgetViewFactory.kt
@@ -26,6 +26,7 @@
 import com.android.systemui.communal.widgets.CommunalAppWidgetHostView
 import com.android.systemui.communal.widgets.WidgetInteractionHandler
 import com.android.systemui.dagger.qualifiers.UiBackground
+import java.util.concurrent.Executor
 import javax.inject.Inject
 import kotlin.coroutines.CoroutineContext
 
@@ -34,6 +35,7 @@
 @Inject
 constructor(
     @UiBackground private val uiBgContext: CoroutineContext,
+    @UiBackground private val uiBgExecutor: Executor,
     private val appWidgetHost: CommunalAppWidgetHost,
     private val interactionHandler: WidgetInteractionHandler,
     private val listenerFactory: AppWidgetHostListenerDelegate.Factory,
@@ -44,8 +46,11 @@
         size: SizeF,
     ): CommunalAppWidgetHostView =
         withContext("$TAG#createWidget", uiBgContext) {
-            val view = CommunalAppWidgetHostView(context, interactionHandler)
-            view.setAppWidget(model.appWidgetId, model.providerInfo)
+            val view =
+                CommunalAppWidgetHostView(context, interactionHandler).apply {
+                    setExecutor(uiBgExecutor)
+                    setAppWidget(model.appWidgetId, model.providerInfo)
+                }
             // Instead of setting the view as the listener directly, we wrap the view in a delegate
             // which ensures the callbacks always get called on the main thread.
             appWidgetHost.setListener(model.appWidgetId, listenerFactory.create(view))