Merge "Use Recents CoroutineScope with cancellable Jobs per TaskView." into main

This commit is contained in:
Uwais Ashraf
2025-03-03 15:37:36 -08:00
committed by Android (Google) Code Review
@@ -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
@@ -515,7 +514,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<Job>()
/**
@@ -744,8 +743,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)
}
}
}