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

Commit 5af6802f authored by Olivier St-Onge's avatar Olivier St-Onge Committed by Android (Google) Code Review
Browse files

Merge changes I6e5eaa39,I6df2e609 into main

* changes:
  Collect the icon tint from the StateFlow
  Only show the stacked mobile icon when all individual mobile icons are visible
parents 15c63469 1129650e
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -97,7 +97,7 @@ class MobileIconInteractorKairosAdapterTest : MobileIconInteractorTestBase() {
                    }
                    .asIncremental()
                    .applyLatestSpecForKey(),
            isStackable = interactor.isStackable.toState(),
            isStackable = interactor.isStackable.toState(false),
            activeDataConnectionHasDataEnabled =
                interactor.activeDataConnectionHasDataEnabled.toState(),
            activeDataIconInteractor =
+40 −3
Original line number Diff line number Diff line
@@ -60,7 +60,6 @@ class MobileIconsViewModelTest : SysuiTestCase() {
    private val interactor = FakeMobileIconsInteractor(FakeMobileMappingsProxy(), mock())

    private lateinit var airplaneModeInteractor: AirplaneModeInteractor
    @Mock private lateinit var constants: ConnectivityConstants
    @Mock private lateinit var logger: MobileViewLogger
    @Mock private lateinit var verboseLogger: VerboseMobileViewLogger

@@ -84,7 +83,10 @@ class MobileIconsViewModelTest : SysuiTestCase() {
                verboseLogger,
                interactor,
                airplaneModeInteractor,
                constants,
                object : ConnectivityConstants {
                    override val hasDataCapabilities = true
                    override val shouldShowActivityConfig = false
                },
                testScope.backgroundScope,
            )

@@ -349,7 +351,42 @@ class MobileIconsViewModelTest : SysuiTestCase() {
            // WHEN sub2 becomes last and sub2 has a network type icon
            interactor.filteredSubscriptions.value = listOf(SUB_1, SUB_2)

            // THEN the flow updates
            assertThat(latest).isTrue()
            job.cancel()
        }

    @Test
    fun isStackable_apmEnabled_false() =
        testScope.runTest {
            var latest: Boolean? = null
            val job = underTest.isStackable.onEach { latest = it }.launchIn(this)

            // Set the interactor to true to test APM
            interactor.isStackable.value = true

            // Enable APM
            airplaneModeInteractor.setIsAirplaneMode(true)

            interactor.filteredSubscriptions.value = listOf(SUB_1, SUB_2)

            assertThat(latest).isFalse()
            job.cancel()
        }

    @Test
    fun isStackable_apmDisabled_true() =
        testScope.runTest {
            var latest: Boolean? = null
            val job = underTest.isStackable.onEach { latest = it }.launchIn(this)

            // Set the interactor to true to test APM
            interactor.isStackable.value = true

            // Disable APM
            airplaneModeInteractor.setIsAirplaneMode(false)

            interactor.filteredSubscriptions.value = listOf(SUB_1, SUB_2)

            assertThat(latest).isTrue()

            job.cancel()
+12 −13
Original line number Diff line number Diff line
@@ -84,7 +84,7 @@ interface MobileIconsInteractor {
    val icons: StateFlow<List<MobileIconInteractor>>

    /** Whether the mobile icons can be stacked vertically. */
    val isStackable: StateFlow<Boolean>
    val isStackable: Flow<Boolean>

    /**
     * Observable for the subscriptionId of the current mobile data connection. Null if we don't
@@ -323,7 +323,6 @@ constructor(
        } else {
            flowOf(false)
        }
            .stateIn(scope, SharingStarted.WhileSubscribed(), false)

    /**
     * Copied from the old pipeline. We maintain a 2s period of time where we will keep the
+5 −2
Original line number Diff line number Diff line
@@ -18,9 +18,11 @@ package com.android.systemui.statusbar.pipeline.mobile.ui.binder

import androidx.compose.material3.LocalContentColor
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.getValue
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.ViewCompositionStrategy
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.lifecycle.repeatOnLifecycle
import com.android.systemui.Flags
import com.android.systemui.kairos.ExperimentalKairosApi
@@ -48,7 +50,7 @@ object StackedMobileIconBinder {
        return SingleBindableStatusBarComposeIconView.withDefaultBinding(
            view = view,
            shouldBeVisible = { mobileIconsViewModel.isStackable.value },
        ) { _, tint ->
        ) { _, tintFlow ->
            view.repeatWhenAttached {
                repeatOnLifecycle(Lifecycle.State.STARTED) {
                    view.composeView.apply {
@@ -66,8 +68,9 @@ object StackedMobileIconBinder {
                                        viewModelFactory.create()
                                    }
                                }
                            val tint by tintFlow.collectAsStateWithLifecycle()
                            if (viewModel.isIconVisible) {
                                CompositionLocalProvider(LocalContentColor provides Color(tint())) {
                                CompositionLocalProvider(LocalContentColor provides Color(tint)) {
                                    StackedMobileIcon(viewModel)
                                }
                            }
+13 −1
Original line number Diff line number Diff line
@@ -36,6 +36,8 @@ import kotlinx.coroutines.Job
import kotlinx.coroutines.cancel
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.map
@@ -99,7 +101,17 @@ constructor(
            }
            .stateIn(scope, SharingStarted.WhileSubscribed(), false)

    val isStackable: StateFlow<Boolean> = interactor.isStackable
    /** Whether all of [mobileSubViewModels] are visible or not. */
    private val iconsAreAllVisible =
        mobileSubViewModels.flatMapLatest { viewModels ->
            combine(viewModels.map { it.isVisible }) { isVisibleArray -> isVisibleArray.all { it } }
        }

    val isStackable: StateFlow<Boolean> =
        combine(iconsAreAllVisible, interactor.isStackable) { isVisible, isStackable ->
                isVisible && isStackable
            }
            .stateIn(scope, SharingStarted.WhileSubscribed(), false)

    init {
        scope.launch { subscriptionIdsFlow.collect { invalidateCaches(it) } }
Loading