From a08dfd344e2e1ef29db172536f055d0f8f6c34c8 Mon Sep 17 00:00:00 2001 From: Ats Jenk Date: Thu, 26 May 2022 16:23:54 -0700 Subject: [PATCH] Ignore group alert setting when opening bubbles When notifications are shown in a group, group alert setting can be set to GROUP_ALERT_SUMMARY to notify the user only once per group. Regardless of this alert setting, user is still allowed to bubble individiual notifications in a group (button is shown). Issue was that our check if a notification can be bubbled was applying the check for alerting on a child notification in a group. Which is not needed as bubbling should be allowed regardless. Removing the check for bubbles. Bug: 214130620 Test: atest NotificationInterruptStateProviderImplTest Test: manually verified that when there are multiple notifications from Telegram, they can be opened as bubbles Test: manually verified with Messages that notifications in a group can be opened as bubbles Change-Id: I01258e0db041b8eb04160242f4fd9a875315ad3d --- ...otificationInterruptStateProviderImpl.java | 41 ++++++++++++++----- ...icationInterruptStateProviderImplTest.java | 29 +++++++++++-- 2 files changed, 57 insertions(+), 13 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/interruption/NotificationInterruptStateProviderImpl.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/interruption/NotificationInterruptStateProviderImpl.java index e210f193b0a1d..a063dbd99626b 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/interruption/NotificationInterruptStateProviderImpl.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/interruption/NotificationInterruptStateProviderImpl.java @@ -194,6 +194,10 @@ public class NotificationInterruptStateProviderImpl implements NotificationInter return false; } + if (!canAlertHeadsUpCommon(entry)) { + return false; + } + if (!canAlertAwakeCommon(entry)) { return false; } @@ -267,6 +271,11 @@ public class NotificationInterruptStateProviderImpl implements NotificationInter return false; } + if (!canAlertHeadsUpCommon(entry)) { + mLogger.logNoPulsingNoAlert(sbn); + return false; + } + if (entry.shouldSuppressAmbient()) { mLogger.logNoPulsingNoAmbientEffect(sbn); return false; @@ -294,12 +303,6 @@ public class NotificationInterruptStateProviderImpl implements NotificationInter return false; } - // Don't alert notifications that are suppressed due to group alert behavior - if (sbn.isGroup() && sbn.getNotification().suppressAlertingDueToGrouping()) { - mLogger.logNoAlertingGroupAlertBehavior(sbn); - return false; - } - for (int i = 0; i < mSuppressors.size(); i++) { if (mSuppressors.get(i).suppressInterruptions(entry)) { mLogger.logNoAlertingSuppressedBy(sbn, mSuppressors.get(i), /* awake */ false); @@ -307,13 +310,31 @@ public class NotificationInterruptStateProviderImpl implements NotificationInter } } - if (entry.hasJustLaunchedFullScreenIntent()) { - mLogger.logNoAlertingRecentFullscreen(sbn); + if (mKeyguardNotificationVisibilityProvider.shouldHideNotification(entry)) { + mLogger.keyguardHideNotification(entry.getKey()); return false; } - if (mKeyguardNotificationVisibilityProvider.shouldHideNotification(entry)) { - mLogger.keyguardHideNotification(entry.getKey()); + return true; + } + + /** + * Common checks for heads up notifications on regular and AOD displays. + * + * @param entry the entry to check + * @return true if these checks pass, false if the notification should not alert + */ + private boolean canAlertHeadsUpCommon(NotificationEntry entry) { + StatusBarNotification sbn = entry.getSbn(); + + // Don't alert notifications that are suppressed due to group alert behavior + if (sbn.isGroup() && sbn.getNotification().suppressAlertingDueToGrouping()) { + mLogger.logNoAlertingGroupAlertBehavior(sbn); + return false; + } + + if (entry.hasJustLaunchedFullScreenIntent()) { + mLogger.logNoAlertingRecentFullscreen(sbn); return false; } diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/interruption/NotificationInterruptStateProviderImplTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/interruption/NotificationInterruptStateProviderImplTest.java index 8a2dc263cf368..7b40ba87b494a 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/interruption/NotificationInterruptStateProviderImplTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/interruption/NotificationInterruptStateProviderImplTest.java @@ -17,6 +17,7 @@ package com.android.systemui.statusbar.notification.interruption; import static android.app.Notification.FLAG_BUBBLE; +import static android.app.Notification.GROUP_ALERT_SUMMARY; import static android.app.NotificationManager.IMPORTANCE_DEFAULT; import static android.app.NotificationManager.IMPORTANCE_HIGH; import static android.app.NotificationManager.IMPORTANCE_LOW; @@ -430,6 +431,17 @@ public class NotificationInterruptStateProviderImplTest extends SysuiTestCase { assertThat(mNotifInterruptionStateProvider.shouldBubbleUp(createBubble())).isTrue(); } + /** + * Test that notification can bubble even if it is a child in a group and group settings are + * set to alert only for summary notifications. + */ + @Test + public void testShouldBubbleUp_notifInGroupWithOnlySummaryAlerts() { + ensureStateForBubbleUp(); + NotificationEntry bubble = createBubble("testgroup", GROUP_ALERT_SUMMARY); + assertThat(mNotifInterruptionStateProvider.shouldBubbleUp(bubble)).isTrue(); + } + /** * If the notification doesn't have permission to bubble, it shouldn't bubble. */ @@ -497,16 +509,27 @@ public class NotificationInterruptStateProviderImplTest extends SysuiTestCase { } private NotificationEntry createBubble() { + return createBubble(null, null); + } + + private NotificationEntry createBubble(String groupKey, Integer groupAlert) { Notification.BubbleMetadata data = new Notification.BubbleMetadata.Builder( PendingIntent.getActivity(mContext, 0, new Intent(), PendingIntent.FLAG_MUTABLE), Icon.createWithResource(mContext.getResources(), R.drawable.android)) .build(); - Notification n = new Notification.Builder(getContext(), "a") + Notification.Builder nb = new Notification.Builder(getContext(), "a") .setContentTitle("title") .setContentText("content text") - .setBubbleMetadata(data) - .build(); + .setBubbleMetadata(data); + if (groupKey != null) { + nb.setGroup(groupKey); + nb.setGroupSummary(false); + } + if (groupAlert != null) { + nb.setGroupAlertBehavior(groupAlert); + } + Notification n = nb.build(); n.flags |= FLAG_BUBBLE; return new NotificationEntryBuilder()