[Sb refactor] Handle telephony display info with only an override

Manual testing (and many bugreports) show that sometimes we calculate a
network type of `Unknown` when it should actually be some form of
`OverrideNetworkType`. It is possible that this is due to differences in the way that the new pipeline calculates the icon group to use. If the
`TelephonyDisplayInfo` objects have a value of
`NETWORK_TYPE_UNKNOWN` for the `networkType` field but still have a
valid `overrideNetworkType`, then we would incorrectly calculate `Unknown` when we should use the override type.

Test: MobileConnectionRepositoryTest
Bug: 272784824
Change-Id: Ieaf30071cf2a0082dc005dfc8e8332c0a7456df6
This commit is contained in:
Evan Laird
2023-03-09 14:28:25 -05:00
parent 64062c3106
commit 18271d6232
2 changed files with 36 additions and 10 deletions

View File

@@ -245,20 +245,18 @@ class MobileConnectionRepositoryImpl(
callbackEvents
.filterIsInstance<CallbackEvent.OnDisplayInfoChanged>()
.map {
if (it.telephonyDisplayInfo.networkType == NETWORK_TYPE_UNKNOWN) {
UnknownNetworkType
} else if (
it.telephonyDisplayInfo.overrideNetworkType == OVERRIDE_NETWORK_TYPE_NONE
) {
DefaultNetworkType(
mobileMappingsProxy.toIconKey(it.telephonyDisplayInfo.networkType)
)
} else {
if (it.telephonyDisplayInfo.overrideNetworkType != OVERRIDE_NETWORK_TYPE_NONE) {
OverrideNetworkType(
mobileMappingsProxy.toIconKeyOverride(
it.telephonyDisplayInfo.overrideNetworkType
)
)
} else if (it.telephonyDisplayInfo.networkType != NETWORK_TYPE_UNKNOWN) {
DefaultNetworkType(
mobileMappingsProxy.toIconKey(it.telephonyDisplayInfo.networkType)
)
} else {
UnknownNetworkType
}
}
.stateIn(scope, SharingStarted.WhileSubscribed(), UnknownNetworkType)

View File

@@ -29,6 +29,7 @@ import android.telephony.TelephonyCallback.DataActivityListener
import android.telephony.TelephonyCallback.ServiceStateListener
import android.telephony.TelephonyDisplayInfo
import android.telephony.TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_LTE_CA
import android.telephony.TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NONE
import android.telephony.TelephonyManager
import android.telephony.TelephonyManager.DATA_ACTIVITY_DORMANT
import android.telephony.TelephonyManager.DATA_ACTIVITY_IN
@@ -414,9 +415,14 @@ class MobileConnectionRepositoryTest : SysuiTestCase() {
val job = underTest.resolvedNetworkType.onEach { latest = it }.launchIn(this)
val callback = getTelephonyCallbackForType<TelephonyCallback.DisplayInfoListener>()
val overrideType = OVERRIDE_NETWORK_TYPE_NONE
val type = NETWORK_TYPE_LTE
val expected = DefaultNetworkType(mobileMappings.toIconKey(type))
val ti = mock<TelephonyDisplayInfo>().also { whenever(it.networkType).thenReturn(type) }
val ti =
mock<TelephonyDisplayInfo>().also {
whenever(it.overrideNetworkType).thenReturn(overrideType)
whenever(it.networkType).thenReturn(type)
}
callback.onDisplayInfoChanged(ti)
assertThat(latest).isEqualTo(expected)
@@ -445,6 +451,28 @@ class MobileConnectionRepositoryTest : SysuiTestCase() {
job.cancel()
}
@Test
fun networkType_unknownNetworkWithOverride_usesOverrideKey() =
testScope.runTest {
var latest: ResolvedNetworkType? = null
val job = underTest.resolvedNetworkType.onEach { latest = it }.launchIn(this)
val callback = getTelephonyCallbackForType<TelephonyCallback.DisplayInfoListener>()
val unknown = NETWORK_TYPE_UNKNOWN
val type = OVERRIDE_NETWORK_TYPE_LTE_CA
val expected = OverrideNetworkType(mobileMappings.toIconKeyOverride(type))
val ti =
mock<TelephonyDisplayInfo>().also {
whenever(it.networkType).thenReturn(unknown)
whenever(it.overrideNetworkType).thenReturn(type)
}
callback.onDisplayInfoChanged(ti)
assertThat(latest).isEqualTo(expected)
job.cancel()
}
@Test
fun dataEnabled_initial_false() =
testScope.runTest {