From 0d3b37cdce43ff87006d2ba533ff4242af39ee9b Mon Sep 17 00:00:00 2001 From: Yuri Lin Date: Mon, 3 Oct 2022 16:29:48 -0400 Subject: [PATCH] On notification update, take the newest value of shouldHeadsUp When addressing only notification updates, this is a very small edge case that will only occur if multiple notification posts/updates occur in the same build cycle, *and* the value of shouldHeadsUp changes. This change is also being made in preparation for updates to handle onRankingApplied, which may add additional cases where an update occurs to the value of shouldHeadsUp. Bug: 248325248 Test: HeadsUpCoordinatorTest Change-Id: I274c5f65d92fc151bacaacb21726445f1bf7fecb --- .../coordinator/HeadsUpCoordinator.kt | 2 +- .../coordinator/HeadsUpCoordinatorTest.kt | 34 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/HeadsUpCoordinator.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/HeadsUpCoordinator.kt index 8278b549a7a04..ccf6feca69927 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/HeadsUpCoordinator.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/HeadsUpCoordinator.kt @@ -393,7 +393,7 @@ class HeadsUpCoordinator @Inject constructor( val posted = mPostedEntries.compute(entry.key) { _, value -> value?.also { update -> update.wasUpdated = true - update.shouldHeadsUpEver = update.shouldHeadsUpEver || shouldHeadsUpEver + update.shouldHeadsUpEver = shouldHeadsUpEver update.shouldHeadsUpAgain = update.shouldHeadsUpAgain || shouldHeadsUpAgain update.isAlerting = isAlerting update.isBinding = isBinding diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/coordinator/HeadsUpCoordinatorTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/coordinator/HeadsUpCoordinatorTest.kt index 2ee31265ff7bb..2970807afb365 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/coordinator/HeadsUpCoordinatorTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/coordinator/HeadsUpCoordinatorTest.kt @@ -336,6 +336,40 @@ class HeadsUpCoordinatorTest : SysuiTestCase() { verify(mHeadsUpManager, never()).showNotification(mEntry) } + @Test + fun testOnEntryUpdated_toAlert() { + // GIVEN that an entry is posted that should not heads up + setShouldHeadsUp(mEntry, false) + mCollectionListener.onEntryAdded(mEntry) + + // WHEN it's updated to heads up + setShouldHeadsUp(mEntry) + mCollectionListener.onEntryUpdated(mEntry) + mBeforeTransformGroupsListener.onBeforeTransformGroups(listOf(mEntry)) + mBeforeFinalizeFilterListener.onBeforeFinalizeFilter(listOf(mEntry)) + + // THEN the notification alerts + finishBind(mEntry) + verify(mHeadsUpManager).showNotification(mEntry) + } + + @Test + fun testOnEntryUpdated_toNotAlert() { + // GIVEN that an entry is posted that should heads up + setShouldHeadsUp(mEntry) + mCollectionListener.onEntryAdded(mEntry) + + // WHEN it's updated to not heads up + setShouldHeadsUp(mEntry, false) + mCollectionListener.onEntryUpdated(mEntry) + mBeforeTransformGroupsListener.onBeforeTransformGroups(listOf(mEntry)) + mBeforeFinalizeFilterListener.onBeforeFinalizeFilter(listOf(mEntry)) + + // THEN the notification is never bound or shown + verify(mHeadsUpViewBinder, never()).bindHeadsUpView(any(), any()) + verify(mHeadsUpManager, never()).showNotification(any()) + } + @Test fun testOnEntryRemovedRemovesHeadsUpNotification() { // GIVEN the current HUN is mEntry