Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fc08b462 authored by Caitlin Shkuratov's avatar Caitlin Shkuratov
Browse files

[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
parent 633510be
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -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 ->
+20 −0
Original line number Diff line number Diff line
@@ -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,
+35 −0
Original line number Diff line number Diff line
@@ -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 {