From bd2eb04ed6016f356ec84ca0535f4d9d0f56c2b3 Mon Sep 17 00:00:00 2001 From: Caitlin Shkuratov Date: Mon, 27 Mar 2023 16:27:01 +0000 Subject: [PATCH] [SB Refactor] Don't show RAT icon if the resource ID is invalid. Fixes: 275356714 Test: force alwaysShowDataRatIcon to true and have an invalid subscription -> verify no extra space between wifi and mobile triangle Test: atest MobileIconViewModelTest Change-Id: I2c6792c37dc50244428b8d5416604e2f8427ee49 --- .../mobile/ui/viewmodel/MobileIconViewModel.kt | 5 ++++- .../ui/viewmodel/MobileIconViewModelTest.kt | 18 +++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/ui/viewmodel/MobileIconViewModel.kt b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/ui/viewmodel/MobileIconViewModel.kt index 0fd007cf40ef5..62bc27f9dd4e3 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/ui/viewmodel/MobileIconViewModel.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/ui/viewmodel/MobileIconViewModel.kt @@ -170,7 +170,10 @@ constructor( if (networkTypeIconGroup.dataContentDescription != 0) ContentDescription.Resource(networkTypeIconGroup.dataContentDescription) else null - val icon = Icon.Resource(networkTypeIconGroup.dataType, desc) + val icon = + if (networkTypeIconGroup.dataType != 0) + Icon.Resource(networkTypeIconGroup.dataType, desc) + else null return@combine when { !shouldShow -> null else -> icon diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/ui/viewmodel/MobileIconViewModelTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/ui/viewmodel/MobileIconViewModelTest.kt index 8ea8f87e6affa..1593e5c735a55 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/ui/viewmodel/MobileIconViewModelTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/ui/viewmodel/MobileIconViewModelTest.kt @@ -20,6 +20,7 @@ import androidx.test.filters.SmallTest import com.android.settingslib.AccessibilityContentDescriptions.PHONE_SIGNAL_STRENGTH import com.android.settingslib.AccessibilityContentDescriptions.PHONE_SIGNAL_STRENGTH_NONE import com.android.settingslib.mobile.TelephonyIcons.THREE_G +import com.android.settingslib.mobile.TelephonyIcons.UNKNOWN import com.android.systemui.SysuiTestCase import com.android.systemui.common.shared.model.ContentDescription import com.android.systemui.common.shared.model.Icon @@ -343,7 +344,7 @@ class MobileIconViewModelTest : SysuiTestCase() { fun networkType_alwaysShow_shownEvenWhenDisabled() = testScope.runTest { interactor.setIconGroup(THREE_G) - interactor.setIsDataEnabled(true) + interactor.setIsDataEnabled(false) interactor.alwaysShowDataRatIcon.value = true var latest: Icon? = null @@ -399,6 +400,21 @@ class MobileIconViewModelTest : SysuiTestCase() { job.cancel() } + @Test + fun networkType_alwaysShow_notShownWhenInvalidDataTypeIcon() = + testScope.runTest { + // The UNKNOWN icon group doesn't have a valid data type icon ID + interactor.setIconGroup(UNKNOWN) + interactor.alwaysShowDataRatIcon.value = true + + var latest: Icon? = null + val job = underTest.networkTypeIcon.onEach { latest = it }.launchIn(this) + + assertThat(latest).isNull() + + job.cancel() + } + @Test fun `network type - alwaysShow - shown when not default`() = testScope.runTest {