Merge "Fix isInCallFlow when no active subscription am: c63f06d4c8" into main

This commit is contained in:
Automerger Merge Worker
2024-05-07 14:49:05 +00:00
committed by Android (Google) Code Review
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()