From 4cbc14285f30306b230c1bd52ec4a2106952f673 Mon Sep 17 00:00:00 2001 From: Lyn Han Date: Fri, 17 Apr 2020 11:08:53 -0700 Subject: [PATCH] Remove bubble when PendingIntent is canceled Bug: 151104690 Test: manual 1) Expand bubble with FLAG_ONE_SHOT PendingIntent => bubble removed Test: manual 1) Overflow bubble with FLAG_ONE_SHOT PendingIntent without expanding it 2) Promote bubble from overflow => bubble removed Test: manual 1) Expand bubble without FLAG_ONE_SHOT PendingIntent 2) Overflow bubble, promote bubble out of overflow 3) Expand bubble again without issue Test: atest SystemUITests Change-Id: I4b0c21dfcd9e424c74dd449146150fe8b830c218 --- .../systemui/bubbles/BubbleController.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/SystemUI/src/com/android/systemui/bubbles/BubbleController.java b/packages/SystemUI/src/com/android/systemui/bubbles/BubbleController.java index e488cf271fdfe..a1fff9412eb2f 100644 --- a/packages/SystemUI/src/com/android/systemui/bubbles/BubbleController.java +++ b/packages/SystemUI/src/com/android/systemui/bubbles/BubbleController.java @@ -54,6 +54,7 @@ import android.content.pm.ActivityInfo; import android.content.pm.PackageManager; import android.content.res.Configuration; import android.graphics.Rect; +import android.os.Handler; import android.os.RemoteException; import android.os.ServiceManager; import android.service.notification.NotificationListenerService; @@ -174,6 +175,9 @@ public class BubbleController implements ConfigurationController.ConfigurationLi private IStatusBarService mBarService; private SysUiState mSysUiState; + // Used to post to main UI thread + private Handler mHandler = new Handler(); + // Used for determining view rect for touch interaction private Rect mTempRect = new Rect(); @@ -799,7 +803,17 @@ public class BubbleController implements ConfigurationController.ConfigurationLi Bubble bubble = mBubbleData.getOrCreateBubble(notif); bubble.setInflateSynchronously(mInflateSynchronously); bubble.inflate( - b -> mBubbleData.notificationEntryUpdated(b, suppressFlyout, showInShade), + b -> { + mBubbleData.notificationEntryUpdated(b, suppressFlyout, showInShade); + if (bubble.getBubbleIntent() == null) { + return; + } + bubble.getBubbleIntent().registerCancelListener(pendingIntent -> { + mHandler.post( + () -> removeBubble(bubble.getEntry(), + BubbleController.DISMISS_INVALID_INTENT)); + }); + }, mContext, mStackView, mBubbleIconFactory); }