Merge "[SB Refactor] Add content descriptions for the mobile triangle." into tm-qpr-dev

This commit is contained in:
Caitlin Shkuratov
2023-02-01 15:07:31 +00:00
committed by Android (Google) Code Review
3 changed files with 62 additions and 0 deletions

View File

@@ -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 ->

View File

@@ -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<Int>
val contentDescription: Flow<ContentDescription>
val roaming: Flow<Boolean>
/** The RAT icon (LTE, 3G, 5G, etc) to be displayed. Null if we shouldn't show anything */
val networkTypeIcon: Flow<Icon?>
@@ -102,6 +105,23 @@ constructor(
.stateIn(scope, SharingStarted.WhileSubscribed(), initial)
}
override val contentDescription: Flow<ContentDescription> = 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<Boolean> =
combine(
iconInteractor.isDataConnected,

View File

@@ -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 {