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

Commit 5e5e969c authored by Julia Tuttle's avatar Julia Tuttle
Browse files

Drop Ineligible AOD RONs in the PromotedNotificationsInteractor

With the current code, Ineligible AOD RONs will still cause the AOD RON
to be included on the keyguard, and even though the Composable won't
display a notification, the bottom margin will still add an extra gap
between smart space and the shelf.

So, ignore Ineligible AOD RONs in the PromotedNotificationsInteractor,
which will make isPresent false, which will remove the AOD RON
Composable from the keyguard entirely.

Bug: 398194709
Test: manual
Flag: com.android.systemui.aod_ui_rich_ongoing
Change-Id: Ia1ae49609ee5874eee4e676edede0a84ebac0160
parent da3c41b2
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.
     */