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

Commit c5e79585 authored by Dave Mankoff's avatar Dave Mankoff
Browse files

Remove Dependency.get(MAIN_HANDLER) from NotificationListener

Bug: 144503618
Test: atest SystemUITests
Change-Id: Ia919358337798b94b7b33625435aa3b603fb0455
parent ad51c4d8
Loading
Loading
Loading
Loading
+15 −12
Original line number Diff line number Diff line
@@ -26,12 +26,13 @@ import android.annotation.SuppressLint;
import android.app.NotificationManager;
import android.content.ComponentName;
import android.content.Context;
import android.os.Handler;
import android.os.RemoteException;
import android.os.UserHandle;
import android.service.notification.StatusBarNotification;
import android.util.Log;

import com.android.systemui.Dependency;
import com.android.systemui.dagger.qualifiers.MainHandler;
import com.android.systemui.statusbar.notification.NotificationEntryManager;
import com.android.systemui.statusbar.phone.NotificationGroupManager;
import com.android.systemui.statusbar.phone.NotificationListenerWithPlugins;
@@ -51,20 +52,22 @@ public class NotificationListener extends NotificationListenerWithPlugins {
    private static final String TAG = "NotificationListener";

    // Dependencies:
    private final NotificationRemoteInputManager mRemoteInputManager =
            Dependency.get(NotificationRemoteInputManager.class);
    private final NotificationEntryManager mEntryManager =
            Dependency.get(NotificationEntryManager.class);
    private final NotificationGroupManager mGroupManager =
            Dependency.get(NotificationGroupManager.class);
    private final NotificationEntryManager mEntryManager;
    private final NotificationGroupManager mGroupManager;

    private final Context mContext;
    private final Handler mMainHandler;
    private final ArrayList<NotificationSettingsListener> mSettingsListeners = new ArrayList<>();
    @Nullable private NotifServiceListener mDownstreamListener;

    @Inject
    public NotificationListener(Context context) {
    public NotificationListener(Context context, @MainHandler Handler mainHandler,
            NotificationEntryManager notificationEntryManager,
            NotificationGroupManager notificationGroupManager) {
        mContext = context;
        mMainHandler = mainHandler;
        mEntryManager = notificationEntryManager;
        mGroupManager = notificationGroupManager;
    }

    public void addNotificationSettingsListener(NotificationSettingsListener listener) {
@@ -85,7 +88,7 @@ public class NotificationListener extends NotificationListenerWithPlugins {
            return;
        }
        final RankingMap currentRanking = getCurrentRanking();
        Dependency.get(Dependency.MAIN_HANDLER).post(() -> {
        mMainHandler.post(() -> {
            for (StatusBarNotification sbn : notifications) {
                if (mDownstreamListener != null) {
                    mDownstreamListener.onNotificationPosted(sbn, currentRanking);
@@ -102,7 +105,7 @@ public class NotificationListener extends NotificationListenerWithPlugins {
            final RankingMap rankingMap) {
        if (DEBUG) Log.d(TAG, "onNotificationPosted: " + sbn);
        if (sbn != null && !onPluginNotificationPosted(sbn, rankingMap)) {
            Dependency.get(Dependency.MAIN_HANDLER).post(() -> {
            mMainHandler.post(() -> {
                processForRemoteInput(sbn.getNotification(), mContext);

                if (mDownstreamListener != null) {
@@ -144,7 +147,7 @@ public class NotificationListener extends NotificationListenerWithPlugins {
        if (DEBUG) Log.d(TAG, "onNotificationRemoved: " + sbn + " reason: " + reason);
        if (sbn != null && !onPluginNotificationRemoved(sbn, rankingMap)) {
            final String key = sbn.getKey();
            Dependency.get(Dependency.MAIN_HANDLER).post(() -> {
            mMainHandler.post(() -> {
                if (mDownstreamListener != null) {
                    mDownstreamListener.onNotificationRemoved(sbn, rankingMap, reason);
                }
@@ -163,7 +166,7 @@ public class NotificationListener extends NotificationListenerWithPlugins {
        if (DEBUG) Log.d(TAG, "onRankingUpdate");
        if (rankingMap != null) {
            RankingMap r = onPluginRankingUpdate(rankingMap);
            Dependency.get(Dependency.MAIN_HANDLER).post(() -> {
            mMainHandler.post(() -> {
                if (mDownstreamListener != null) {
                    mDownstreamListener.onNotificationRankingUpdate(rankingMap);
                }
+5 −9
Original line number Diff line number Diff line
@@ -34,9 +34,9 @@ import android.testing.TestableLooper;

import androidx.test.filters.SmallTest;

import com.android.systemui.Dependency;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.statusbar.notification.NotificationEntryManager;
import com.android.systemui.statusbar.phone.NotificationGroupManager;

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

    @Mock private NotificationPresenter mPresenter;
    @Mock private NotificationListenerService.RankingMap mRanking;

    // Dependency mocks:
    @Mock private NotificationEntryManager mEntryManager;
    @Mock private NotificationRemoteInputManager mRemoteInputManager;
    @Mock private NotificationManager mNotificationManager;
    @Mock private NotificationGroupManager mNotificationGroupManager;

    private NotificationListener mListener;
    private StatusBarNotification mSbn;
@@ -65,14 +64,11 @@ public class NotificationListenerTest extends SysuiTestCase {
    @Before
    public void setUp() {
        MockitoAnnotations.initMocks(this);
        mDependency.injectTestDependency(NotificationEntryManager.class, mEntryManager);
        mDependency.injectTestDependency(NotificationRemoteInputManager.class,
                mRemoteInputManager);
        mDependency.injectTestDependency(Dependency.MAIN_HANDLER,
                new Handler(TestableLooper.get(this).getLooper()));
        mContext.addMockSystemService(NotificationManager.class, mNotificationManager);

        mListener = new NotificationListener(mContext);
        mListener = new NotificationListener(mContext,
                new Handler(TestableLooper.get(this).getLooper()), mEntryManager,
                mNotificationGroupManager);
        mSbn = new StatusBarNotification(TEST_PACKAGE_NAME, TEST_PACKAGE_NAME, 0, null, TEST_UID, 0,
                new Notification(), UserHandle.CURRENT, null, 0);
    }