From 7a797477ea74c94c2e3ef63de16f44d133cc5dee Mon Sep 17 00:00:00 2001 From: Uwais Ashraf Date: Mon, 3 Mar 2025 10:16:03 +0000 Subject: [PATCH] Use Recents CoroutineScope with cancellable Jobs per TaskView. This saves time on first usage which can happen during a CUJ on main. Bug: 395294954 Flag: com.android.launcher3.enable_refactor_task_thumbnail Test: Perfetto trace comparison Change-Id: I496a00e3002f29830adbd8bb10857e78b16c68c8 --- quickstep/src/com/android/quickstep/views/TaskView.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/quickstep/src/com/android/quickstep/views/TaskView.kt b/quickstep/src/com/android/quickstep/views/TaskView.kt index 276318c2db..7016188cb0 100644 --- a/quickstep/src/com/android/quickstep/views/TaskView.kt +++ b/quickstep/src/com/android/quickstep/views/TaskView.kt @@ -100,7 +100,6 @@ import com.android.systemui.shared.recents.model.ThumbnailData import com.android.systemui.shared.system.ActivityManagerWrapper import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Job -import kotlinx.coroutines.SupervisorJob import kotlinx.coroutines.cancel import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.launch @@ -511,7 +510,7 @@ constructor( private var viewModel: TaskViewModel? = null private val dispatcherProvider: DispatcherProvider by RecentsDependencies.inject() - private val coroutineScope by lazy { CoroutineScope(SupervisorJob() + dispatcherProvider.main) } + private val coroutineScope: CoroutineScope by RecentsDependencies.inject() private val coroutineJobs = mutableListOf() /** @@ -740,8 +739,9 @@ constructor( // The TaskView lifecycle is starts the ViewModel during onBind, and cleans it in // onRecycle. So it should be initialized at this point. TaskView Lifecycle: // `bind` -> `onBind` -> onAttachedToWindow() -> onDetachFromWindow -> onRecycle - coroutineJobs += - coroutineScope.launch { viewModel!!.state.collectLatest(::updateTaskViewState) } + coroutineJobs += coroutineScope.launch(dispatcherProvider.main) { + viewModel!!.state.collectLatest(::updateTaskViewState) + } } }