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

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

Merge "Drop Ineligible AOD RONs in the PromotedNotificationsInteractor" into main

parents 60681ea7 5e5e969c
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -111,7 +111,7 @@ class PromotedNotificationsInteractorTest : SysuiTestCase() {
            )

            val topPromotedNotificationContent by
                collectLastValue(underTest.topPromotedNotificationContent)
                collectLastValue(underTest.aodPromotedNotification)

            // THEN the ron is first because the call has no content
            assertThat(topPromotedNotificationContent?.identity?.key)
@@ -131,7 +131,7 @@ class PromotedNotificationsInteractorTest : SysuiTestCase() {
            )

            val topPromotedNotificationContent by
                collectLastValue(underTest.topPromotedNotificationContent)
                collectLastValue(underTest.aodPromotedNotification)

            // THEN the call is the top notification
            assertThat(topPromotedNotificationContent?.identity?.key)
@@ -148,7 +148,7 @@ class PromotedNotificationsInteractorTest : SysuiTestCase() {
            renderNotificationListInteractor.setRenderedList(listOf(callEntry, otherEntry))

            val topPromotedNotificationContent by
                collectLastValue(underTest.topPromotedNotificationContent)
                collectLastValue(underTest.aodPromotedNotification)

            // THEN there is no top promoted notification
            assertThat(topPromotedNotificationContent).isNull()
+2 −6
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@ package com.android.systemui.statusbar.notification.promoted.domain.interactor
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dump.DumpManager
import com.android.systemui.statusbar.notification.promoted.shared.model.PromotedNotificationContentModel
import com.android.systemui.statusbar.notification.promoted.shared.model.PromotedNotificationContentModel.Style
import com.android.systemui.util.kotlin.FlowDumperImpl
import javax.inject.Inject
import kotlinx.coroutines.flow.Flow
@@ -34,10 +33,7 @@ constructor(
) : FlowDumperImpl(dumpManager) {
    /** The content to show as the promoted notification on AOD */
    val content: Flow<PromotedNotificationContentModel?> =
        promotedNotificationsInteractor.topPromotedNotificationContent
        promotedNotificationsInteractor.aodPromotedNotification

    val isPresent: Flow<Boolean> =
        content
            .map { (it != null) && (it.style != Style.Ineligible) }
            .dumpWhileCollecting("isPresent")
    val isPresent: Flow<Boolean> = content.map { it != null }.dumpWhileCollecting("isPresent")
}
+15 −3
Original line number Diff line number Diff line
@@ -22,6 +22,8 @@ import com.android.systemui.statusbar.chips.call.domain.interactor.CallChipInter
import com.android.systemui.statusbar.chips.notification.domain.interactor.StatusBarNotificationChipsInteractor
import com.android.systemui.statusbar.notification.domain.interactor.ActiveNotificationsInteractor
import com.android.systemui.statusbar.notification.promoted.shared.model.PromotedNotificationContentModel
import com.android.systemui.statusbar.notification.promoted.shared.model.PromotedNotificationContentModel.Style.Ineligible
import com.android.systemui.statusbar.notification.shared.ActiveNotificationModel
import com.android.systemui.statusbar.phone.ongoingcall.shared.model.OngoingCallModel
import javax.inject.Inject
import kotlinx.coroutines.CoroutineDispatcher
@@ -83,13 +85,13 @@ constructor(
            .map { list -> list.firstNotNullOfOrNull { it.promotedContent } }
            .distinctUntilNewInstance()

    /** This is the top-most promoted notification, which should avoid regular changing. */
    val topPromotedNotificationContent: Flow<PromotedNotificationContentModel?> =
    /** This is the AOD promoted notification, which should avoid regular changing. */
    val aodPromotedNotification: Flow<PromotedNotificationContentModel?> =
        combine(
                topPromotedChipNotification,
                activeNotificationsInteractor.topLevelRepresentativeNotifications,
            ) { topChipNotif, topLevelNotifs ->
                topChipNotif ?: topLevelNotifs.firstNotNullOfOrNull { it.promotedContent }
                topChipNotif?.takeIfAodEligible() ?: topLevelNotifs.firstAodEligibleOrNull()
            }
            // #equals() can be a bit expensive on this object, but this flow will regularly try to
            // emit the same immutable instance over and over, so just prevent that.
@@ -105,6 +107,16 @@ constructor(
            .distinctUntilChanged()
            .flowOn(backgroundDispatcher)

    private fun List<ActiveNotificationModel>.firstAodEligibleOrNull():
        PromotedNotificationContentModel? {
        return this.firstNotNullOfOrNull { it.promotedContent?.takeIfAodEligible() }
    }

    private fun PromotedNotificationContentModel.takeIfAodEligible():
        PromotedNotificationContentModel? {
        return this.takeUnless { it.style == Ineligible }
    }

    /**
     * Returns flow where all subsequent repetitions of the same object instance are filtered out.
     */