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

Commit c63f06d4 authored by Chaohui Wang's avatar Chaohui Wang
Browse files

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
parent f1be1400
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -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,10 +51,14 @@ class CallStateRepository(private val context: Context) {
    fun isInCallFlow(): Flow<Boolean> = context.subscriptionsChangedFlow()
        .flatMapLatest {
            val subIds = subscriptionManager.activeSubscriptionIdList
            if (subIds.isEmpty()) {
                flowOf(false)
            } else {
                combine(subIds.map(::callStateFlow)) { states ->
                    states.any { it != TelephonyManager.CALL_STATE_IDLE }
                }
            }
        }
        .conflate()
        .flowOn(Dispatchers.Default)
        .onEach { Log.d(TAG, "isInCallFlow: $it") }
+12 −0
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ import org.mockito.kotlin.doAnswer
import org.mockito.kotlin.doReturn
import org.mockito.kotlin.mock
import org.mockito.kotlin.spy
import org.mockito.kotlin.stub

@RunWith(AndroidJUnit4::class)
class CallStateRepositoryTest {
@@ -86,6 +87,17 @@ class CallStateRepositoryTest {
            .inOrder()
    }

    @Test
    fun isInCallFlow_noActiveSubscription() = runBlocking {
        mockSubscriptionManager.stub {
            on { activeSubscriptionIdList } doReturn intArrayOf()
        }

        val isInCall = repository.isInCallFlow().firstWithTimeoutOrNull()

        assertThat(isInCall).isFalse()
    }

    @Test
    fun isInCallFlow_initial() = runBlocking {
        val isInCall = repository.isInCallFlow().firstWithTimeoutOrNull()