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

Commit e6855d6e authored by Ned Burns's avatar Ned Burns
Browse files

Rename NotifServiceListener -> NotificationHandler

Just humor me here.

Test: atest
Change-Id: Iad7ed1af4cb2dae0880c0eb5e0e5195a59f9c16b
parent d7bf792d
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());
+3 −3
Original line number Diff line number Diff line
@@ -48,7 +48,7 @@ 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.NotificationListener.NotificationHandler;
import com.android.systemui.util.Assert;

import java.lang.annotation.Retention;
@@ -115,7 +115,7 @@ public class NotifCollection {
        }
        mAttached = true;

        listenerService.addNotificationListener(mNotifServiceListener);
        listenerService.addNotificationHandler(mNotificationHandler);
    }

    /**
@@ -372,7 +372,7 @@ public class NotifCollection {
        mAmDispatchingToOtherCode = false;
    }

    private final NotifServiceListener mNotifServiceListener = new NotifServiceListener() {
    private final NotificationHandler mNotificationHandler = new NotificationHandler() {
        @Override
        public void onNotificationPosted(StatusBarNotification sbn, RankingMap rankingMap) {
            NotifCollection.this.onNotificationPosted(sbn, rankingMap);
+6 −6
Original line number Diff line number Diff line
@@ -36,7 +36,7 @@ import android.testing.TestableLooper;
import androidx.test.filters.SmallTest;

import com.android.systemui.SysuiTestCase;
import com.android.systemui.statusbar.NotificationListener.NotifServiceListener;
import com.android.systemui.statusbar.NotificationListener.NotificationHandler;

import org.junit.Before;
import org.junit.Test;
@@ -51,7 +51,7 @@ public class NotificationListenerTest extends SysuiTestCase {
    private static final String TEST_PACKAGE_NAME = "test";
    private static final int TEST_UID = 0;

    @Mock private NotifServiceListener mServiceListener;
    @Mock private NotificationHandler mNotificationHandler;
    @Mock private NotificationManager mNotificationManager;

    private NotificationListener mListener;
@@ -69,21 +69,21 @@ public class NotificationListenerTest extends SysuiTestCase {
        mSbn = new StatusBarNotification(TEST_PACKAGE_NAME, TEST_PACKAGE_NAME, 0, null, TEST_UID, 0,
                new Notification(), UserHandle.CURRENT, null, 0);

        mListener.addNotificationListener(mServiceListener);
        mListener.addNotificationHandler(mNotificationHandler);
    }

    @Test
    public void testNotificationAddCallsAddNotification() {
        mListener.onNotificationPosted(mSbn, mRanking);
        TestableLooper.get(this).processAllMessages();
        verify(mServiceListener).onNotificationPosted(mSbn, mRanking);
        verify(mNotificationHandler).onNotificationPosted(mSbn, mRanking);
    }

    @Test
    public void testNotificationRemovalCallsRemoveNotification() {
        mListener.onNotificationRemoved(mSbn, mRanking);
        TestableLooper.get(this).processAllMessages();
        verify(mServiceListener).onNotificationRemoved(eq(mSbn), eq(mRanking), anyInt());
        verify(mNotificationHandler).onNotificationRemoved(eq(mSbn), eq(mRanking), anyInt());
    }

    @Test
@@ -91,7 +91,7 @@ public class NotificationListenerTest extends SysuiTestCase {
        mListener.onNotificationRankingUpdate(mRanking);
        TestableLooper.get(this).processAllMessages();
        // RankingMap may be modified by plugins.
        verify(mServiceListener).onNotificationRankingUpdate(any());
        verify(mNotificationHandler).onNotificationRankingUpdate(any());
    }

    @Test
+6 −6
Original line number Diff line number Diff line
@@ -23,7 +23,7 @@ import android.service.notification.NotificationListenerService.RankingMap;
import android.service.notification.StatusBarNotification;
import android.util.ArrayMap;

import com.android.systemui.statusbar.NotificationListener.NotifServiceListener;
import com.android.systemui.statusbar.NotificationListener.NotificationHandler;

import java.util.ArrayList;
import java.util.List;
@@ -36,13 +36,13 @@ import java.util.Map;
 * keep its RankingMap up to date and call appropriate event listeners.
 */
public class NoManSimulator {
    private final List<NotifServiceListener> mListeners = new ArrayList<>();
    private final List<NotificationHandler> mListeners = new ArrayList<>();
    private final Map<String, Ranking> mRankings = new ArrayMap<>();

    public NoManSimulator() {
    }

    public void addListener(NotifServiceListener listener) {
    public void addListener(NotificationHandler listener) {
        mListeners.add(listener);
    }

@@ -50,7 +50,7 @@ public class NoManSimulator {
        final NotificationEntry entry = builder.build();
        mRankings.put(entry.getKey(), entry.getRanking());
        final RankingMap rankingMap = buildRankingMap();
        for (NotifServiceListener listener : mListeners) {
        for (NotificationHandler listener : mListeners) {
            listener.onNotificationPosted(entry.getSbn(), rankingMap);
        }
        return new NotifEvent(entry.getSbn(), entry.getRanking(), rankingMap);
@@ -59,7 +59,7 @@ public class NoManSimulator {
    public NotifEvent retractNotif(StatusBarNotification sbn, int reason) {
        assertNotNull(mRankings.remove(sbn.getKey()));
        final RankingMap rankingMap = buildRankingMap();
        for (NotifServiceListener listener : mListeners) {
        for (NotificationHandler listener : mListeners) {
            listener.onNotificationRemoved(sbn, rankingMap, reason);
        }
        return new NotifEvent(sbn, null, rankingMap);
@@ -67,7 +67,7 @@ public class NoManSimulator {

    public void issueRankingUpdate() {
        final RankingMap rankingMap = buildRankingMap();
        for (NotifServiceListener listener : mListeners) {
        for (NotificationHandler listener : mListeners) {
            listener.onNotificationRankingUpdate(rankingMap);
        }
    }
Loading