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

Commit 31ad79e7 authored by Ned Burns's avatar Ned Burns Committed by Android (Google) Code Review
Browse files

Merge changes I4b5dd1a6,I47cb9c8b,Iad7ed1af,I44c0b13c

* changes:
  Add GroupCoalescer to new pipeline
  Remove onBeginDispatchToListeners from CollectionReadyForBuildListener
  Rename NotifServiceListener -> NotificationHandler
  Extract NoManSimulator to top level
parents da8c253b a944ea3e
Loading
Loading
Loading
Loading
+12 −12
Original line number Diff line number Diff line
@@ -51,7 +51,7 @@ public class NotificationListener extends NotificationListenerWithPlugins {
    private final Context mContext;
    private final NotificationManager mNotificationManager;
    private final Handler mMainHandler;
    private final List<NotifServiceListener> mNotificationListeners = new ArrayList<>();
    private final List<NotificationHandler> mNotificationHandlers = new ArrayList<>();
    private final ArrayList<NotificationSettingsListener> mSettingsListeners = new ArrayList<>();

    @Inject
@@ -65,11 +65,11 @@ public class NotificationListener extends NotificationListenerWithPlugins {
    }

    /** Registers a listener that's notified when notifications are added/removed/etc. */
    public void addNotificationListener(NotifServiceListener listener) {
        if (mNotificationListeners.contains(listener)) {
    public void addNotificationHandler(NotificationHandler handler) {
        if (mNotificationHandlers.contains(handler)) {
            throw new IllegalArgumentException("Listener is already added");
        }
        mNotificationListeners.add(listener);
        mNotificationHandlers.add(handler);
    }

    /** Registers a listener that's notified when any notification-related settings change. */
@@ -100,7 +100,7 @@ public class NotificationListener extends NotificationListenerWithPlugins {
            final RankingMap completeMap = new RankingMap(newRankings.toArray(new Ranking[0]));

            for (StatusBarNotification sbn : notifications) {
                for (NotifServiceListener listener : mNotificationListeners) {
                for (NotificationHandler listener : mNotificationHandlers) {
                    listener.onNotificationPosted(sbn, completeMap);
                }
            }
@@ -117,8 +117,8 @@ public class NotificationListener extends NotificationListenerWithPlugins {
            mMainHandler.post(() -> {
                processForRemoteInput(sbn.getNotification(), mContext);

                for (NotifServiceListener listener : mNotificationListeners) {
                    listener.onNotificationPosted(sbn, rankingMap);
                for (NotificationHandler handler : mNotificationHandlers) {
                    handler.onNotificationPosted(sbn, rankingMap);
                }
            });
        }
@@ -130,8 +130,8 @@ public class NotificationListener extends NotificationListenerWithPlugins {
        if (DEBUG) Log.d(TAG, "onNotificationRemoved: " + sbn + " reason: " + reason);
        if (sbn != null && !onPluginNotificationRemoved(sbn, rankingMap)) {
            mMainHandler.post(() -> {
                for (NotifServiceListener listener : mNotificationListeners) {
                    listener.onNotificationRemoved(sbn, rankingMap, reason);
                for (NotificationHandler handler : mNotificationHandlers) {
                    handler.onNotificationRemoved(sbn, rankingMap, reason);
                }
            });
        }
@@ -148,8 +148,8 @@ public class NotificationListener extends NotificationListenerWithPlugins {
        if (rankingMap != null) {
            RankingMap r = onPluginRankingUpdate(rankingMap);
            mMainHandler.post(() -> {
                for (NotifServiceListener listener : mNotificationListeners) {
                    listener.onNotificationRankingUpdate(r);
                for (NotificationHandler handler : mNotificationHandlers) {
                    handler.onNotificationRankingUpdate(r);
                }
            });
        }
@@ -207,7 +207,7 @@ public class NotificationListener extends NotificationListenerWithPlugins {
    }

    /** Interface for listening to add/remove events that we receive from NotificationManager. */
    public interface NotifServiceListener {
    public interface NotificationHandler {
        void onNotificationPosted(StatusBarNotification sbn, RankingMap rankingMap);
        void onNotificationRemoved(StatusBarNotification sbn, RankingMap rankingMap);
        void onNotificationRemoved(StatusBarNotification sbn, RankingMap rankingMap, int reason);
+3 −3
Original line number Diff line number Diff line
@@ -36,7 +36,7 @@ import com.android.systemui.Dependency;
import com.android.systemui.Dumpable;
import com.android.systemui.statusbar.NotificationLifetimeExtender;
import com.android.systemui.statusbar.NotificationListener;
import com.android.systemui.statusbar.NotificationListener.NotifServiceListener;
import com.android.systemui.statusbar.NotificationListener.NotificationHandler;
import com.android.systemui.statusbar.NotificationPresenter;
import com.android.systemui.statusbar.NotificationRemoteInputManager;
import com.android.systemui.statusbar.NotificationRemoveInterceptor;
@@ -179,7 +179,7 @@ public class NotificationEntryManager implements

    /** Once called, the NEM will start processing notification events from system server. */
    public void attach(NotificationListener notificationListener) {
        notificationListener.addNotificationListener(mNotifListener);
        notificationListener.addNotificationHandler(mNotifListener);
    }

    /** Adds a {@link NotificationEntryListener}. */
@@ -326,7 +326,7 @@ public class NotificationEntryManager implements
        }
    }

    private final NotifServiceListener mNotifListener = new NotifServiceListener() {
    private final NotificationHandler mNotifListener = new NotificationHandler() {
        @Override
        public void onNotificationPosted(StatusBarNotification sbn, RankingMap rankingMap) {
            final boolean isUpdate = mActiveNotifications.containsKey(sbn.getKey());
+0 −12
Original line number Diff line number Diff line
@@ -23,18 +23,6 @@ import java.util.Collection;
 * filtered, and grouped list of currently visible notifications.
 */
public interface CollectionReadyForBuildListener {
    /**
     * Called after the NotifCollection has received an update from NotificationManager but before
     * it dispatches any change events to its listeners. This is to inform the list builder that
     * the first stage of the pipeline has been triggered. After events have been dispatched,
     * onBuildList() will be called.
     *
     * While onBuildList() is always called after this method is called, the converse is not always
     * true: sometimes the NotifCollection applies an update that does not need to dispatch events,
     * in which case this method will be skipped and onBuildList will be called directly.
     */
    void onBeginDispatchToListeners();

    /**
     * Called by the NotifCollection to indicate that something in the collection has changed and
     * that the list builder should regenerate the list.
+55 −36
Original line number Diff line number Diff line
@@ -47,8 +47,9 @@ import android.util.ArrayMap;
import android.util.Log;

import com.android.internal.statusbar.IStatusBarService;
import com.android.systemui.statusbar.NotificationListener;
import com.android.systemui.statusbar.NotificationListener.NotifServiceListener;
import com.android.systemui.statusbar.notification.collection.notifcollection.CoalescedEvent;
import com.android.systemui.statusbar.notification.collection.notifcollection.GroupCoalescer;
import com.android.systemui.statusbar.notification.collection.notifcollection.GroupCoalescer.BatchableNotificationHandler;
import com.android.systemui.util.Assert;

import java.lang.annotation.Retention;
@@ -108,14 +109,14 @@ public class NotifCollection {
    }

    /** Initializes the NotifCollection and registers it to receive notification events. */
    public void attach(NotificationListener listenerService) {
    public void attach(GroupCoalescer groupCoalescer) {
        Assert.isMainThread();
        if (mAttached) {
            throw new RuntimeException("attach() called twice");
        }
        mAttached = true;

        listenerService.addNotificationListener(mNotifServiceListener);
        groupCoalescer.setNotificationHandler(mNotifHandler);
    }

    /**
@@ -178,15 +179,52 @@ public class NotifCollection {
    private void onNotificationPosted(StatusBarNotification sbn, RankingMap rankingMap) {
        Assert.isMainThread();

        postNotification(sbn, requireRanking(rankingMap, sbn.getKey()), rankingMap);
        rebuildList();
    }

    private void onNotificationGroupPosted(List<CoalescedEvent> batch) {
        Assert.isMainThread();

        Log.d(TAG, "POSTED GROUP " + batch.get(0).getSbn().getGroupKey()
                + " (" + batch.size() + " events)");
        for (CoalescedEvent event : batch) {
            postNotification(event.getSbn(), event.getRanking(), null);
        }
        rebuildList();
    }

    private void onNotificationRemoved(
            StatusBarNotification sbn,
            RankingMap rankingMap,
            int reason) {
        Assert.isMainThread();

        Log.d(TAG, "REMOVED " + sbn.getKey() + " reason=" + reason);
        removeNotification(sbn.getKey(), rankingMap, reason, null);
    }

    private void onNotificationRankingUpdate(RankingMap rankingMap) {
        Assert.isMainThread();
        applyRanking(rankingMap);
        rebuildList();
    }

    private void postNotification(
            StatusBarNotification sbn,
            Ranking ranking,
            @Nullable RankingMap rankingMap) {
        NotificationEntry entry = mNotificationSet.get(sbn.getKey());

        if (entry == null) {
            // A new notification!
            Log.d(TAG, "POSTED  " + sbn.getKey());

            entry = new NotificationEntry(sbn, requireRanking(rankingMap, sbn.getKey()));
            entry = new NotificationEntry(sbn, ranking);
            mNotificationSet.put(sbn.getKey(), entry);
            if (rankingMap != null) {
                applyRanking(rankingMap);
            }

            dispatchOnEntryAdded(entry);

@@ -199,34 +237,19 @@ public class NotifCollection {
            cancelLifetimeExtension(entry);

            entry.setSbn(sbn);
            if (rankingMap != null) {
                applyRanking(rankingMap);

            dispatchOnEntryUpdated(entry);
            }

        rebuildList();
            dispatchOnEntryUpdated(entry);
        }

    private void onNotificationRemoved(
            StatusBarNotification sbn,
            @Nullable RankingMap rankingMap,
            int reason) {
        Assert.isMainThread();
        Log.d(TAG, "REMOVED " + sbn.getKey() + " reason=" + reason);
        removeNotification(sbn.getKey(), rankingMap, reason, null);
    }

    private void onNotificationRankingUpdate(RankingMap rankingMap) {
        Assert.isMainThread();
        applyRanking(rankingMap);
        rebuildList();
    }

    private void removeNotification(
            String key,
            @Nullable RankingMap rankingMap,
            @CancellationReason int reason,
            DismissedByUserStats dismissedByUserStats) {
            @Nullable DismissedByUserStats dismissedByUserStats) {

        NotificationEntry entry = mNotificationSet.get(key);
        if (entry == null) {
@@ -271,7 +294,7 @@ public class NotifCollection {
        rebuildList();
    }

    private void applyRanking(RankingMap rankingMap) {
    private void applyRanking(@NonNull RankingMap rankingMap) {
        for (NotificationEntry entry : mNotificationSet.values()) {
            if (!isLifetimeExtended(entry)) {
                Ranking ranking = requireRanking(rankingMap, entry.getKey());
@@ -338,9 +361,6 @@ public class NotifCollection {

    private void dispatchOnEntryAdded(NotificationEntry entry) {
        mAmDispatchingToOtherCode = true;
        if (mBuildListener != null) {
            mBuildListener.onBeginDispatchToListeners();
        }
        for (NotifCollectionListener listener : mNotifCollectionListeners) {
            listener.onEntryAdded(entry);
        }
@@ -349,9 +369,6 @@ public class NotifCollection {

    private void dispatchOnEntryUpdated(NotificationEntry entry) {
        mAmDispatchingToOtherCode = true;
        if (mBuildListener != null) {
            mBuildListener.onBeginDispatchToListeners();
        }
        for (NotifCollectionListener listener : mNotifCollectionListeners) {
            listener.onEntryUpdated(entry);
        }
@@ -363,21 +380,23 @@ public class NotifCollection {
            @CancellationReason int reason,
            boolean removedByUser) {
        mAmDispatchingToOtherCode = true;
        if (mBuildListener != null) {
            mBuildListener.onBeginDispatchToListeners();
        }
        for (NotifCollectionListener listener : mNotifCollectionListeners) {
            listener.onEntryRemoved(entry, reason, removedByUser);
        }
        mAmDispatchingToOtherCode = false;
    }

    private final NotifServiceListener mNotifServiceListener = new NotifServiceListener() {
    private final BatchableNotificationHandler mNotifHandler = new BatchableNotificationHandler() {
        @Override
        public void onNotificationPosted(StatusBarNotification sbn, RankingMap rankingMap) {
            NotifCollection.this.onNotificationPosted(sbn, rankingMap);
        }

        @Override
        public void onNotificationBatchPosted(List<CoalescedEvent> events) {
            NotifCollection.this.onNotificationGroupPosted(events);
        }

        @Override
        public void onNotificationRemoved(StatusBarNotification sbn, RankingMap rankingMap) {
            NotifCollection.this.onNotificationRemoved(sbn, rankingMap, REASON_UNKNOWN);
+0 −7
Original line number Diff line number Diff line
@@ -18,7 +18,6 @@ package com.android.systemui.statusbar.notification.collection;

import static com.android.systemui.statusbar.notification.collection.GroupEntry.ROOT_ENTRY;
import static com.android.systemui.statusbar.notification.collection.ListDumper.dumpList;
import static com.android.systemui.statusbar.notification.collection.listbuilder.PipelineState.STATE_BUILD_PENDING;
import static com.android.systemui.statusbar.notification.collection.listbuilder.PipelineState.STATE_BUILD_STARTED;
import static com.android.systemui.statusbar.notification.collection.listbuilder.PipelineState.STATE_FINALIZING;
import static com.android.systemui.statusbar.notification.collection.listbuilder.PipelineState.STATE_GROUPING;
@@ -197,12 +196,6 @@ public class NotifListBuilderImpl implements NotifListBuilder {

    private final CollectionReadyForBuildListener mReadyForBuildListener =
            new CollectionReadyForBuildListener() {
                @Override
                public void onBeginDispatchToListeners() {
                    Assert.isMainThread();
                    mPipelineState.incrementTo(STATE_BUILD_PENDING);
                }

                @Override
                public void onBuildList(Collection<NotificationEntry> entries) {
                    Assert.isMainThread();
Loading