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

Commit 1eee7dcc authored by Tom Hsu's avatar Tom Hsu Committed by Android (Google) Code Review
Browse files

Merge "Add emergency call check to control sim switch UI" into main

parents ac65a51d d694666c
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.settings.network.telephony

import android.content.Context
import android.telecom.TelecomManager
import android.telephony.TelephonyCallback
import android.telephony.TelephonyManager
import android.util.Log
@@ -66,6 +67,14 @@ class CallStateRepository(
        .onEach { Log.d(TAG, "isInCallFlow: $it") }
        .flowOn(Dispatchers.Default)

    fun isInEmergencyCallFlow(): Flow<Boolean> {
       val telecomManager = context.getSystemService(TelecomManager::class.java)
        return if (telecomManager == null)
            flowOf(false)
        else
            flowOf(telecomManager.isInEmergencyCall)
    }

    private companion object {
        private const val TAG = "CallStateRepository"
    }
+3 −2
Original line number Diff line number Diff line
@@ -37,9 +37,10 @@ class SubscriptionActivationRepository(
) {
    fun isActivationChangeableFlow(): Flow<Boolean> = combine(
        callStateRepository.isInCallFlow(),
        callStateRepository.isInEmergencyCallFlow(),
        satelliteRepository.getIsSessionStartedFlow()
    ) { isInCall, isSatelliteModemEnabled ->
        !isInCall && !isSatelliteModemEnabled
    ) { isInCall, isInEmergencyCallFlow, isSatelliteModemEnabled ->
        !isInCall && !isInEmergencyCallFlow && !isSatelliteModemEnabled
    }

    /**
+23 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.settings.network.telephony

import android.content.Context
import android.telecom.TelecomManager
import android.telephony.TelephonyCallback
import android.telephony.TelephonyManager
import androidx.test.core.app.ApplicationProvider
@@ -26,6 +27,7 @@ import com.android.settingslib.spa.testutils.toListWithTimeout
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.async
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.runBlocking
import org.junit.Test
@@ -36,6 +38,7 @@ import org.mockito.kotlin.doReturn
import org.mockito.kotlin.mock
import org.mockito.kotlin.spy
import org.mockito.kotlin.stub
import org.mockito.kotlin.whenever

@RunWith(AndroidJUnit4::class)
class CallStateRepositoryTest {
@@ -49,12 +52,15 @@ class CallStateRepositoryTest {
        }
    }

    private val mockTelecomManager = mock<TelecomManager>{}

    private val mockSubscriptionRepository = mock<SubscriptionRepository> {
        on { activeSubscriptionIdListFlow() } doReturn flowOf(listOf(SUB_ID))
    }

    private val context: Context = spy(ApplicationProvider.getApplicationContext()) {
        on { getSystemService(TelephonyManager::class.java) } doReturn mockTelephonyManager
        on { getSystemService(TelecomManager::class.java) } doReturn mockTelecomManager
    }

    private val repository = CallStateRepository(context, mockSubscriptionRepository)
@@ -114,6 +120,23 @@ class CallStateRepositoryTest {
            .inOrder()
    }

    @Test
    fun isInEmergencyCall_inCall_returnTrue() = runBlocking {
        whenever(mockTelecomManager.isInEmergencyCall).thenReturn(true)

        val result = repository.isInEmergencyCallFlow().first()
        assertThat(result).isEqualTo(true)
    }

    @Test
    fun isInEmergencyCall_notInCall_returnFalse() = runBlocking {
        whenever(mockTelecomManager.isInEmergencyCall).thenReturn(false)

        val result = repository.isInEmergencyCallFlow().first()

        assertThat(result).isEqualTo(false)
    }

    private companion object {
        const val SUB_ID = 1
    }
+18 −1
Original line number Diff line number Diff line
@@ -18,7 +18,6 @@ package com.android.settings.network.telephony

import android.content.Context
import android.content.pm.PackageManager
import android.content.Intent
import android.os.UserHandle
import android.telephony.SubscriptionManager
import android.telephony.TelephonyManager
@@ -72,6 +71,7 @@ class SubscriptionActivationRepositoryTest {
    fun isActivationChangeableFlow_changeable() = runBlocking {
        mockCallStateRepository.stub {
            on { isInCallFlow() } doReturn flowOf(false)
            on { isInEmergencyCallFlow() } doReturn flowOf(false)
        }
        mockSatelliteRepository.stub {
            on { getIsSessionStartedFlow() } doReturn flowOf(false)
@@ -86,6 +86,7 @@ class SubscriptionActivationRepositoryTest {
    fun isActivationChangeableFlow_inCall_notChangeable() = runBlocking {
        mockCallStateRepository.stub {
            on { isInCallFlow() } doReturn flowOf(true)
            on { isInEmergencyCallFlow() } doReturn flowOf(false)
        }
        mockSatelliteRepository.stub {
            on { getIsSessionStartedFlow() } doReturn flowOf(false)
@@ -100,6 +101,7 @@ class SubscriptionActivationRepositoryTest {
    fun isActivationChangeableFlow_satelliteSessionStarted_notChangeable() = runBlocking {
        mockCallStateRepository.stub {
            on { isInCallFlow() } doReturn flowOf(false)
            on { isInEmergencyCallFlow() } doReturn flowOf(false)
        }
        mockSatelliteRepository.stub {
            on { getIsSessionStartedFlow() } doReturn flowOf(true)
@@ -110,6 +112,21 @@ class SubscriptionActivationRepositoryTest {
        assertThat(changeable).isFalse()
    }

    @Test
    fun isActivationChangeableFlow_inEmergencyCall_notChangeable() = runBlocking {
        mockCallStateRepository.stub {
            on { isInCallFlow() } doReturn flowOf(false)
            on { isInEmergencyCallFlow() } doReturn flowOf(true)
        }
        mockSatelliteRepository.stub {
            on { getIsSessionStartedFlow() } doReturn flowOf(false)
        }

        val changeable = repository.isActivationChangeableFlow().firstWithTimeoutOrNull()

        assertThat(changeable).isFalse()
    }

    @Test
    fun setActive_defaultSubId_doNothing() = runBlocking {
        repository.setActive(subId = SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, active = true)