From 18271d623220377a1dbf5dd15dffb7ce89a387b9 Mon Sep 17 00:00:00 2001 From: Evan Laird Date: Thu, 9 Mar 2023 14:28:25 -0500 Subject: [PATCH] [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 --- .../prod/MobileConnectionRepositoryImpl.kt | 16 +++++----- .../prod/MobileConnectionRepositoryTest.kt | 30 ++++++++++++++++++- 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/MobileConnectionRepositoryImpl.kt b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/MobileConnectionRepositoryImpl.kt index b0bc2a571b197..79e5b3eba4a8e 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/MobileConnectionRepositoryImpl.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/MobileConnectionRepositoryImpl.kt @@ -245,20 +245,18 @@ class MobileConnectionRepositoryImpl( callbackEvents .filterIsInstance() .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) diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/MobileConnectionRepositoryTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/MobileConnectionRepositoryTest.kt index 4ce422685dfa1..90d602145223a 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/MobileConnectionRepositoryTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/MobileConnectionRepositoryTest.kt @@ -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() + val overrideType = OVERRIDE_NETWORK_TYPE_NONE val type = NETWORK_TYPE_LTE val expected = DefaultNetworkType(mobileMappings.toIconKey(type)) - val ti = mock().also { whenever(it.networkType).thenReturn(type) } + val ti = + mock().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() + val unknown = NETWORK_TYPE_UNKNOWN + val type = OVERRIDE_NETWORK_TYPE_LTE_CA + val expected = OverrideNetworkType(mobileMappings.toIconKeyOverride(type)) + val ti = + mock().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 {