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

Commit 6440b41a authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "DarkIconRepository: add display id parameter" into main

parents ddbd8d06 f133c63e
Loading
Loading
Loading
Loading
+21 −42
Original line number Diff line number Diff line
@@ -110,14 +110,10 @@ class NotificationIconContainerStatusBarViewModelTest(flags: FlagsParameterizati
                lastSleepReason = WakeSleepReason.OTHER,
            )
            keyguardTransitionRepository.sendTransitionStep(
                TransitionStep(
                    transitionState = TransitionState.STARTED,
                )
                TransitionStep(transitionState = TransitionState.STARTED)
            )
            keyguardRepository.setDozeTransitionModel(
                DozeTransitionModel(
                    to = DozeStateModel.DOZE_AOD,
                )
                DozeTransitionModel(to = DozeStateModel.DOZE_AOD)
            )
            val animationsEnabled by collectLastValue(underTest.animationsEnabled)
            runCurrent()
@@ -133,14 +129,10 @@ class NotificationIconContainerStatusBarViewModelTest(flags: FlagsParameterizati
                lastSleepReason = WakeSleepReason.OTHER,
            )
            keyguardTransitionRepository.sendTransitionStep(
                TransitionStep(
                    transitionState = TransitionState.STARTED,
                )
                TransitionStep(transitionState = TransitionState.STARTED)
            )
            keyguardRepository.setDozeTransitionModel(
                DozeTransitionModel(
                    to = DozeStateModel.DOZE_PULSING,
                )
                DozeTransitionModel(to = DozeStateModel.DOZE_PULSING)
            )
            val animationsEnabled by collectLastValue(underTest.animationsEnabled)
            runCurrent()
@@ -201,9 +193,7 @@ class NotificationIconContainerStatusBarViewModelTest(flags: FlagsParameterizati
                lastSleepReason = WakeSleepReason.OTHER,
            )
            keyguardTransitionRepository.sendTransitionStep(
                TransitionStep(
                    transitionState = TransitionState.STARTED,
                )
                TransitionStep(transitionState = TransitionState.STARTED)
            )
            val animationsEnabled by collectLastValue(underTest.animationsEnabled)
            runCurrent()
@@ -216,9 +206,7 @@ class NotificationIconContainerStatusBarViewModelTest(flags: FlagsParameterizati
            val animationsEnabled by collectLastValue(underTest.animationsEnabled)

            keyguardTransitionRepository.sendTransitionStep(
                TransitionStep(
                    transitionState = TransitionState.STARTED,
                )
                TransitionStep(transitionState = TransitionState.STARTED)
            )
            keyguardRepository.setKeyguardShowing(true)
            runCurrent()
@@ -234,13 +222,10 @@ class NotificationIconContainerStatusBarViewModelTest(flags: FlagsParameterizati
    @Test
    fun iconColors_testsDarkBounds() =
        testScope.runTest {
            darkIconRepository.darkState.value =
                SysuiDarkIconDispatcher.DarkChange(
                    emptyList(),
                    0f,
                    0xAABBCC,
                )
            val iconColorsLookup by collectLastValue(underTest.iconColors)
            val displayId = 123
            darkIconRepository.darkState(displayId).value =
                SysuiDarkIconDispatcher.DarkChange(emptyList(), 0f, 0xAABBCC)
            val iconColorsLookup by collectLastValue(underTest.iconColors(displayId))
            assertThat(iconColorsLookup).isNotNull()

            val iconColors = iconColorsLookup?.iconColors(Rect())
@@ -257,13 +242,10 @@ class NotificationIconContainerStatusBarViewModelTest(flags: FlagsParameterizati
    @Test
    fun iconColors_staticDrawableColor_notInDarkTintArea() =
        testScope.runTest {
            darkIconRepository.darkState.value =
                SysuiDarkIconDispatcher.DarkChange(
                    listOf(Rect(0, 0, 5, 5)),
                    0f,
                    0xAABBCC,
                )
            val iconColorsLookup by collectLastValue(underTest.iconColors)
            val displayId = 321
            darkIconRepository.darkState(displayId).value =
                SysuiDarkIconDispatcher.DarkChange(listOf(Rect(0, 0, 5, 5)), 0f, 0xAABBCC)
            val iconColorsLookup by collectLastValue(underTest.iconColors(displayId))
            val iconColors = iconColorsLookup?.iconColors(Rect(1, 1, 4, 4))
            val staticDrawableColor = iconColors?.staticDrawableColor(Rect(6, 6, 7, 7))
            assertThat(staticDrawableColor).isEqualTo(DarkIconDispatcher.DEFAULT_ICON_TINT)
@@ -272,13 +254,10 @@ class NotificationIconContainerStatusBarViewModelTest(flags: FlagsParameterizati
    @Test
    fun iconColors_notInDarkTintArea() =
        testScope.runTest {
            darkIconRepository.darkState.value =
                SysuiDarkIconDispatcher.DarkChange(
                    listOf(Rect(0, 0, 5, 5)),
                    0f,
                    0xAABBCC,
                )
            val iconColorsLookup by collectLastValue(underTest.iconColors)
            val displayId = 987
            darkIconRepository.darkState(displayId).value =
                SysuiDarkIconDispatcher.DarkChange(listOf(Rect(0, 0, 5, 5)), 0f, 0xAABBCC)
            val iconColorsLookup by collectLastValue(underTest.iconColors(displayId))
            val iconColors = iconColorsLookup?.iconColors(Rect(6, 6, 7, 7))
            assertThat(iconColors).isNull()
        }
@@ -295,7 +274,7 @@ class NotificationIconContainerStatusBarViewModelTest(flags: FlagsParameterizati
                            activeNotificationModel(
                                key = "notif1",
                                groupKey = "group",
                                statusBarIcon = icon
                                statusBarIcon = icon,
                            )
                        )
                    }
@@ -322,7 +301,7 @@ class NotificationIconContainerStatusBarViewModelTest(flags: FlagsParameterizati
                            activeNotificationModel(
                                key = "notif1",
                                groupKey = "group",
                                statusBarIcon = icon
                                statusBarIcon = icon,
                            )
                        )
                    }
@@ -354,7 +333,7 @@ class NotificationIconContainerStatusBarViewModelTest(flags: FlagsParameterizati
                            activeNotificationModel(
                                key = "notif1",
                                groupKey = "group",
                                statusBarIcon = icon
                                statusBarIcon = icon,
                            )
                        )
                    }
+2 −1
Original line number Diff line number Diff line
@@ -40,11 +40,12 @@ constructor(
    private val failureTracker: StatusBarIconViewBindingFailureTracker,
    private val viewStore: StatusBarNotificationIconViewStore,
) {
    fun bindWhileAttached(view: NotificationIconContainer): DisposableHandle {
    fun bindWhileAttached(view: NotificationIconContainer, displayId: Int): DisposableHandle {
        return traceSection("NICStatusBar#bindWhileAttached") {
            view.repeatWhenAttached {
                lifecycleScope.launch {
                    NotificationIconContainerViewBinder.bind(
                        displayId = displayId,
                        view = view,
                        viewModel = viewModel,
                        configuration = configuration,
+11 −15
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import android.widget.FrameLayout
import androidx.annotation.ColorInt
import androidx.collection.ArrayMap
import androidx.lifecycle.lifecycleScope
import com.android.app.tracing.coroutines.launchTraced as launch
import com.android.app.tracing.traceSection
import com.android.internal.R as RInternal
import com.android.internal.statusbar.StatusBarIcon
@@ -54,12 +55,12 @@ import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.mapNotNull
import kotlinx.coroutines.flow.stateIn
import com.android.app.tracing.coroutines.launchTraced as launch

/** Binds a view-model to a [NotificationIconContainer]. */
object NotificationIconContainerViewBinder {

    suspend fun bind(
        displayId: Int,
        view: NotificationIconContainer,
        viewModel: NotificationIconContainerStatusBarViewModel,
        configuration: ConfigurationState,
@@ -70,7 +71,10 @@ object NotificationIconContainerViewBinder {
        launch {
            val contrastColorUtil = ContrastColorUtil.getInstance(view.context)
            val iconColors: StateFlow<NotificationIconColors> =
                viewModel.iconColors.mapNotNull { it.iconColors(view.viewBounds) }.stateIn(this)
                viewModel
                    .iconColors(displayId)
                    .mapNotNull { it.iconColors(view.viewBounds) }
                    .stateIn(this)
            viewModel.icons.bindIcons(
                logTag = "statusbar",
                view = view,
@@ -79,11 +83,7 @@ object NotificationIconContainerViewBinder {
                notifyBindingFailures = { failureTracker.statusBarFailures = it },
                viewStore = viewStore,
            ) { _, sbiv ->
                StatusBarIconViewBinder.bindIconColors(
                    sbiv,
                    iconColors,
                    contrastColorUtil,
                )
                StatusBarIconViewBinder.bindIconColors(sbiv, iconColors, contrastColorUtil)
            }
        }
        launch { viewModel.bindIsolatedIcon(view, viewStore) }
@@ -194,8 +194,7 @@ object NotificationIconContainerViewBinder {
            combine(iconSizeFlow, iconHorizontalPaddingFlow, systemBarUtilsState.statusBarHeight) {
                    iconSize,
                    iconHPadding,
                    statusBarHeight,
                    ->
                    statusBarHeight ->
                    FrameLayout.LayoutParams(iconSize + 2 * iconHPadding, statusBarHeight)
                }
                .stateIn(this)
@@ -251,10 +250,7 @@ object NotificationIconContainerViewBinder {
                    traceSection("addIcon") {
                        (sbiv.parent as? ViewGroup)?.run {
                            if (this !== view) {
                                Log.wtf(
                                    TAG,
                                    "[$logTag] SBIV($notifKey) has an unexpected parent",
                                )
                                Log.wtf(TAG, "[$logTag] SBIV($notifKey) has an unexpected parent")
                            }
                            // If the container was re-inflated and re-bound, then SBIVs might still
                            // be attached to the prior view.
@@ -271,7 +267,7 @@ object NotificationIconContainerViewBinder {
                                launch {
                                    launch {
                                        layoutParams.collectTracingEach(
                                            tag = { "[$logTag] SBIV#bindLayoutParams" },
                                            tag = { "[$logTag] SBIV#bindLayoutParams" }
                                        ) {
                                            if (it != sbiv.layoutParams) {
                                                sbiv.layoutParams = it
@@ -344,7 +340,7 @@ object NotificationIconContainerViewBinder {
    //  a single SBIV instance for the group. Then this whole concept can go away.
    private inline fun <R> NotificationIconContainer.withIconReplacements(
        replacements: ArrayMap<String, StatusBarIcon>,
        block: () -> R
        block: () -> R,
    ): R {
        setReplacingIcons(replacements)
        return block().also { setReplacingIcons(null) }
+10 −12
Original line number Diff line number Diff line
@@ -45,8 +45,8 @@ import kotlinx.coroutines.flow.map
class NotificationIconContainerStatusBarViewModel
@Inject
constructor(
    @Background bgContext: CoroutineContext,
    darkIconInteractor: DarkIconInteractor,
    @Background private val bgContext: CoroutineContext,
    private val darkIconInteractor: DarkIconInteractor,
    iconsInteractor: StatusBarNotificationIconsInteractor,
    headsUpIconInteractor: HeadsUpNotificationIconInteractor,
    keyguardInteractor: KeyguardInteractor,
@@ -58,10 +58,9 @@ constructor(

    /** Are changes to the icon container animated? */
    val animationsEnabled: Flow<Boolean> =
        combine(
                shadeInteractor.isShadeTouchable,
                keyguardInteractor.isKeyguardShowing,
            ) { panelTouchesEnabled, isKeyguardShowing ->
        combine(shadeInteractor.isShadeTouchable, keyguardInteractor.isKeyguardShowing) {
                panelTouchesEnabled,
                isKeyguardShowing ->
                panelTouchesEnabled && !isKeyguardShowing
            }
            .flowOn(bgContext)
@@ -69,8 +68,9 @@ constructor(
            .distinctUntilChanged()

    /** The colors with which to display the notification icons. */
    val iconColors: Flow<NotificationIconColorLookup> =
        darkIconInteractor.darkState
    fun iconColors(displayId: Int): Flow<NotificationIconColorLookup> =
        darkIconInteractor
            .darkState(displayId)
            .map { (areas: Collection<Rect>, tint: Int) ->
                NotificationIconColorLookup { viewBounds: Rect ->
                    if (DarkIconDispatcher.isInAreas(areas, viewBounds)) {
@@ -125,10 +125,8 @@ constructor(
    val isolatedIconLocation: Flow<Rect> =
        headsUpIconInteractor.isolatedIconLocation.filterNotNull().conflate().distinctUntilChanged()

    private class IconColorsImpl(
        override val tint: Int,
        private val areas: Collection<Rect>,
    ) : NotificationIconColors {
    private class IconColorsImpl(override val tint: Int, private val areas: Collection<Rect>) :
        NotificationIconColors {
        override fun staticDrawableColor(viewBounds: Rect): Int {
            return if (DarkIconDispatcher.isInAreas(areas, viewBounds)) {
                tint
+6 −6
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@
package com.android.systemui.statusbar.phone.data.repository

import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.statusbar.phone.SysuiDarkIconDispatcher
import com.android.systemui.statusbar.data.repository.SysuiDarkIconDispatcherStore
import com.android.systemui.statusbar.phone.SysuiDarkIconDispatcher.DarkChange
import dagger.Binds
import dagger.Module
@@ -25,16 +25,16 @@ import kotlinx.coroutines.flow.StateFlow

/** Dark-mode state for tinting icons. */
interface DarkIconRepository {
    val darkState: StateFlow<DarkChange>
    fun darkState(displayId: Int): StateFlow<DarkChange>
}

@SysUISingleton
class DarkIconRepositoryImpl
@Inject
constructor(
    darkIconDispatcher: SysuiDarkIconDispatcher,
) : DarkIconRepository {
    override val darkState: StateFlow<DarkChange> = darkIconDispatcher.darkChangeFlow()
constructor(private val darkIconDispatcherStore: SysuiDarkIconDispatcherStore) :
    DarkIconRepository {
    override fun darkState(displayId: Int): StateFlow<DarkChange> =
        darkIconDispatcherStore.forDisplay(displayId).darkChangeFlow()
}

@Module
Loading