Remove Dependency.get(MAIN_HANDLER) from NotificationListener
Bug: 144503618
Test: atest SystemUITests
Change-Id: Ia919358337798b94b7b33625435aa3b603fb0455
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationListener.java b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationListener.java
index 98a2675..9dcfb6a 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.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 @@
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 @@
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 @@
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 @@
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 @@
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 2f53a01..8e6f4d7 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 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 @@
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 @@
@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);
}