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

Commit 9e7ee45e authored by Evan Laird's avatar Evan Laird
Browse files

[Sb refactor] Filter out -1 values for ERI

TelephonyManager.getCdmaEnhancedRoamingIndicatorNumber will return -1
before the service is available. Filter these out so we don't
accidentally consider the connection to be `cdmaRoaming` when actually
we don't have that information yet.

Test: MobileConnectionRepositoryTest
Bug: 269040632
Change-Id: I5d7762b7a671ef1ab48130eb051abcba04c231eb
parent 049f8dc0
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -28,7 +28,8 @@ import android.telephony.TelephonyCallback
import android.telephony.TelephonyDisplayInfo
import android.telephony.TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NONE
import android.telephony.TelephonyManager
import android.telephony.TelephonyManager.ERI_OFF
import android.telephony.TelephonyManager.ERI_FLASH
import android.telephony.TelephonyManager.ERI_ON
import android.telephony.TelephonyManager.EXTRA_SUBSCRIPTION_ID
import android.telephony.TelephonyManager.NETWORK_TYPE_UNKNOWN
import com.android.settingslib.Utils
@@ -282,7 +283,10 @@ class MobileConnectionRepositoryImpl(

    override val cdmaRoaming: StateFlow<Boolean> =
        telephonyPollingEvent
            .mapLatest { telephonyManager.cdmaEnhancedRoamingIndicatorDisplayNumber != ERI_OFF }
            .mapLatest {
                val cdmaEri = telephonyManager.cdmaEnhancedRoamingIndicatorDisplayNumber
                cdmaEri == ERI_ON || cdmaEri == ERI_FLASH
            }
            .stateIn(scope, SharingStarted.WhileSubscribed(), false)

    override val networkName: StateFlow<NetworkNameModel> =
+24 −0
Original line number Diff line number Diff line
@@ -514,6 +514,30 @@ class MobileConnectionRepositoryTest : SysuiTestCase() {
            job.cancel()
        }

    /**
     * [TelephonyManager.getCdmaEnhancedRoamingIndicatorDisplayNumber] returns -1 if the service is
     * not running or if there is an error while retrieving the cdma ERI
     */
    @Test
    fun cdmaRoaming_ignoresNegativeOne() =
        runBlocking(IMMEDIATE) {
            var latest: Boolean? = null
            val job = underTest.cdmaRoaming.onEach { latest = it }.launchIn(this)

            val serviceState = ServiceState()
            serviceState.roaming = false

            val cb = getTelephonyCallbackForType<ServiceStateListener>()

            // CDMA roaming is unavailable (-1), GSM roaming is off
            whenever(telephonyManager.cdmaEnhancedRoamingIndicatorDisplayNumber).thenReturn(-1)
            cb.onServiceStateChanged(serviceState)

            assertThat(latest).isFalse()

            job.cancel()
        }

    @Test
    fun `roaming - gsm - queries service state`() =
        runBlocking(IMMEDIATE) {