summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--packages/SystemUI/src/com/android/systemui/display/data/repository/DisplayRepository.kt4
-rw-r--r--packages/SystemUI/src/com/android/systemui/util/kotlin/CoroutinesModule.kt9
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/display/data/repository/DisplayRepositoryTest.kt1
3 files changed, 12 insertions, 2 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..d3def315f131 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
@@ -94,6 +94,7 @@ constructor(
private val displayManager: DisplayManager,
@Background backgroundHandler: Handler,
@Application applicationScope: CoroutineScope,
+ @Background bgApplicationScope: CoroutineScope,
@Background backgroundCoroutineDispatcher: CoroutineDispatcher
) : DisplayRepository {
private val allDisplayEvents: Flow<DisplayEvent> =
@@ -203,9 +204,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",
diff --git a/packages/SystemUI/tests/src/com/android/systemui/display/data/repository/DisplayRepositoryTest.kt b/packages/SystemUI/tests/src/com/android/systemui/display/data/repository/DisplayRepositoryTest.kt
index 806930d091b1..447265d806ed 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/display/data/repository/DisplayRepositoryTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/display/data/repository/DisplayRepositoryTest.kt
@@ -69,6 +69,7 @@ class DisplayRepositoryTest : SysuiTestCase() {
displayManager,
testHandler,
TestScope(UnconfinedTestDispatcher()),
+ TestScope(UnconfinedTestDispatcher()),
UnconfinedTestDispatcher()
)
verify(displayManager, never()).registerDisplayListener(any(), any())