Add DATA_UNKNOWN to the data state parsing

Test: atest MobileConnectionRepositoryTest
Bug: 249790009
Fixes: 260182454
Change-Id: Ice240ec2168dc9d470c1145709c7633a2738a9c6
This commit is contained in:
Evan Laird
2022-11-30 16:25:33 -05:00
parent 6b37d71772
commit 5f941ad1b1
2 changed files with 20 additions and 1 deletions

View File

@@ -20,6 +20,7 @@ import android.telephony.TelephonyManager.DATA_CONNECTED
import android.telephony.TelephonyManager.DATA_CONNECTING
import android.telephony.TelephonyManager.DATA_DISCONNECTED
import android.telephony.TelephonyManager.DATA_DISCONNECTING
import android.telephony.TelephonyManager.DATA_UNKNOWN
import android.telephony.TelephonyManager.DataState
/** Internal enum representation of the telephony data connection states */
@@ -28,6 +29,7 @@ enum class DataConnectionState(@DataState val dataState: Int) {
Connecting(DATA_CONNECTING),
Disconnected(DATA_DISCONNECTED),
Disconnecting(DATA_DISCONNECTING),
Unknown(DATA_UNKNOWN),
}
fun @receiver:DataState Int.toDataConnectionType(): DataConnectionState =
@@ -36,5 +38,6 @@ fun @receiver:DataState Int.toDataConnectionType(): DataConnectionState =
DATA_CONNECTING -> DataConnectionState.Connecting
DATA_DISCONNECTED -> DataConnectionState.Disconnected
DATA_DISCONNECTING -> DataConnectionState.Disconnecting
else -> throw IllegalArgumentException("unknown data state received")
DATA_UNKNOWN -> DataConnectionState.Unknown
else -> throw IllegalArgumentException("unknown data state received $this")
}

View File

@@ -31,6 +31,7 @@ import android.telephony.TelephonyManager.DATA_CONNECTED
import android.telephony.TelephonyManager.DATA_CONNECTING
import android.telephony.TelephonyManager.DATA_DISCONNECTED
import android.telephony.TelephonyManager.DATA_DISCONNECTING
import android.telephony.TelephonyManager.DATA_UNKNOWN
import android.telephony.TelephonyManager.NETWORK_TYPE_LTE
import android.telephony.TelephonyManager.NETWORK_TYPE_UNKNOWN
import androidx.test.filters.SmallTest
@@ -220,6 +221,21 @@ class MobileConnectionRepositoryTest : SysuiTestCase() {
job.cancel()
}
@Test
fun testFlowForSubId_dataConnectionState_unknown() =
runBlocking(IMMEDIATE) {
var latest: MobileSubscriptionModel? = null
val job = underTest.subscriptionModelFlow.onEach { latest = it }.launchIn(this)
val callback =
getTelephonyCallbackForType<TelephonyCallback.DataConnectionStateListener>()
callback.onDataConnectionStateChanged(DATA_UNKNOWN, 200 /* unused */)
assertThat(latest?.dataConnectionState).isEqualTo(DataConnectionState.Unknown)
job.cancel()
}
@Test
fun testFlowForSubId_dataActivity() =
runBlocking(IMMEDIATE) {