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

Commit af694e91 authored by Evan Laird's avatar Evan Laird
Browse files

[mobile] Represent invalid subIds as null

MobileConnectionsRepository.defaultDataSubId was allowing
INVALID_SUBSCRIPTION_ID to be propagated downstream, which is kind of
wrong. The only reason we would represent that value was because reading
the int from the broadcast intent wants to have a default value.

This change turns INVALID_SUBSCRIPTION_ID to null downstream, and adds
the necessary changes to support it elsewhere.

Test: StatusBarOperatorNameViewModelTest
Test: MobileConnectionsRepositoryTest
Test: all tets statusbar/pipeline/mobile
Bug: 388834614
Flag: EXEMPT bugfix
Change-Id: I7898aa304b4f2f6b58a88567ed5d42abd65a36f3
parent d1765c39
Loading
Loading
Loading
Loading
+13 −4
Original line number Diff line number Diff line
@@ -39,14 +39,12 @@ class StatusBarOperatorNameViewModelTest : SysuiTestCase() {
        kosmos.runTest {
            val intr1 = fakeMobileIconsInteractor.getMobileConnectionInteractorForSubId(1)
            val intr2 = fakeMobileIconsInteractor.getMobileConnectionInteractorForSubId(2)
            val invalidIntr = fakeMobileIconsInteractor.getMobileConnectionInteractorForSubId(-1)

            // GIVEN default data subId is 1
            fakeMobileIconsInteractor.defaultDataSubId.value = 1

            intr1.carrierName.value = "Test Name 1"
            intr2.carrierName.value = "Test Name 2"
            invalidIntr.carrierName.value = "default network name"

            val latest by collectLastValue(underTest.operatorName)

@@ -56,8 +54,19 @@ class StatusBarOperatorNameViewModelTest : SysuiTestCase() {

            assertThat(latest).isEqualTo("Test Name 2")

            fakeMobileIconsInteractor.defaultDataSubId.value = -1
            fakeMobileIconsInteractor.defaultDataSubId.value = null

            assertThat(latest).isEqualTo("default network name")
            assertThat(latest).isNull()
        }

    @Test
    fun operatorName_noDefaultDataSubId_null() =
        kosmos.runTest {
            // GIVEN defaultDataSubId is null
            fakeMobileIconsInteractor.defaultDataSubId.value = null

            val latest by collectLastValue(underTest.operatorName)

            assertThat(latest).isNull()
        }
}
+5 −2
Original line number Diff line number Diff line
@@ -34,6 +34,9 @@ interface CarrierConfigRepository {
     */
    suspend fun startObservingCarrierConfigUpdates()

    /** Gets a cached [SystemUiCarrierConfig], or creates a new one which will track the defaults */
    fun getOrCreateConfigForSubId(subId: Int): SystemUiCarrierConfig
    /**
     * Gets a cached [SystemUiCarrierConfig], or creates a new one which will track the defaults. A
     * null [maybeSubId] will return the default carrier config.
     */
    fun getOrCreateConfigForSubId(maybeSubId: Int?): SystemUiCarrierConfig
}
+6 −2
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.content.IntentFilter
import android.os.PersistableBundle
import android.telephony.CarrierConfigManager
import android.telephony.SubscriptionManager
import android.telephony.SubscriptionManager.INVALID_SUBSCRIPTION_ID
import android.util.SparseArray
import androidx.annotation.VisibleForTesting
import androidx.core.util.getOrElse
@@ -51,7 +52,7 @@ constructor(
    private val defaultConfig: PersistableBundle by lazy { CarrierConfigManager.getDefaultConfig() }
    // Used for logging the default config in the dumpsys
    private val defaultConfigForLogs: SystemUiCarrierConfig by lazy {
        SystemUiCarrierConfig(-1, defaultConfig)
        SystemUiCarrierConfig(INVALID_SUBSCRIPTION_ID, defaultConfig)
    }

    private val configs = SparseArray<SystemUiCarrierConfig>()
@@ -89,7 +90,10 @@ constructor(
        configToUpdate.processNewCarrierConfig(config)
    }

    override fun getOrCreateConfigForSubId(subId: Int): SystemUiCarrierConfig {
    override fun getOrCreateConfigForSubId(maybeSubId: Int?): SystemUiCarrierConfig {
        // See CarrierConfigManager#getConfigForSubId(), passing INVALID_SUBSCRIPTION_ID yields
        // the default carrier config
        val subId = maybeSubId ?: INVALID_SUBSCRIPTION_ID
        return configs.getOrElse(subId) {
            val config = SystemUiCarrierConfig(subId, defaultConfig)
            val carrierConfig = carrierConfigManager?.getConfigForSubId(subId)
+2 −2
Original line number Diff line number Diff line
@@ -48,8 +48,8 @@ interface MobileConnectionsRepository {
     */
    val activeSubChangedInGroupEvent: Flow<Unit>

    /** Tracks [SubscriptionManager.getDefaultDataSubscriptionId] */
    val defaultDataSubId: StateFlow<Int>
    /** Tracks [SubscriptionManager.getDefaultDataSubscriptionId]. Null if there is no default */
    val defaultDataSubId: StateFlow<Int?>

    /**
     * True if the default network connection is a mobile-like connection and false otherwise.
+1 −1
Original line number Diff line number Diff line
@@ -164,7 +164,7 @@ constructor(

    override fun getIsAnySimSecure(): Boolean = activeRepo.value.getIsAnySimSecure()

    override val defaultDataSubId: StateFlow<Int> =
    override val defaultDataSubId: StateFlow<Int?> =
        activeRepo
            .flatMapLatest { it.defaultDataSubId }
            .stateIn(scope, SharingStarted.WhileSubscribed(), realRepository.defaultDataSubId.value)
Loading