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

Commit 13f60bf5 authored by Lucas Silva's avatar Lucas Silva
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
Change-Id: Ic5225a0b3296548bd918ec70cab54887a64df937
parent d00ccc11
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))