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

Commit dca2be5f authored by Gus Prevas's avatar Gus Prevas
Browse files

Combines NotificationEntryManager listener interfaces (part 5).

This change combines the onEntryRemoved() and
onPerformRemoveNotification() methods on NotificationEntryListener to a
single method.  The latter method was called after the former method in
all cases where the removal of the notification was precipitated by user
action (swipe, bubble swipe, launching content intent), so it's replaced
by a boolean parameter to the former method indicating whether a user
action caused the removal.

Test: atest SystemUITests, manual
Change-Id: I448fdd68984e3c2489259940c4d3432ac5bfe320
parent f37435a6
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -81,7 +81,8 @@ public class NotificationAlertingManager {

            @Override
            public void onEntryRemoved(
                    String key, StatusBarNotification old, boolean lifetimeExtended) {
                    String key, StatusBarNotification old, boolean lifetimeExtended,
                    boolean removedByUser) {
                stopAlerting(key);
            }
        });
+6 −12
Original line number Diff line number Diff line
@@ -59,21 +59,15 @@ public interface NotificationEntryListener {
    /**
     * Called when a notification has been removed (either because the user swiped it away or
     * because the developer retracted it).
     *
     *  @param key key of notification that was removed
     * @param old StatusBarNotification of the notification before it was removed
     * @param lifetimeExtended true if something is artificially extending how long the notification
     *                         stays visible after it's removed
     * @param removedByUser true if the notification was removed by a user action
     */
    default void onEntryRemoved(
            String key, StatusBarNotification old, boolean lifetimeExtended) {
    }

    /**
     * Removes a notification immediately.
     *
     * TODO: combine this with onEntryRemoved().
     */
    default void onPerformRemoveNotification(StatusBarNotification statusBarNotification) {
            String key,
            StatusBarNotification old,
            boolean lifetimeExtended,
            boolean removedByUser) {
    }
}
+12 −11
Original line number Diff line number Diff line
@@ -246,15 +246,11 @@ public class NotificationEntryManager implements
            int dismissalSentiment = NotificationStats.DISMISS_SENTIMENT_NEUTRAL;
            mBarService.onNotificationClear(pkg, tag, id, userId, n.getKey(), dismissalSurface,
                    dismissalSentiment, nv);
            removeNotification(n.getKey(), null);

            removeNotificationInternal(
                    n.getKey(), null, false /* forceRemove */, true /* removedByUser */);
        } catch (RemoteException ex) {
            // system process is dead if we're here.
        }

        for (NotificationEntryListener listener : mNotificationEntryListeners) {
            listener.onPerformRemoveNotification(n);
        }
    }

    @Override
@@ -294,7 +290,8 @@ public class NotificationEntryManager implements
     */
    @Override
    public void handleInflationException(StatusBarNotification n, Exception e) {
        removeNotificationInternal(n.getKey(), null, true /* forceRemove */);
        removeNotificationInternal(
                n.getKey(), null, true /* forceRemove */, false /* removedByUser */);
        try {
            mBarService.onNotificationError(n.getPackageName(), n.getTag(), n.getId(), n.getUid(),
                    n.getInitialPid(), e.getMessage(), n.getUserId());
@@ -355,11 +352,15 @@ public class NotificationEntryManager implements

    @Override
    public void removeNotification(String key, NotificationListenerService.RankingMap ranking) {
        removeNotificationInternal(key, ranking, false /* forceRemove */);
        removeNotificationInternal(
                key, ranking, false /* forceRemove */, false /* removedByUser */);
    }

    private void removeNotificationInternal(String key,
            @Nullable NotificationListenerService.RankingMap ranking, boolean forceRemove) {
    private void removeNotificationInternal(
            String key,
            @Nullable NotificationListenerService.RankingMap ranking,
            boolean forceRemove,
            boolean removedByUser) {
        final NotificationData.Entry entry = mNotificationData.get(key);

        abortExistingInflation(key);
@@ -405,7 +406,7 @@ public class NotificationEntryManager implements
        }

        for (NotificationEntryListener listener : mNotificationEntryListeners) {
            listener.onEntryRemoved(key, old, lifetimeExtended);
            listener.onEntryRemoved(key, old, lifetimeExtended, removedByUser);
        }
    }

+2 −1
Original line number Diff line number Diff line
@@ -217,7 +217,8 @@ public class NotificationGroupAlertTransferHelper implements OnHeadsUpChangedLis

        @Override
        public void onEntryRemoved(
                String key, StatusBarNotification old, boolean lifetimeExtended) {
                String key, StatusBarNotification old, boolean lifetimeExtended,
                boolean removedByUser) {
            // Removes any alerts pending on this entry. Note that this will not stop any inflation
            // tasks started by a transfer, so this should only be used as clean-up for when
            // inflation is stopped and the pending alert no longer needs to happen.
+5 −8
Original line number Diff line number Diff line
@@ -189,16 +189,13 @@ public class StatusBarNotificationPresenter implements NotificationPresenter,

                @Override
                public void onEntryRemoved(String key, StatusBarNotification old,
                        boolean lifetimeExtended) {
                        boolean lifetimeExtended, boolean removedByUser) {
                    if (!lifetimeExtended) {
                        StatusBarNotificationPresenter.this.onNotificationRemoved(key, old);
                    }
                    if (removedByUser) {
                        maybeEndAmbientPulse();
                    }

                @Override
                public void onPerformRemoveNotification(
                        StatusBarNotification statusBarNotification) {
                    StatusBarNotificationPresenter.this.onPerformRemoveNotification();
                }
            };

@@ -260,7 +257,7 @@ public class StatusBarNotificationPresenter implements NotificationPresenter,
                || mActivityLaunchAnimator.isAnimationRunning();
    }

    private void onPerformRemoveNotification() {
    private void maybeEndAmbientPulse() {
        if (mNotificationPanel.hasPulsingNotifications() &&
                !mAmbientPulseManager.hasNotifications()) {
            // We were showing a pulse for a notification, but no notifications are pulsing anymore.
Loading