From fc08b462caca172ee432940d9db9da65640e8824 Mon Sep 17 00:00:00 2001 From: Caitlin Shkuratov Date: Thu, 26 Jan 2023 22:02:17 +0000 Subject: [PATCH] [SB Refactor] Add content descriptions for the mobile triangle. This mirrors `SignalController#getContentDescription`, which is called from `MobileSignalController#notifyListeners`. Bug: 238425913 Test: manual: Verified content description updates correctly using demo mode Test: atest MobileIconViewModelTest Change-Id: I2f1f603fd6b0d1257d90fb6addb1403847438415 --- .../mobile/ui/binder/MobileIconBinder.kt | 7 ++++ .../ui/viewmodel/MobileIconViewModel.kt | 20 +++++++++++ .../ui/viewmodel/MobileIconViewModelTest.kt | 35 +++++++++++++++++++ 3 files changed, 62 insertions(+) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/ui/binder/MobileIconBinder.kt b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/ui/binder/MobileIconBinder.kt index 3e81c7c7cefda..a4b2abcf7385c 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/ui/binder/MobileIconBinder.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/ui/binder/MobileIconBinder.kt @@ -29,6 +29,7 @@ import androidx.lifecycle.Lifecycle import androidx.lifecycle.repeatOnLifecycle import com.android.settingslib.graph.SignalDrawable import com.android.systemui.R +import com.android.systemui.common.ui.binder.ContentDescriptionViewBinder import com.android.systemui.common.ui.binder.IconViewBinder import com.android.systemui.lifecycle.repeatWhenAttached import com.android.systemui.statusbar.StatusBarIconView @@ -97,6 +98,12 @@ object MobileIconBinder { } } + launch { + viewModel.contentDescription.distinctUntilChanged().collect { + ContentDescriptionViewBinder.bind(it, view) + } + } + // Set the network type icon launch { viewModel.networkTypeIcon.distinctUntilChanged().collect { dataTypeId -> 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 5e9356163e6e5..9e2024afda8f3 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 @@ -16,6 +16,8 @@ package com.android.systemui.statusbar.pipeline.mobile.ui.viewmodel +import com.android.settingslib.AccessibilityContentDescriptions.PHONE_SIGNAL_STRENGTH +import com.android.settingslib.AccessibilityContentDescriptions.PHONE_SIGNAL_STRENGTH_NONE import com.android.settingslib.graph.SignalDrawable import com.android.systemui.common.shared.model.ContentDescription import com.android.systemui.common.shared.model.Icon @@ -43,6 +45,7 @@ interface MobileIconViewModelCommon { val subscriptionId: Int /** An int consumable by [SignalDrawable] for display */ val iconId: Flow + val contentDescription: Flow val roaming: Flow /** The RAT icon (LTE, 3G, 5G, etc) to be displayed. Null if we shouldn't show anything */ val networkTypeIcon: Flow @@ -102,6 +105,23 @@ constructor( .stateIn(scope, SharingStarted.WhileSubscribed(), initial) } + override val contentDescription: Flow = run { + val initial = ContentDescription.Resource(PHONE_SIGNAL_STRENGTH_NONE) + combine( + iconInteractor.level, + iconInteractor.isInService, + ) { level, isInService -> + val resId = + when { + isInService -> PHONE_SIGNAL_STRENGTH[level] + else -> PHONE_SIGNAL_STRENGTH_NONE + } + ContentDescription.Resource(resId) + } + .distinctUntilChanged() + .stateIn(scope, SharingStarted.WhileSubscribed(), initial) + } + private val showNetworkTypeIcon: Flow = combine( iconInteractor.isDataConnected, 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 a24e29aebc1ef..b91a4df6ddda2 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 @@ -17,6 +17,8 @@ package com.android.systemui.statusbar.pipeline.mobile.ui.viewmodel 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.graph.SignalDrawable import com.android.settingslib.mobile.TelephonyIcons.THREE_G import com.android.systemui.SysuiTestCase @@ -121,6 +123,39 @@ class MobileIconViewModelTest : SysuiTestCase() { job.cancel() } + @Test + fun contentDescription_notInService_usesNoPhone() = + testScope.runTest { + var latest: ContentDescription? = null + val job = underTest.contentDescription.onEach { latest = it }.launchIn(this) + + interactor.isInService.value = false + + assertThat((latest as ContentDescription.Resource).res) + .isEqualTo(PHONE_SIGNAL_STRENGTH_NONE) + + job.cancel() + } + + @Test + fun contentDescription_inService_usesLevel() = + testScope.runTest { + var latest: ContentDescription? = null + val job = underTest.contentDescription.onEach { latest = it }.launchIn(this) + + interactor.isInService.value = true + + interactor.level.value = 2 + assertThat((latest as ContentDescription.Resource).res) + .isEqualTo(PHONE_SIGNAL_STRENGTH[2]) + + interactor.level.value = 0 + assertThat((latest as ContentDescription.Resource).res) + .isEqualTo(PHONE_SIGNAL_STRENGTH[0]) + + job.cancel() + } + @Test fun networkType_dataEnabled_groupIsRepresented() = testScope.runTest {