Fix isInCallFlow when no active subscription

Direct emit false in this case to fix.

Fix: 338484668
Test: manual - on SIMs
Test: unit test
Change-Id: I5286701160d95b1c06e577db6232f7e70f040cdb
This commit is contained in:
Chaohui Wang
2024-05-07 16:37:11 +08:00
parent f1be1400b7
commit c63f06d4c8
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()