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

Commit 88aeaf7d authored by Ned Burns's avatar Ned Burns
Browse files

Add getAllNotifs() to CommonNotifCollection

The following CL needs to be able to iterate through all current
notifications, so we need this method.

Adds a method, getAllNotifs() to CommonNotifCollection. This means that
both NotifCollection and NotificationEntryManager must now implement
this method.

NotifCollection previously had the (confusingly-named)
getActiveNotifs(). Now renamed to getAllNotifs().

NotificationEntryManager previously had
getPendingAndActiveNotifications(), which wasn't very efficient.
Restructured to the class to not need to rebuild the collection every
time it was called. Moved the (one) existing client over to use it.

Bug: 112656837
Test: atest SystemUITests
Change-Id: Ic2d5860e080fff8cb11c37ccc1a92f0af761caab
parent 7342e3c3
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -70,6 +70,7 @@ import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -284,8 +285,7 @@ public class NotificationMediaManager implements Dumpable {
        boolean metaDataChanged = false;

        synchronized (mEntryManager) {
            Set<NotificationEntry> allNotifications =
                    mEntryManager.getPendingAndActiveNotifications();
            Collection<NotificationEntry> allNotifications = mEntryManager.getAllNotifs();

            // Promote the media notification with a controller in 'playing' state, if any.
            NotificationEntry mediaNotification = null;
+18 −10
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import android.service.notification.NotificationListenerService.Ranking;
import android.service.notification.NotificationListenerService.RankingMap;
import android.service.notification.StatusBarNotification;
import android.util.ArrayMap;
import android.util.ArraySet;
import android.util.Log;

import com.android.internal.annotations.VisibleForTesting;
@@ -56,9 +57,9 @@ import com.android.systemui.util.leak.LeakDetector;
import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -105,6 +106,10 @@ public class NotificationEntryManager implements
     */
    public static final int UNDEFINED_DISMISS_REASON = 0;

    private final Set<NotificationEntry> mAllNotifications = new ArraySet<>();
    private final Set<NotificationEntry> mReadOnlyAllNotifications =
            Collections.unmodifiableSet(mAllNotifications);

    /** Pending notifications are ones awaiting inflation */
    @VisibleForTesting
    protected final HashMap<String, NotificationEntry> mPendingNotifications = new HashMap<>();
@@ -468,6 +473,8 @@ public class NotificationEntryManager implements
                    entry.removeRow();
                }

                mAllNotifications.remove(entry);

                // Let's remove the children if this was a summary
                handleGroupSummaryRemoved(key);
                removeVisibleNotification(key);
@@ -548,6 +555,7 @@ public class NotificationEntryManager implements
                notification,
                ranking,
                mFgsFeatureController.isForegroundServiceDismissalEnabled());
        mAllNotifications.add(entry);

        mLeakDetector.trackInstance(entry);

@@ -708,15 +716,6 @@ public class NotificationEntryManager implements
        return mPendingNotifications.values();
    }

    /**
     * @return all notifications we're currently aware of (both pending and active notifications)
     */
    public Set<NotificationEntry> getPendingAndActiveNotifications() {
        Set<NotificationEntry> allNotifs = new HashSet<>(mPendingNotifications.values());
        allNotifs.addAll(mSortedAndFiltered);
        return allNotifs;
    }

    /**
     * Use this method to retrieve a notification entry that has been prepared for presentation.
     * Note that the notification may be filtered out and never shown to the user.
@@ -861,6 +860,15 @@ public class NotificationEntryManager implements
        return mReadOnlyNotifications;
    }

    /**
     * Returns a collections containing ALL notifications we know about, including ones that are
     * hidden or for other users. See {@link CommonNotifCollection#getAllNotifs()}.
     */
    @Override
    public Collection<NotificationEntry> getAllNotifs() {
        return mReadOnlyAllNotifications;
    }

    /** @return A count of the active notifications */
    public int getActiveNotificationsCount() {
        return mReadOnlyNotifications.size();
+4 −4
Original line number Diff line number Diff line
@@ -172,8 +172,8 @@ public class NotifCollection implements Dumpable {
        mBuildListener = buildListener;
    }

    /** @see NotifPipeline#getActiveNotifs() */
    Collection<NotificationEntry> getActiveNotifs() {
    /** @see NotifPipeline#getAllNotifs() */
    Collection<NotificationEntry> getAllNotifs() {
        Assert.isMainThread();
        return mReadOnlyNotificationSet;
    }
@@ -279,7 +279,7 @@ public class NotifCollection implements Dumpable {
            // system process is dead if we're here.
        }

        final List<NotificationEntry> entries = new ArrayList<>(getActiveNotifs());
        final List<NotificationEntry> entries = new ArrayList<>(getAllNotifs());
        for (int i = entries.size() - 1; i >= 0; i--) {
            NotificationEntry entry = entries.get(i);
            if (!shouldDismissOnClearAll(entry, userId)) {
@@ -675,7 +675,7 @@ public class NotifCollection implements Dumpable {

    @Override
    public void dump(@NonNull FileDescriptor fd, PrintWriter pw, @NonNull String[] args) {
        final List<NotificationEntry> entries = new ArrayList<>(getActiveNotifs());
        final List<NotificationEntry> entries = new ArrayList<>(getAllNotifs());

        pw.println("\t" + TAG + " unsorted/unfiltered notifications:");
        if (entries.size() == 0) {
+3 −3
Original line number Diff line number Diff line
@@ -82,14 +82,14 @@ public class NotifPipeline implements CommonNotifCollection {
    }

    /**
     * Returns the list of "active" notifications, i.e. the notifications that are currently posted
     * Returns the list of all known notifications, i.e. the notifications that are currently posted
     * to the phone. In general, this tracks closely to the list maintained by NotificationManager,
     * but it can diverge slightly due to lifetime extenders.
     *
     * The returned collection is read-only, unsorted, unfiltered, and ungrouped.
     */
    public Collection<NotificationEntry> getActiveNotifs() {
        return mNotifCollection.getActiveNotifs();
    public Collection<NotificationEntry> getAllNotifs() {
        return mNotifCollection.getAllNotifs();
    }

    @Override
+1 −1
Original line number Diff line number Diff line
@@ -126,7 +126,7 @@ public class BubbleCoordinator implements Coordinator {
                mInterceptedDismissalEntries.remove(entry.getKey());
                mOnEndDismissInterception.onEndDismissInterception(mDismissInterceptor, entry,
                        createDismissedByUserStats(entry));
            } else if (mNotifPipeline.getActiveNotifs().contains(entry)) {
            } else if (mNotifPipeline.getAllNotifs().contains(entry)) {
                // Bubbles are hiding the notifications from the shade, but the bubble was
                // deleted; therefore, the notification should be cancelled as if it were a user
                // dismissal (this won't re-enter handleInterceptDimissal because Bubbles
Loading