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:
@@ -26,6 +26,7 @@ import kotlinx.coroutines.flow.Flow
|
|||||||
import kotlinx.coroutines.flow.combine
|
import kotlinx.coroutines.flow.combine
|
||||||
import kotlinx.coroutines.flow.conflate
|
import kotlinx.coroutines.flow.conflate
|
||||||
import kotlinx.coroutines.flow.flatMapLatest
|
import kotlinx.coroutines.flow.flatMapLatest
|
||||||
|
import kotlinx.coroutines.flow.flowOf
|
||||||
import kotlinx.coroutines.flow.flowOn
|
import kotlinx.coroutines.flow.flowOn
|
||||||
import kotlinx.coroutines.flow.onEach
|
import kotlinx.coroutines.flow.onEach
|
||||||
|
|
||||||
@@ -50,8 +51,12 @@ class CallStateRepository(private val context: Context) {
|
|||||||
fun isInCallFlow(): Flow<Boolean> = context.subscriptionsChangedFlow()
|
fun isInCallFlow(): Flow<Boolean> = context.subscriptionsChangedFlow()
|
||||||
.flatMapLatest {
|
.flatMapLatest {
|
||||||
val subIds = subscriptionManager.activeSubscriptionIdList
|
val subIds = subscriptionManager.activeSubscriptionIdList
|
||||||
combine(subIds.map(::callStateFlow)) { states ->
|
if (subIds.isEmpty()) {
|
||||||
states.any { it != TelephonyManager.CALL_STATE_IDLE }
|
flowOf(false)
|
||||||
|
} else {
|
||||||
|
combine(subIds.map(::callStateFlow)) { states ->
|
||||||
|
states.any { it != TelephonyManager.CALL_STATE_IDLE }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.conflate()
|
.conflate()
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ import org.mockito.kotlin.doAnswer
|
|||||||
import org.mockito.kotlin.doReturn
|
import org.mockito.kotlin.doReturn
|
||||||
import org.mockito.kotlin.mock
|
import org.mockito.kotlin.mock
|
||||||
import org.mockito.kotlin.spy
|
import org.mockito.kotlin.spy
|
||||||
|
import org.mockito.kotlin.stub
|
||||||
|
|
||||||
@RunWith(AndroidJUnit4::class)
|
@RunWith(AndroidJUnit4::class)
|
||||||
class CallStateRepositoryTest {
|
class CallStateRepositoryTest {
|
||||||
@@ -86,6 +87,17 @@ class CallStateRepositoryTest {
|
|||||||
.inOrder()
|
.inOrder()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun isInCallFlow_noActiveSubscription() = runBlocking {
|
||||||
|
mockSubscriptionManager.stub {
|
||||||
|
on { activeSubscriptionIdList } doReturn intArrayOf()
|
||||||
|
}
|
||||||
|
|
||||||
|
val isInCall = repository.isInCallFlow().firstWithTimeoutOrNull()
|
||||||
|
|
||||||
|
assertThat(isInCall).isFalse()
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun isInCallFlow_initial() = runBlocking {
|
fun isInCallFlow_initial() = runBlocking {
|
||||||
val isInCall = repository.isInCallFlow().firstWithTimeoutOrNull()
|
val isInCall = repository.isInCallFlow().firstWithTimeoutOrNull()
|
||||||
|
|||||||
Reference in New Issue
Block a user