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

Commit e702a34a authored by Evan Laird's avatar Evan Laird
Browse files

[Sb] flowOn(bgDispatcher) to IPC calls

Any place in the mobile repositories that used a `conflatedCallbackFlow`
or `callbackFlow` which registered an IPC is now defined to
`flowOn(bgDispatcher)`. This ensures that the initial IPC that registers
the callbacks with the system runs on a background thread and doesn't
block.

Any processing after the `flowOn` still runs in the calling context.

Fixes: 290336252
Test: tests in systemui/statusbar/pipeline/
Change-Id: I9748040006701cbcbcafcb84b7b7ddce8f17a8ac
parent bf6f5e54
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -71,6 +71,7 @@ import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.callbackFlow
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.mapLatest
import kotlinx.coroutines.flow.mapNotNull
@@ -181,6 +182,7 @@ class MobileConnectionRepositoryImpl(
                telephonyManager.registerTelephonyCallback(bgDispatcher.asExecutor(), callback)
                awaitClose { telephonyManager.unregisterTelephonyCallback(callback) }
            }
            .flowOn(bgDispatcher)
            .scan(initial = initial) { state, event -> state.applyEvent(event) }
            .stateIn(scope = scope, started = SharingStarted.WhileSubscribed(), initial)
    }
@@ -358,6 +360,7 @@ class MobileConnectionRepositoryImpl(

                awaitClose { context.unregisterReceiver(receiver) }
            }
            .flowOn(bgDispatcher)
            .stateIn(scope, SharingStarted.WhileSubscribed(), defaultNetworkName)

    override val dataEnabled = run {
+17 −14
Original line number Diff line number Diff line
@@ -134,7 +134,8 @@ constructor(
            )
            .stateIn(scope, started = SharingStarted.WhileSubscribed(), null)

    private val mobileSubscriptionsChangeEvent: Flow<Unit> = conflatedCallbackFlow {
    private val mobileSubscriptionsChangeEvent: Flow<Unit> =
        conflatedCallbackFlow {
                val callback =
                    object : SubscriptionManager.OnSubscriptionsChangedListener() {
                        override fun onSubscriptionsChanged() {
@@ -150,6 +151,7 @@ constructor(

                awaitClose { subscriptionManager.removeOnSubscriptionsChangedListener(callback) }
            }
            .flowOn(bgDispatcher)

    /**
     * State flow that emits the set of mobile data subscriptions, each represented by its own
@@ -184,6 +186,7 @@ constructor(
                telephonyManager.registerTelephonyCallback(bgDispatcher.asExecutor(), callback)
                awaitClose { telephonyManager.unregisterTelephonyCallback(callback) }
            }
            .flowOn(bgDispatcher)
            .distinctUntilChanged()
            .logDiffsForTable(
                tableLogger,