diff options
| author | 2019-11-20 18:10:35 +0000 | |
|---|---|---|
| committer | 2019-11-20 18:10:35 +0000 | |
| commit | 56e2bd284f78ad286e17f9c4cad9ecaaaba5213a (patch) | |
| tree | aeed3159e590532d5005fe073df02cb6b9b94e19 | |
| parent | e83eb253b17b43bdf7738afc066f025b0daefc40 (diff) | |
| parent | c5e795858731b29927df33b3f1c8b4036b62899e (diff) | |
Merge "Remove Dependency.get(MAIN_HANDLER) from NotificationListener"
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/statusbar/NotificationListener.java | 27 | ||||
| -rw-r--r-- | packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationListenerTest.java | 14 |
2 files changed, 20 insertions, 21 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationListener.java b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationListener.java index 98a267599f7e..9dcfb6a8a4c6 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationListener.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationListener.java @@ -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); } diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationListenerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationListenerTest.java index 2f53a01b1d69..8e6f4d7dd793 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationListenerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationListenerTest.java @@ -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); } |