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

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

[Sb refactor] Add Utils.isInService to mobile pipeline

This CL just adds the backend to track the Utils.isInService bit that
the old pipeline was also tracking. It is tracked in exactly the same
way as before, but with a TODO to clarify our usage in the future.

Test: MobileConnectionRepositoryTest
Bug: 238425913
Bug: 263167683
Change-Id: I9541a9148d8cb44a5e9ebeee1c824c2402f63b5a
parent 47c9c93e
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -51,6 +51,16 @@ data class MobileConnectionModel(
     */
    val operatorAlphaShort: String? = null,

    /**
     * TODO (b/263167683): Clarify this field
     *
     * This check comes from [com.android.settingslib.Utils.isInService]. It is intended to be a
     * mapping from a ServiceState to a notion of connectivity. Notably, it will consider a
     * connection to be in-service if either the voice registration state is IN_SERVICE or the data
     * registration state is IN_SERVICE and NOT IWLAN.
     */
    val isInService: Boolean = false,

    /** Fields below from [SignalStrengthsListener.onSignalStrengthsChanged] */
    val isGsm: Boolean = false,
    @IntRange(from = 0, to = 4)
@@ -99,6 +109,10 @@ data class MobileConnectionModel(
            row.logChange(COL_OPERATOR, operatorAlphaShort)
        }

        if (prevVal.isInService != isInService) {
            row.logChange(COL_IS_IN_SERVICE, isInService)
        }

        if (prevVal.isGsm != isGsm) {
            row.logChange(COL_IS_GSM, isGsm)
        }
@@ -129,6 +143,7 @@ data class MobileConnectionModel(
        row.logChange(COL_EMERGENCY, isEmergencyOnly)
        row.logChange(COL_ROAMING, isRoaming)
        row.logChange(COL_OPERATOR, operatorAlphaShort)
        row.logChange(COL_IS_IN_SERVICE, isInService)
        row.logChange(COL_IS_GSM, isGsm)
        row.logChange(COL_CDMA_LEVEL, cdmaLevel)
        row.logChange(COL_PRIMARY_LEVEL, primaryLevel)
@@ -141,6 +156,7 @@ data class MobileConnectionModel(
        const val COL_EMERGENCY = "EmergencyOnly"
        const val COL_ROAMING = "Roaming"
        const val COL_OPERATOR = "OperatorName"
        const val COL_IS_IN_SERVICE = "IsInService"
        const val COL_IS_GSM = "IsGsm"
        const val COL_CDMA_LEVEL = "CdmaLevel"
        const val COL_PRIMARY_LEVEL = "PrimaryLevel"
+1 −0
Original line number Diff line number Diff line
@@ -247,6 +247,7 @@ constructor(
        return MobileConnectionModel(
            isEmergencyOnly = false, // TODO(b/261029387): not yet supported
            isRoaming = roaming,
            isInService = (level ?: 0) > 0,
            isGsm = false, // TODO(b/261029387): not yet supported
            cdmaLevel = level ?: 0,
            primaryLevel = level ?: 0,
+2 −0
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import android.telephony.TelephonyManager
import android.telephony.TelephonyManager.ERI_OFF
import android.telephony.TelephonyManager.EXTRA_SUBSCRIPTION_ID
import android.telephony.TelephonyManager.NETWORK_TYPE_UNKNOWN
import com.android.settingslib.Utils
import com.android.systemui.broadcast.BroadcastDispatcher
import com.android.systemui.common.coroutine.ConflatedCallbackFlow.conflatedCallbackFlow
import com.android.systemui.dagger.qualifiers.Application
@@ -117,6 +118,7 @@ class MobileConnectionRepositoryImpl(
                                    isEmergencyOnly = serviceState.isEmergencyOnly,
                                    isRoaming = serviceState.roaming,
                                    operatorAlphaShort = serviceState.operatorAlphaShort,
                                    isInService = Utils.isInService(serviceState),
                                )
                            trySend(state)
                        }
+53 −2
Original line number Diff line number Diff line
@@ -20,7 +20,10 @@ import android.content.Intent
import android.os.UserHandle
import android.provider.Settings
import android.telephony.CellSignalStrengthCdma
import android.telephony.NetworkRegistrationInfo
import android.telephony.ServiceState
import android.telephony.ServiceState.STATE_IN_SERVICE
import android.telephony.ServiceState.STATE_OUT_OF_SERVICE
import android.telephony.SignalStrength
import android.telephony.SubscriptionInfo
import android.telephony.TelephonyCallback
@@ -47,7 +50,6 @@ import android.telephony.TelephonyManager.EXTRA_SHOW_SPN
import android.telephony.TelephonyManager.EXTRA_SPN
import android.telephony.TelephonyManager.EXTRA_SUBSCRIPTION_ID
import android.telephony.TelephonyManager.NETWORK_TYPE_LTE
import android.telephony.TelephonyManager.NETWORK_TYPE_UNKNOWN
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.log.table.TableLogBuffer
@@ -302,7 +304,6 @@ class MobileConnectionRepositoryTest : SysuiTestCase() {
            var latest: MobileConnectionModel? = null
            val job = underTest.connectionInfo.onEach { latest = it }.launchIn(this)

            val type = NETWORK_TYPE_UNKNOWN
            val expected = UnknownNetworkType

            assertThat(latest?.resolvedNetworkType).isEqualTo(expected)
@@ -590,6 +591,56 @@ class MobileConnectionRepositoryTest : SysuiTestCase() {
            job.cancel()
        }

    @Test
    fun `connection model - isInService - not iwlan`() =
        runBlocking(IMMEDIATE) {
            var latest: Boolean? = null
            val job = underTest.connectionInfo.onEach { latest = it.isInService }.launchIn(this)

            val serviceState = ServiceState()
            serviceState.voiceRegState = STATE_IN_SERVICE
            serviceState.dataRegState = STATE_IN_SERVICE

            getTelephonyCallbackForType<ServiceStateListener>().onServiceStateChanged(serviceState)

            assertThat(latest).isTrue()

            serviceState.voiceRegState = STATE_OUT_OF_SERVICE
            getTelephonyCallbackForType<ServiceStateListener>().onServiceStateChanged(serviceState)
            assertThat(latest).isTrue()

            serviceState.dataRegState = STATE_OUT_OF_SERVICE
            getTelephonyCallbackForType<ServiceStateListener>().onServiceStateChanged(serviceState)
            assertThat(latest).isFalse()

            job.cancel()
        }

    @Test
    fun `connection model - isInService - is iwlan - voice out of service - data in service`() =
        runBlocking(IMMEDIATE) {
            var latest: Boolean? = null
            val job = underTest.connectionInfo.onEach { latest = it.isInService }.launchIn(this)

            // Mock the service state here so we can make it specifically IWLAN
            val serviceState: ServiceState = mock()
            whenever(serviceState.state).thenReturn(STATE_OUT_OF_SERVICE)
            whenever(serviceState.dataRegistrationState).thenReturn(STATE_IN_SERVICE)

            // See [com.android.settingslib.Utils.isInService] for more info. This is one way to
            // make the network look like IWLAN
            val networkRegWlan: NetworkRegistrationInfo = mock()
            whenever(serviceState.getNetworkRegistrationInfo(any(), any()))
                .thenReturn(networkRegWlan)
            whenever(networkRegWlan.registrationState)
                .thenReturn(NetworkRegistrationInfo.REGISTRATION_STATE_HOME)

            getTelephonyCallbackForType<ServiceStateListener>().onServiceStateChanged(serviceState)
            assertThat(latest).isFalse()

            job.cancel()
        }

    private fun getTelephonyCallbacks(): List<TelephonyCallback> {
        val callbackCaptor = argumentCaptor<TelephonyCallback>()
        Mockito.verify(telephonyManager).registerTelephonyCallback(any(), callbackCaptor.capture())