Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 68478456 authored by Beverly's avatar Beverly
Browse files

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
parent a2e32910
Loading
Loading
Loading
Loading
+20 −23
Original line number Diff line number Diff line
@@ -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() {