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

Commit 26bc59b5 authored by Gus Prevas's avatar Gus Prevas
Browse files

Combines NotificationEntryManager listener interfaces (part 1).

This change combines the NotificationEntryManager.Callback interface
with the NotificationEntryListener interface.

Future changes will reduce duplication between the methods in these
interfaces, move the previous Callback instance into the list of
listeners instead of having its own special field, and introduce more
listeners to replace logic that's proactively invoked in
NotificationEntryManager, but this first step is just a pure combination
of the two interfaces.

Test: atest SystemUITests, manual
Change-Id: Ifafcee697e7dd35e0aaae32f677ef1582f8d5920
parent d65c2db9
Loading
Loading
Loading
Loading
+0 −2
Original line number Original line Diff line number Diff line
@@ -15,7 +15,6 @@
 */
 */
package com.android.systemui.statusbar;
package com.android.systemui.statusbar;


import com.android.systemui.statusbar.notification.NotificationEntryManager;
import com.android.systemui.statusbar.notification.NotificationRowBinder;
import com.android.systemui.statusbar.notification.NotificationRowBinder;
import com.android.systemui.statusbar.notification.row.ActivatableNotificationView;
import com.android.systemui.statusbar.notification.row.ActivatableNotificationView;
import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow;
import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow;
@@ -29,7 +28,6 @@ import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow
 */
 */
public interface NotificationPresenter extends ExpandableNotificationRow.OnExpandClickListener,
public interface NotificationPresenter extends ExpandableNotificationRow.OnExpandClickListener,
        ActivatableNotificationView.OnActivatedListener,
        ActivatableNotificationView.OnActivatedListener,
        NotificationEntryManager.Callback,
        NotificationRowBinder.BindRowCallback {
        NotificationRowBinder.BindRowCallback {
    /**
    /**
     * Returns true if the presenter is not visible. For example, it may not be necessary to do
     * Returns true if the presenter is not visible. For example, it may not be necessary to do
+33 −0
Original line number Original line Diff line number Diff line
@@ -15,6 +15,8 @@
 */
 */
package com.android.systemui.statusbar.notification;
package com.android.systemui.statusbar.notification;


import android.service.notification.StatusBarNotification;

/**
/**
 * Listener interface for changes sent by NotificationEntryManager.
 * Listener interface for changes sent by NotificationEntryManager.
 */
 */
@@ -26,6 +28,18 @@ public interface NotificationEntryListener {
    default void onPendingEntryAdded(NotificationData.Entry entry) {
    default void onPendingEntryAdded(NotificationData.Entry entry) {
    }
    }


    /**
     * Called when a new entry is created.
     */
    default void onNotificationAdded(NotificationData.Entry entry) {
    }

    /**
     * Called when a notification was updated.
     */
    default void onNotificationUpdated(StatusBarNotification notification) {
    }

    /**
    /**
     * Called when an existing notification's views are reinflated (usually due to an update being
     * Called when an existing notification's views are reinflated (usually due to an update being
     * posted to that notification).
     * posted to that notification).
@@ -36,7 +50,26 @@ public interface NotificationEntryListener {
    /**
    /**
     * Called when a notification has been removed (either because the user swiped it away or
     * Called when a notification has been removed (either because the user swiped it away or
     * because the developer retracted it).
     * because the developer retracted it).
     *
     * TODO: combine this with onNotificationRemoved().
     */
     */
    default void onEntryRemoved(NotificationData.Entry entry) {
    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
     */
    default void onNotificationRemoved(String key, StatusBarNotification old) {
    }

    /**
     * Removes a notification immediately.
     *
     * TODO: combine this with onNotificationRemoved().
     */
    default void onPerformRemoveNotification(StatusBarNotification statusBarNotification) {
    }
}
}
+2 −37
Original line number Original line Diff line number Diff line
@@ -117,7 +117,7 @@ public class NotificationEntryManager implements


    protected IStatusBarService mBarService;
    protected IStatusBarService mBarService;
    private NotificationPresenter mPresenter;
    private NotificationPresenter mPresenter;
    private Callback mCallback;
    private NotificationEntryListener mCallback;
    protected PowerManager mPowerManager;
    protected PowerManager mPowerManager;
    private NotificationListenerService.RankingMap mLatestRankingMap;
    private NotificationListenerService.RankingMap mLatestRankingMap;
    protected HeadsUpManager mHeadsUpManager;
    protected HeadsUpManager mHeadsUpManager;
@@ -208,7 +208,7 @@ public class NotificationEntryManager implements
    }
    }


    public void setUpWithPresenter(NotificationPresenter presenter,
    public void setUpWithPresenter(NotificationPresenter presenter,
            NotificationListContainer listContainer, Callback callback,
            NotificationListContainer listContainer, NotificationEntryListener callback,
            HeadsUpManager headsUpManager) {
            HeadsUpManager headsUpManager) {
        mPresenter = presenter;
        mPresenter = presenter;
        mUpdateNotificationViewsCallback = mPresenter::updateNotificationViews;
        mUpdateNotificationViewsCallback = mPresenter::updateNotificationViews;
@@ -784,39 +784,4 @@ public class NotificationEntryManager implements
    public Iterable<NotificationData.Entry> getPendingNotificationsIterator() {
    public Iterable<NotificationData.Entry> getPendingNotificationsIterator() {
        return mPendingNotifications.values();
        return mPendingNotifications.values();
    }
    }

    /**
     * Callback for NotificationEntryManager.
     */
    public interface Callback {

        /**
         * Called when a new entry is created.
         *
         * @param shadeEntry entry that was created
         */
        void onNotificationAdded(NotificationData.Entry shadeEntry);

        /**
         * Called when a notification was updated.
         *
         * @param notification notification that was updated
         */
        void onNotificationUpdated(StatusBarNotification notification);

        /**
         * Called when a notification was removed.
         *
         * @param key key of notification that was removed
         * @param old StatusBarNotification of the notification before it was removed
         */
        void onNotificationRemoved(String key, StatusBarNotification old);

        /**
         * Removes a notification immediately.
         *
         * @param statusBarNotification notification that is being removed
         */
        void onPerformRemoveNotification(StatusBarNotification statusBarNotification);
    }
}
}
+28 −15
Original line number Original line Diff line number Diff line
@@ -57,6 +57,7 @@ import com.android.systemui.statusbar.StatusBarStateController;
import com.android.systemui.statusbar.notification.AboveShelfObserver;
import com.android.systemui.statusbar.notification.AboveShelfObserver;
import com.android.systemui.statusbar.notification.ActivityLaunchAnimator;
import com.android.systemui.statusbar.notification.ActivityLaunchAnimator;
import com.android.systemui.statusbar.notification.NotificationData.Entry;
import com.android.systemui.statusbar.notification.NotificationData.Entry;
import com.android.systemui.statusbar.notification.NotificationEntryListener;
import com.android.systemui.statusbar.notification.NotificationEntryManager;
import com.android.systemui.statusbar.notification.NotificationEntryManager;
import com.android.systemui.statusbar.notification.NotificationInterruptionStateProvider;
import com.android.systemui.statusbar.notification.NotificationInterruptionStateProvider;
import com.android.systemui.statusbar.notification.NotificationRowBinder;
import com.android.systemui.statusbar.notification.NotificationRowBinder;
@@ -172,8 +173,33 @@ public class StatusBarNotificationPresenter implements NotificationPresenter,


        NotificationListContainer notifListContainer = (NotificationListContainer) stackScroller;
        NotificationListContainer notifListContainer = (NotificationListContainer) stackScroller;
        Dependency.get(InitController.class).addPostInitTask(() -> {
        Dependency.get(InitController.class).addPostInitTask(() -> {
            NotificationEntryListener notificationEntryListener = new NotificationEntryListener() {
                @Override
                public void onNotificationAdded(Entry entry) {
                    // Recalculate the position of the sliding windows and the titles.
                    mShadeController.updateAreThereNotifications();
                }

                @Override
                public void onNotificationUpdated(StatusBarNotification notification) {
                    mShadeController.updateAreThereNotifications();
                }

                @Override
                public void onNotificationRemoved(String key, StatusBarNotification old) {
                    StatusBarNotificationPresenter.this.onNotificationRemoved(key, old);
                }

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

            mViewHierarchyManager.setUpWithPresenter(this, notifListContainer);
            mViewHierarchyManager.setUpWithPresenter(this, notifListContainer);
            mEntryManager.setUpWithPresenter(this, notifListContainer, this, mHeadsUpManager);
            mEntryManager.setUpWithPresenter(
                    this, notifListContainer, notificationEntryListener, mHeadsUpManager);
            mNotificationRowBinder.setUpWithPresenter(this, notifListContainer, mHeadsUpManager,
            mNotificationRowBinder.setUpWithPresenter(this, notifListContainer, mHeadsUpManager,
                    mEntryManager, this);
                    mEntryManager, this);
            mNotificationInterruptionStateProvider.setUpWithPresenter(
            mNotificationInterruptionStateProvider.setUpWithPresenter(
@@ -227,8 +253,7 @@ public class StatusBarNotificationPresenter implements NotificationPresenter,
                || mActivityLaunchAnimator.isAnimationRunning();
                || mActivityLaunchAnimator.isAnimationRunning();
    }
    }


    @Override
    private void onPerformRemoveNotification() {
    public void onPerformRemoveNotification(StatusBarNotification n) {
        if (mNotificationPanel.hasPulsingNotifications() &&
        if (mNotificationPanel.hasPulsingNotifications() &&
                !mAmbientPulseManager.hasNotifications()) {
                !mAmbientPulseManager.hasNotifications()) {
            // We were showing a pulse for a notification, but no notifications are pulsing anymore.
            // We were showing a pulse for a notification, but no notifications are pulsing anymore.
@@ -254,18 +279,6 @@ public class StatusBarNotificationPresenter implements NotificationPresenter,
        mNotificationPanel.updateNotificationViews();
        mNotificationPanel.updateNotificationViews();
    }
    }


    @Override
    public void onNotificationAdded(Entry shadeEntry) {
        // Recalculate the position of the sliding windows and the titles.
        mShadeController.updateAreThereNotifications();
    }

    @Override
    public void onNotificationUpdated(StatusBarNotification notification) {
        mShadeController.updateAreThereNotifications();
    }

    @Override
    public void onNotificationRemoved(String key, StatusBarNotification old) {
    public void onNotificationRemoved(String key, StatusBarNotification old) {
        if (SPEW) Log.d(TAG, "removeNotification key=" + key + " old=" + old);
        if (SPEW) Log.d(TAG, "removeNotification key=" + key + " old=" + old);


+3 −1
Original line number Original line Diff line number Diff line
@@ -26,6 +26,7 @@ import android.testing.TestableLooper;
import com.android.systemui.Dependency;
import com.android.systemui.Dependency;
import com.android.systemui.InitController;
import com.android.systemui.InitController;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.statusbar.notification.NotificationEntryListener;
import com.android.systemui.statusbar.notification.NotificationEntryManager;
import com.android.systemui.statusbar.notification.NotificationEntryManager;
import com.android.systemui.statusbar.notification.logging.NotificationLogger;
import com.android.systemui.statusbar.notification.logging.NotificationLogger;
import com.android.systemui.statusbar.notification.row.NotificationGutsManager;
import com.android.systemui.statusbar.notification.row.NotificationGutsManager;
@@ -55,7 +56,8 @@ import org.mockito.MockitoAnnotations;
public class NonPhoneDependencyTest extends SysuiTestCase {
public class NonPhoneDependencyTest extends SysuiTestCase {
    @Mock private NotificationPresenter mPresenter;
    @Mock private NotificationPresenter mPresenter;
    @Mock private NotificationListContainer mListContainer;
    @Mock private NotificationListContainer mListContainer;
    @Mock private NotificationEntryManager.Callback mEntryManagerCallback;
    @Mock
    private NotificationEntryListener mEntryManagerCallback;
    @Mock private HeadsUpManager mHeadsUpManager;
    @Mock private HeadsUpManager mHeadsUpManager;
    @Mock private RemoteInputController.Delegate mDelegate;
    @Mock private RemoteInputController.Delegate mDelegate;
    @Mock private NotificationRemoteInputManager.Callback mRemoteInputManagerCallback;
    @Mock private NotificationRemoteInputManager.Callback mRemoteInputManagerCallback;
Loading