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

Commit 79691170 authored by Steve Elliott's avatar Steve Elliott
Browse files

Exempt ongoing and media notifications from unseen filter

Test: atest KeygaurdCoordinatorTet
Bug: 240472040
Fixes: 260563613
Change-Id: Iec08a548fd789161effbb1ac89a096f3ae008299
parent 5aad6ff5
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -119,6 +119,9 @@ constructor(
                    // Don't apply the filter to (non-promoted) group summaries
                    //  - summary will be pruned if necessary, depending on if children are filtered
                    entry.parent?.summary == entry -> false
                    // Check that the entry satisfies certain characteristics that would bypass the
                    // filter
                    shouldIgnoreUnseenCheck(entry) -> false
                    else -> true
                }.also { hasFiltered -> hasFilteredAnyNotifs = hasFilteredAnyNotifs || hasFiltered }

@@ -134,6 +137,13 @@ constructor(
                keyguardNotificationVisibilityProvider.shouldHideNotification(entry)
        }

    private fun shouldIgnoreUnseenCheck(entry: NotificationEntry): Boolean =
        when {
            entry.isMediaNotification -> true
            entry.sbn.isOngoing -> true
            else -> false
        }

    // TODO(b/206118999): merge this class with SensitiveContentCoordinator which also depends on
    //  these same updates
    private fun setupInvalidateNotifListCallbacks() {}
+46 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@

package com.android.systemui.statusbar.notification.collection.coordinator

import android.app.Notification
import android.testing.AndroidTestingRunner
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
@@ -33,6 +34,7 @@ import com.android.systemui.statusbar.notification.collection.provider.SectionHe
import com.android.systemui.statusbar.notification.collection.provider.SeenNotificationsProvider
import com.android.systemui.statusbar.notification.collection.provider.SeenNotificationsProviderImpl
import com.android.systemui.statusbar.notification.interruption.KeyguardNotificationVisibilityProvider
import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow
import com.android.systemui.util.mockito.eq
import com.android.systemui.util.mockito.mock
import com.android.systemui.util.mockito.withArgCaptor
@@ -104,6 +106,50 @@ class KeyguardCoordinatorTest : SysuiTestCase() {
        }
    }

    @Test
    fun unseenFilterDoesNotSuppressSeenOngoingNotifWhileKeyguardShowing() {
        whenever(notifPipelineFlags.shouldFilterUnseenNotifsOnKeyguard).thenReturn(true)

        // GIVEN: Keyguard is not showing, and an ongoing notification is present
        keyguardRepository.setKeyguardShowing(false)
        runKeyguardCoordinatorTest {
            val fakeEntry = NotificationEntryBuilder()
                .setNotification(Notification.Builder(mContext).setOngoing(true).build())
                .build()
            collectionListener.onEntryAdded(fakeEntry)

            // WHEN: The keyguard is now showing
            keyguardRepository.setKeyguardShowing(true)
            testScheduler.runCurrent()

            // THEN: The notification is recognized as "ongoing" and is not filtered out.
            assertThat(unseenFilter.shouldFilterOut(fakeEntry, 0L)).isFalse()
        }
    }

    @Test
    fun unseenFilterDoesNotSuppressSeenMediaNotifWhileKeyguardShowing() {
        whenever(notifPipelineFlags.shouldFilterUnseenNotifsOnKeyguard).thenReturn(true)

        // GIVEN: Keyguard is not showing, and a media notification is present
        keyguardRepository.setKeyguardShowing(false)
        runKeyguardCoordinatorTest {
            val fakeEntry = NotificationEntryBuilder().build().apply {
                row = mock<ExpandableNotificationRow>().apply {
                    whenever(isMediaRow).thenReturn(true)
                }
            }
            collectionListener.onEntryAdded(fakeEntry)

            // WHEN: The keyguard is now showing
            keyguardRepository.setKeyguardShowing(true)
            testScheduler.runCurrent()

            // THEN: The notification is recognized as "media" and is not filtered out.
            assertThat(unseenFilter.shouldFilterOut(fakeEntry, 0L)).isFalse()
        }
    }

    @Test
    fun unseenFilterUpdatesSeenProviderWhenSuppressing() {
        whenever(notifPipelineFlags.shouldFilterUnseenNotifsOnKeyguard).thenReturn(true)