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

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

Combines NotificationEntryManager listener interfaces (part 4).

This change combines the onEntryRemoved() and onNotificationRemoved()
methods on NotificationEntryListener to a single method.  The logic in
NotificationEntryManager which calls these methods is rearranged and a
flag is added to the callback method in order to fully preserve the
previous behavior of all implementors.

Test: atest SystemUITests, manual
Change-Id: I6077e78005ed6c20b02f5fa21f213199384cc3b8
parent 8621bd27
Loading
Loading
Loading
Loading
+9 −9
Original line number Diff line number Diff line
@@ -80,8 +80,9 @@ public class NotificationAlertingManager {
            }

            @Override
            public void onEntryRemoved(NotificationData.Entry entry) {
                stopAlerting(entry);
            public void onEntryRemoved(
                    String key, StatusBarNotification old, boolean lifetimeExtended) {
                stopAlerting(key);
            }
        });
    }
@@ -159,24 +160,23 @@ public class NotificationAlertingManager {
        }
    }

    private void stopAlerting(NotificationData.Entry entry) {
    private void stopAlerting(final String key) {
        // Attempt to remove notifications from their alert managers (heads up, ambient pulse).
        // Though the remove itself may fail, it lets the manager know to remove as soon as
        // possible.
        if (mHeadsUpManager.isAlerting(entry.key)) {
        if (mHeadsUpManager.isAlerting(key)) {
            // A cancel() in response to a remote input shouldn't be delayed, as it makes the
            // sending look longer than it takes.
            // Also we should not defer the removal if reordering isn't allowed since otherwise
            // some notifications can't disappear before the panel is closed.
            boolean ignoreEarliestRemovalTime =
                    mRemoteInputManager.getController().isSpinning(entry.key)
                    mRemoteInputManager.getController().isSpinning(key)
                            && !FORCE_REMOTE_INPUT_HISTORY
                            || !mVisualStabilityManager.isReorderingAllowed();
            mHeadsUpManager.removeNotification(entry.key, ignoreEarliestRemovalTime);
            mHeadsUpManager.removeNotification(key, ignoreEarliestRemovalTime);
        }
        if (mAmbientPulseManager.isAlerting(entry.key)) {
            mAmbientPulseManager.removeNotification(entry.key,
                    false /* ignoreEarliestRemovalTime */);
        if (mAmbientPulseManager.isAlerting(key)) {
            mAmbientPulseManager.removeNotification(key, false /* ignoreEarliestRemovalTime */);
        }
    }
}
+5 −10
Original line number Diff line number Diff line
@@ -60,24 +60,19 @@ public interface NotificationEntryListener {
     * Called when a notification has been removed (either because the user swiped it away or
     * because the developer retracted it).
     *
     * TODO: combine this with onNotificationRemoved().
     */
    default void onEntryRemoved(NotificationData.Entry entry) {
    }

    /**
     * Called when a notification was removed.
     *
     * @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
     */
    default void onNotificationRemoved(String key, StatusBarNotification old) {
    default void onEntryRemoved(
            String key, StatusBarNotification old, boolean lifetimeExtended) {
    }

    /**
     * Removes a notification immediately.
     *
     * TODO: combine this with onNotificationRemoved().
     * TODO: combine this with onEntryRemoved().
     */
    default void onPerformRemoveNotification(StatusBarNotification statusBarNotification) {
    }
+31 −35
Original line number Diff line number Diff line
@@ -363,31 +363,25 @@ public class NotificationEntryManager implements
        final NotificationData.Entry entry = mNotificationData.get(key);

        abortExistingInflation(key);
        if (entry != null) {
            for (NotificationEntryListener listener : mNotificationEntryListeners) {
                listener.onEntryRemoved(entry);
            }
        }

        if (entry == null) {
            for (NotificationEntryListener listener : mNotificationEntryListeners) {
                listener.onNotificationRemoved(key, null /* old */);
            }
            return;
        }
        StatusBarNotification old = null;
        boolean lifetimeExtended = false;

        // If a manager needs to keep the notification around for whatever reason, we return early
        // and keep the notification
        if (entry != null) {
            // If a manager needs to keep the notification around for whatever reason, we
            // keep the notification
            if (!forceRemove) {
                for (NotificationLifetimeExtender extender : mNotificationLifetimeExtenders) {
                    if (extender.shouldExtendLifetime(entry)) {
                        mLatestRankingMap = ranking;
                        extender.setShouldManageLifetime(entry, true /* shouldManage */);
                    return;
                        lifetimeExtended = true;
                        break;
                    }
                }
            }

            if (!lifetimeExtended) {
                // At this point, we are guaranteed the notification will be removed

                // Ensure any managers keeping the lifetime extended stop managing the entry
@@ -406,10 +400,12 @@ public class NotificationEntryManager implements
                // Let's remove the children if this was a summary
                handleGroupSummaryRemoved(key);

        StatusBarNotification old = removeNotificationViews(key, ranking);
                old = removeNotificationViews(key, ranking);
            }
        }

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

+3 −2
Original line number Diff line number Diff line
@@ -216,11 +216,12 @@ public class NotificationGroupAlertTransferHelper implements OnHeadsUpChangedLis
        }

        @Override
        public void onEntryRemoved(Entry entry) {
        public void onEntryRemoved(
                String key, StatusBarNotification old, boolean lifetimeExtended) {
            // 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.
            mPendingAlerts.remove(entry.key);
            mPendingAlerts.remove(key);
        }
    };

+5 −2
Original line number Diff line number Diff line
@@ -188,9 +188,12 @@ public class StatusBarNotificationPresenter implements NotificationPresenter,
                }

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

                @Override
                public void onPerformRemoveNotification(
Loading