Fix isInCallFlow when no active subscription am: c63f06d4c8

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/27205448

Change-Id: I5a58046c3e7ed2a1164648516248b39ee4feb5ef
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Chaohui Wang
2024-05-07 14:48:55 +00:00
committed by Automerger Merge Worker
2 changed files with 19 additions and 2 deletions

View File

@@ -26,6 +26,7 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.conflate
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.onEach
@@ -50,8 +51,12 @@ class CallStateRepository(private val context: Context) {
fun isInCallFlow(): Flow<Boolean> = context.subscriptionsChangedFlow()
.flatMapLatest {
val subIds = subscriptionManager.activeSubscriptionIdList
combine(subIds.map(::callStateFlow)) { states ->
states.any { it != TelephonyManager.CALL_STATE_IDLE }
if (subIds.isEmpty()) {
flowOf(false)
} else {
combine(subIds.map(::callStateFlow)) { states ->
states.any { it != TelephonyManager.CALL_STATE_IDLE }
}
}
}
.conflate()