Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b4c9a340 authored by Lucas Silva's avatar Lucas Silva Committed by Android Build Coastguard Worker
Browse files

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
parent b65fa442
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import com.android.systemui.communal.widgets.CommunalAppWidgetHost
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 @@ class WidgetViewFactory
@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 @@ constructor(
        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))