Dismiss bubbles if shouldBubbleUp returns false (e.g. DND is enabled and configured to hide that bubble).

Bug: 159413312
Test: post a bubble, enable dnd, bubble goes away, disable DND, bubble is back!
Test: change DND settings from 'no sound' to 'no visual', bubble remains if 'no sound' is selected
Test: dismiss bubble, enable DND, disable DND, observe bubble does not re-appear since it was manually disabled
Change-Id: I8cb4b62d2cf272e9ac46f4088112a6dad381d40c
This commit is contained in:
Josh Tsuji
2020-08-10 14:50:22 -04:00
parent 5fa0c6d621
commit 160d1eb4ac

View File

@@ -138,7 +138,8 @@ public class BubbleController implements ConfigurationController.ConfigurationLi
@IntDef({DISMISS_USER_GESTURE, DISMISS_AGED, DISMISS_TASK_FINISHED, DISMISS_BLOCKED,
DISMISS_NOTIF_CANCEL, DISMISS_ACCESSIBILITY_ACTION, DISMISS_NO_LONGER_BUBBLE,
DISMISS_USER_CHANGED, DISMISS_GROUP_CANCELLED, DISMISS_INVALID_INTENT,
DISMISS_OVERFLOW_MAX_REACHED, DISMISS_SHORTCUT_REMOVED, DISMISS_PACKAGE_REMOVED})
DISMISS_OVERFLOW_MAX_REACHED, DISMISS_SHORTCUT_REMOVED, DISMISS_PACKAGE_REMOVED,
DISMISS_NO_BUBBLE_UP})
@Target({FIELD, LOCAL_VARIABLE, PARAMETER})
@interface DismissReason {}
@@ -155,6 +156,7 @@ public class BubbleController implements ConfigurationController.ConfigurationLi
static final int DISMISS_OVERFLOW_MAX_REACHED = 11;
static final int DISMISS_SHORTCUT_REMOVED = 12;
static final int DISMISS_PACKAGE_REMOVED = 13;
static final int DISMISS_NO_BUBBLE_UP = 14;
private final Context mContext;
private final NotificationEntryManager mNotificationEntryManager;
@@ -1253,8 +1255,18 @@ public class BubbleController implements ConfigurationController.ConfigurationLi
rankingMap.getRanking(key, mTmpRanking);
boolean isActiveBubble = mBubbleData.hasAnyBubbleWithKey(key);
if (isActiveBubble && !mTmpRanking.canBubble()) {
mBubbleData.dismissBubbleWithKey(entry.getKey(),
BubbleController.DISMISS_BLOCKED);
// If this entry is no longer allowed to bubble, dismiss with the BLOCKED reason.
// This means that the app or channel's ability to bubble has been revoked.
mBubbleData.dismissBubbleWithKey(
key, BubbleController.DISMISS_BLOCKED);
} else if (isActiveBubble
&& !mNotificationInterruptStateProvider.shouldBubbleUp(entry)) {
// If this entry is allowed to bubble, but cannot currently bubble up, dismiss it.
// This happens when DND is enabled and configured to hide bubbles. Dismissing with
// the reason DISMISS_NO_BUBBLE_UP will retain the underlying notification, so that
// the bubble will be re-created if shouldBubbleUp returns true.
mBubbleData.dismissBubbleWithKey(
key, BubbleController.DISMISS_NO_BUBBLE_UP);
} else if (entry != null && mTmpRanking.isBubble() && !isActiveBubble) {
entry.setFlagBubble(true);
onEntryUpdated(entry);
@@ -1331,8 +1343,10 @@ public class BubbleController implements ConfigurationController.ConfigurationLi
mStackView.removeBubble(bubble);
}
// If the bubble is removed for user switching, leave the notification in place.
if (reason == DISMISS_USER_CHANGED) {
// Leave the notification in place if we're dismissing due to user switching, or
// because DND is suppressing the bubble. In both of those cases, we need to be able
// to restore the bubble from the notification later.
if (reason == DISMISS_USER_CHANGED || reason == DISMISS_NO_BUBBLE_UP) {
continue;
}
if (reason == DISMISS_NOTIF_CANCEL) {