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

Commit 60dfe7ed authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Switch to using a ThreadPoolExecutor for widget inflation on the hub" into main

parents 0c7e4642 540ed5d8
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -1200,6 +1200,16 @@ flag {
  bug: "368053818"
}

flag {
  name: "communal_hub_use_thread_pool_for_widgets"
  namespace: "systemui"
  description: "Use a dedicated thread pool executor for loading widgets on glanceable hub"
  bug: "369412569"
  metadata {
    purpose: PURPOSE_BUGFIX
  }
}

flag {
  name: "communal_standalone_support"
  namespace: "systemui"
+24 −1
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.content.Context
import android.os.Bundle
import android.util.SizeF
import com.android.app.tracing.coroutines.withContextTraced as withContext
import com.android.systemui.Flags
import com.android.systemui.communal.domain.model.CommunalContentModel
import com.android.systemui.communal.shared.model.GlanceableHubMultiUserHelper
import com.android.systemui.communal.widgets.AppWidgetHostListenerDelegate
@@ -30,6 +31,9 @@ import com.android.systemui.communal.widgets.WidgetInteractionHandler
import com.android.systemui.dagger.qualifiers.UiBackground
import dagger.Lazy
import java.util.concurrent.Executor
import java.util.concurrent.LinkedBlockingQueue
import java.util.concurrent.ThreadPoolExecutor
import java.util.concurrent.TimeUnit
import javax.inject.Inject
import kotlin.coroutines.CoroutineContext

@@ -53,7 +57,11 @@ constructor(
        withContext("$TAG#createWidget", uiBgContext) {
            val view =
                CommunalAppWidgetHostView(context, interactionHandler).apply {
                    if (Flags.communalHubUseThreadPoolForWidgets()) {
                        setExecutor(widgetExecutor)
                    } else {
                        setExecutor(uiBgExecutor)
                    }
                    setAppWidget(model.appWidgetId, model.providerInfo)
                }

@@ -90,5 +98,20 @@ constructor(

    private companion object {
        const val TAG = "WidgetViewFactory"

        val poolSize = Runtime.getRuntime().availableProcessors().coerceAtLeast(2)

        /**
         * This executor is used for widget inflation. Parameters match what launcher uses. See
         * [com.android.launcher3.util.Executors.THREAD_POOL_EXECUTOR].
         */
        val widgetExecutor =
            ThreadPoolExecutor(
                /*corePoolSize*/ poolSize,
                /*maxPoolSize*/ poolSize,
                /*keepAlive*/ 1,
                /*unit*/ TimeUnit.SECONDS,
                /*workQueue*/ LinkedBlockingQueue(),
            )
    }
}