diff options
| author | 2023-11-27 17:05:17 +0000 | |
|---|---|---|
| committer | 2023-11-27 17:05:17 +0000 | |
| commit | fde7a7dbcb3a3ba14a3145763b5f70d8e7869dfd (patch) | |
| tree | a70212a0e8477d5d28fac0e958219e246fd8ed63 | |
| parent | 686b0764bf9a2e922caac70670d96dff35435244 (diff) | |
| parent | 021c1a9ad298282176b26d15ed02dcfc4b0c0222 (diff) | |
Merge changes Ibac62793,I45260817 into main
* changes:
Convert enableDisplays to a StateFlow in the background
Introduce @Background CoroutineScope
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/display/data/repository/DisplayRepository.kt | 9 | ||||
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/util/kotlin/CoroutinesModule.kt | 9 |
2 files changed, 12 insertions, 6 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/display/data/repository/DisplayRepository.kt b/packages/SystemUI/src/com/android/systemui/display/data/repository/DisplayRepository.kt index 26c5ea6e164d..c93b8e1a48f2 100644 --- a/packages/SystemUI/src/com/android/systemui/display/data/repository/DisplayRepository.kt +++ b/packages/SystemUI/src/com/android/systemui/display/data/repository/DisplayRepository.kt @@ -29,7 +29,6 @@ import com.android.app.tracing.FlowTracing.traceEach import com.android.app.tracing.traceSection import com.android.systemui.common.coroutine.ConflatedCallbackFlow.conflatedCallbackFlow import com.android.systemui.dagger.SysUISingleton -import com.android.systemui.dagger.qualifiers.Application import com.android.systemui.dagger.qualifiers.Background import com.android.systemui.display.data.DisplayEvent import com.android.systemui.util.Compile @@ -93,7 +92,7 @@ class DisplayRepositoryImpl constructor( private val displayManager: DisplayManager, @Background backgroundHandler: Handler, - @Application applicationScope: CoroutineScope, + @Background bgApplicationScope: CoroutineScope, @Background backgroundCoroutineDispatcher: CoroutineDispatcher ) : DisplayRepository { private val allDisplayEvents: Flow<DisplayEvent> = @@ -141,8 +140,7 @@ constructor( private val enabledDisplays = allDisplayEvents .map { getDisplays() } - .flowOn(backgroundCoroutineDispatcher) - .shareIn(applicationScope, started = SharingStarted.WhileSubscribed(), replay = 1) + .shareIn(bgApplicationScope, started = SharingStarted.WhileSubscribed(), replay = 1) override val displays: Flow<Set<Display>> = enabledDisplays @@ -203,9 +201,8 @@ constructor( } .distinctUntilChanged() .debugLog("connectedDisplayIds") - .flowOn(backgroundCoroutineDispatcher) .stateIn( - applicationScope, + bgApplicationScope, started = SharingStarted.WhileSubscribed(), // The initial value is set to empty, but connected displays are gathered as soon as // the flow starts being collected. This is to ensure the call to get displays (an diff --git a/packages/SystemUI/src/com/android/systemui/util/kotlin/CoroutinesModule.kt b/packages/SystemUI/src/com/android/systemui/util/kotlin/CoroutinesModule.kt index cc9335edfc14..472f0ae364c5 100644 --- a/packages/SystemUI/src/com/android/systemui/util/kotlin/CoroutinesModule.kt +++ b/packages/SystemUI/src/com/android/systemui/util/kotlin/CoroutinesModule.kt @@ -14,6 +14,7 @@ import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.ExperimentalCoroutinesApi +import kotlinx.coroutines.plus import kotlin.coroutines.CoroutineContext import kotlin.coroutines.EmptyCoroutineContext @@ -29,6 +30,14 @@ class CoroutinesModule { @Provides @SysUISingleton + @Background + fun bgApplicationScope( + @Application applicationScope: CoroutineScope, + @Background coroutineContext: CoroutineContext, + ): CoroutineScope = applicationScope.plus(coroutineContext) + + @Provides + @SysUISingleton @Main @Deprecated( "Use @Main CoroutineContext instead", |