From e6efbb4127bd31a3a370b8715f93e9ac92cbd34f Mon Sep 17 00:00:00 2001 From: Jeff DeCew Date: Fri, 23 Jun 2023 16:54:33 -0400 Subject: Do not dismiss priority children of a group being dismissed These notifications are never visually part of the group, and should not be dismissed. The NotificationManagerService already checks the channel for this exception, but the SystemUI NotifCollection was not. Fixes: 287747787 Test: atest NotifCollectionTest Merged-In: I6ee36618889b4fe1c8999ff149034a7db63fcbb7 Change-Id: I6ee36618889b4fe1c8999ff149034a7db63fcbb7 --- .../notification/collection/NotifCollection.java | 1 + .../collection/NotifCollectionTest.java | 33 +++++++++++++++++++--- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotifCollection.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotifCollection.java index 8aeefeeac211..d2c6d4baf817 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotifCollection.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotifCollection.java @@ -840,6 +840,7 @@ public class NotifCollection implements Dumpable, PipelineDumpable { && !hasFlag(entry, Notification.FLAG_ONGOING_EVENT) && !hasFlag(entry, Notification.FLAG_BUBBLE) && !hasFlag(entry, Notification.FLAG_NO_CLEAR) + && (entry.getChannel() == null || !entry.getChannel().isImportantConversation()) && entry.getDismissState() != DISMISSED; } diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/NotifCollectionTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/NotifCollectionTest.java index 540bda6ea9dc..9037df821ca8 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/NotifCollectionTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/NotifCollectionTest.java @@ -1674,12 +1674,22 @@ public class NotifCollectionTest extends SysuiTestCase { verifyNoMoreInteractions(mStatusBarService); } + @Test + public void testCanDismissOtherNotificationChildren() { + // GIVEN an ongoing notification + final NotificationEntry container = new NotificationEntryBuilder() + .setGroup(mContext, "group") + .build(); + + // THEN its children are dismissible + assertTrue(mCollection.shouldAutoDismissChildren( + container, container.getSbn().getGroupKey())); + } + @Test public void testCannotDismissOngoingNotificationChildren() { // GIVEN an ongoing notification final NotificationEntry container = new NotificationEntryBuilder() - .setPkg(TEST_PACKAGE) - .setId(47) .setGroup(mContext, "group") .setFlag(mContext, FLAG_ONGOING_EVENT, true) .build(); @@ -1693,6 +1703,7 @@ public class NotifCollectionTest extends SysuiTestCase { public void testCannotDismissNoClearNotifications() { // GIVEN an no-clear notification final NotificationEntry container = new NotificationEntryBuilder() + .setGroup(mContext, "group") .setFlag(mContext, FLAG_NO_CLEAR, true) .build(); @@ -1701,12 +1712,26 @@ public class NotifCollectionTest extends SysuiTestCase { container, container.getSbn().getGroupKey())); } + @Test + public void testCannotDismissPriorityConversations() { + // GIVEN an no-clear notification + NotificationChannel channel = + new NotificationChannel("foo", "Foo", NotificationManager.IMPORTANCE_HIGH); + channel.setImportantConversation(true); + final NotificationEntry container = new NotificationEntryBuilder() + .setGroup(mContext, "group") + .setChannel(channel) + .build(); + + // THEN its children are not dismissible + assertFalse(mCollection.shouldAutoDismissChildren( + container, container.getSbn().getGroupKey())); + } + @Test public void testCanDismissFgsNotificationChildren() { // GIVEN an FGS but not ongoing notification final NotificationEntry container = new NotificationEntryBuilder() - .setPkg(TEST_PACKAGE) - .setId(47) .setGroup(mContext, "group") .setFlag(mContext, FLAG_FOREGROUND_SERVICE, true) .build(); -- cgit v1.2.3-59-g8ed1b