From 68478456774d2cdc5cd6c21ce4720259938bb0e7 Mon Sep 17 00:00:00 2001 From: Beverly Date: Tue, 27 Oct 2020 21:04:35 -0400 Subject: [PATCH] Remove visible notif + summary before NMS.onClick The onDismiss callback was being called after NMS had handled the onClick and cancelled the notification already. This would result in the parent (group summary) not being removed from the UI. Test: atest SystemUITests Test: manual 1. Install go/notify-apk 2. Post auto-cancellable notification group with two children 3. Click on notification from the posted group Observe: notification is removed; there is still one notification left in the group 4. Click on the last notification Observe: group is gone Fixes: 171467963 Change-Id: Ia0dbc6f12b99c9193cc9355d2fa2b60eb460e0bf --- .../StatusBarNotificationActivityStarter.java | 43 +++++++++---------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarNotificationActivityStarter.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarNotificationActivityStarter.java index 256ee2081f416..014d5c274c1f4 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarNotificationActivityStarter.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarNotificationActivityStarter.java @@ -360,15 +360,11 @@ public class StatusBarNotificationActivityStarter implements NotificationActivit collapseOnMainThread(); } - final int count = getVisibleNotificationsCount(); - final int rank = entry.getRanking().getRank(); NotificationVisibility.NotificationLocation location = NotificationLogger.getNotificationLocation(entry); - final NotificationVisibility nv = NotificationVisibility.obtain(notificationKey, - rank, count, true, location); + final NotificationVisibility nv = NotificationVisibility.obtain(entry.getKey(), + entry.getRanking().getRank(), getVisibleNotificationsCount(), true, location); - // NMS will officially remove notification if the notification has FLAG_AUTO_CANCEL: - mClickNotifier.onNotificationClick(notificationKey, nv); // TODO (b/162832756): delete these notification removals when migrating to the new // pipeline; this is taken care of in {@link NotifCollection#tryRemoveNotification} @@ -378,9 +374,25 @@ public class StatusBarNotificationActivityStarter implements NotificationActivit if (shouldAutoCancel(entry.getSbn()) || mRemoteInputManager.isNotificationKeptForRemoteInputHistory( notificationKey)) { - // manually call notification removal in order to cancel any lifetime extenders - removeNotification(row.getEntry()); + // Immediately remove notification from visually showing. + // We have to post the removal to the UI thread for synchronization. + mMainThreadHandler.post(() -> { + final Runnable removeNotification = () -> { + mOnUserInteractionCallback.onDismiss(entry, REASON_CLICK); + mClickNotifier.onNotificationClick(entry.getKey(), nv); + }; + if (mPresenter.isCollapsing()) { + // To avoid lags we're only performing the remove + // after the shade is collapsed + mShadeController.addPostCollapseAction(removeNotification); + } else { + removeNotification.run(); + } + }); } + } else { + // inform NMS that the notification was clicked + mClickNotifier.onNotificationClick(notificationKey, nv); } mIsCollapsingToShowActivityOverLockscreen = false; @@ -565,21 +577,6 @@ public class StatusBarNotificationActivityStarter implements NotificationActivit return entry.shouldSuppressFullScreenIntent(); } - private void removeNotification(NotificationEntry entry) { - // We have to post it to the UI thread for synchronization - mMainThreadHandler.post(() -> { - if (mPresenter.isCollapsing()) { - // To avoid lags we're only performing the remove - // after the shade was collapsed - mShadeController.addPostCollapseAction( - () -> mOnUserInteractionCallback.onDismiss(entry, REASON_CLICK) - ); - } else { - mOnUserInteractionCallback.onDismiss(entry, REASON_CLICK); - } - }); - } - // --------------------- NotificationEntryManager/NotifPipeline methods ------------------------ private int getVisibleNotificationsCount() {