summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Burns <pixel@google.com>2019-12-17 23:32:26 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2019-12-17 23:32:26 +0000
commit6d05f1df50c93fc99347640a7060d1166a49be6f (patch)
treeba657bb7f2a518541c9cda215d643bf340f9a405
parentad2d19a0d6e8ddd11c11e5548b03ae9c4fad7f1a (diff)
parent2246b33f5fc2197394dc528762cb49fb9a0427d5 (diff)
Merge "Unify listener interfaces in NotificationListener"
-rw-r--r--packages/SystemUI/src/com/android/systemui/dagger/SystemServicesModule.java7
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/NotificationListener.java84
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationEntryManager.java37
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationFilter.java6
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotifCollection.java2
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRow.java11
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java4
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationListenerTest.java41
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/NotifCollectionTest.java2
9 files changed, 92 insertions, 102 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/dagger/SystemServicesModule.java b/packages/SystemUI/src/com/android/systemui/dagger/SystemServicesModule.java
index f032a33c45a9..534f350e4898 100644
--- a/packages/SystemUI/src/com/android/systemui/dagger/SystemServicesModule.java
+++ b/packages/SystemUI/src/com/android/systemui/dagger/SystemServicesModule.java
@@ -23,6 +23,7 @@ import android.app.AlarmManager;
import android.app.IActivityManager;
import android.app.IWallpaperManager;
import android.app.KeyguardManager;
+import android.app.NotificationManager;
import android.app.WallpaperManager;
import android.app.admin.DevicePolicyManager;
import android.content.Context;
@@ -131,6 +132,12 @@ public class SystemServicesModule {
@Singleton
@Provides
+ static NotificationManager provideNotificationManager(Context context) {
+ return context.getSystemService(NotificationManager.class);
+ }
+
+ @Singleton
+ @Provides
static PackageManagerWrapper providePackageManagerWrapper() {
return PackageManagerWrapper.getInstance();
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationListener.java b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationListener.java
index 9a64b30ed918..97dd3daae341 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationListener.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationListener.java
@@ -19,9 +19,7 @@ package com.android.systemui.statusbar;
import static com.android.systemui.statusbar.RemoteInputController.processForRemoteInput;
import static com.android.systemui.statusbar.notification.NotificationEntryManager.UNDEFINED_DISMISS_REASON;
import static com.android.systemui.statusbar.phone.StatusBar.DEBUG;
-import static com.android.systemui.statusbar.phone.StatusBar.ENABLE_CHILD_NOTIFICATIONS;
-import android.annotation.Nullable;
import android.annotation.SuppressLint;
import android.app.NotificationManager;
import android.content.ComponentName;
@@ -33,8 +31,6 @@ import android.service.notification.StatusBarNotification;
import android.util.Log;
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;
import java.util.ArrayList;
@@ -52,31 +48,33 @@ import javax.inject.Singleton;
public class NotificationListener extends NotificationListenerWithPlugins {
private static final String TAG = "NotificationListener";
- // Dependencies:
- private final NotificationEntryManager mEntryManager;
- private final NotificationGroupManager mGroupManager;
-
private final Context mContext;
+ private final NotificationManager mNotificationManager;
private final Handler mMainHandler;
+ private final List<NotifServiceListener> mNotificationListeners = new ArrayList<>();
private final ArrayList<NotificationSettingsListener> mSettingsListeners = new ArrayList<>();
- @Nullable private NotifServiceListener mDownstreamListener;
@Inject
- public NotificationListener(Context context, @MainHandler Handler mainHandler,
- NotificationEntryManager notificationEntryManager,
- NotificationGroupManager notificationGroupManager) {
+ public NotificationListener(
+ Context context,
+ NotificationManager notificationManager,
+ @MainHandler Handler mainHandler) {
mContext = context;
+ mNotificationManager = notificationManager;
mMainHandler = mainHandler;
- mEntryManager = notificationEntryManager;
- mGroupManager = notificationGroupManager;
}
- public void addNotificationSettingsListener(NotificationSettingsListener listener) {
- mSettingsListeners.add(listener);
+ /** Registers a listener that's notified when notifications are added/removed/etc. */
+ public void addNotificationListener(NotifServiceListener listener) {
+ if (mNotificationListeners.contains(listener)) {
+ throw new IllegalArgumentException("Listener is already added");
+ }
+ mNotificationListeners.add(listener);
}
- public void setDownstreamListener(NotifServiceListener downstreamListener) {
- mDownstreamListener = downstreamListener;
+ /** Registers a listener that's notified when any notification-related settings change. */
+ public void addNotificationSettingsListener(NotificationSettingsListener listener) {
+ mSettingsListeners.add(listener);
}
@Override
@@ -102,14 +100,13 @@ public class NotificationListener extends NotificationListenerWithPlugins {
final RankingMap completeMap = new RankingMap(newRankings.toArray(new Ranking[0]));
for (StatusBarNotification sbn : notifications) {
- if (mDownstreamListener != null) {
- mDownstreamListener.onNotificationPosted(sbn, completeMap);
+ for (NotifServiceListener listener : mNotificationListeners) {
+ listener.onNotificationPosted(sbn, completeMap);
}
- mEntryManager.addNotification(sbn, completeMap);
}
});
- NotificationManager noMan = mContext.getSystemService(NotificationManager.class);
- onSilentStatusBarIconsVisibilityChanged(noMan.shouldHideSilentStatusBarIcons());
+ onSilentStatusBarIconsVisibilityChanged(
+ mNotificationManager.shouldHideSilentStatusBarIcons());
}
@Override
@@ -120,34 +117,8 @@ public class NotificationListener extends NotificationListenerWithPlugins {
mMainHandler.post(() -> {
processForRemoteInput(sbn.getNotification(), mContext);
- if (mDownstreamListener != null) {
- mDownstreamListener.onNotificationPosted(sbn, rankingMap);
- }
-
- String key = sbn.getKey();
- boolean isUpdate = mEntryManager.getActiveNotificationUnfiltered(key) != null;
- // In case we don't allow child notifications, we ignore children of
- // notifications that have a summary, since` we're not going to show them
- // anyway. This is true also when the summary is canceled,
- // because children are automatically canceled by NoMan in that case.
- if (!ENABLE_CHILD_NOTIFICATIONS
- && mGroupManager.isChildInGroupWithSummary(sbn)) {
- if (DEBUG) {
- Log.d(TAG, "Ignoring group child due to existing summary: " + sbn);
- }
-
- // Remove existing notification to avoid stale data.
- if (isUpdate) {
- mEntryManager.removeNotification(key, rankingMap, UNDEFINED_DISMISS_REASON);
- } else {
- mEntryManager.updateRanking(rankingMap, "onNotificationPosted");
- }
- return;
- }
- if (isUpdate) {
- mEntryManager.updateNotification(sbn, rankingMap);
- } else {
- mEntryManager.addNotification(sbn, rankingMap);
+ for (NotifServiceListener listener : mNotificationListeners) {
+ listener.onNotificationPosted(sbn, rankingMap);
}
});
}
@@ -158,12 +129,10 @@ public class NotificationListener extends NotificationListenerWithPlugins {
int reason) {
if (DEBUG) Log.d(TAG, "onNotificationRemoved: " + sbn + " reason: " + reason);
if (sbn != null && !onPluginNotificationRemoved(sbn, rankingMap)) {
- final String key = sbn.getKey();
mMainHandler.post(() -> {
- if (mDownstreamListener != null) {
- mDownstreamListener.onNotificationRemoved(sbn, rankingMap, reason);
+ for (NotifServiceListener listener : mNotificationListeners) {
+ listener.onNotificationRemoved(sbn, rankingMap, reason);
}
- mEntryManager.removeNotification(key, rankingMap, reason);
});
}
}
@@ -179,10 +148,9 @@ public class NotificationListener extends NotificationListenerWithPlugins {
if (rankingMap != null) {
RankingMap r = onPluginRankingUpdate(rankingMap);
mMainHandler.post(() -> {
- if (mDownstreamListener != null) {
- mDownstreamListener.onNotificationRankingUpdate(rankingMap);
+ for (NotifServiceListener listener : mNotificationListeners) {
+ listener.onNotificationRankingUpdate(r);
}
- mEntryManager.updateNotificationRanking(r);
});
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationEntryManager.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationEntryManager.java
index dbefc7b4514e..43b9fbc909dc 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationEntryManager.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationEntryManager.java
@@ -33,6 +33,8 @@ import com.android.internal.statusbar.NotificationVisibility;
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.NotificationPresenter;
import com.android.systemui.statusbar.NotificationRemoteInputManager;
import com.android.systemui.statusbar.NotificationRemoveInterceptor;
@@ -174,6 +176,11 @@ public class NotificationEntryManager implements
mKeyguardEnvironment = keyguardEnvironment;
}
+ /** Once called, the NEM will start processing notification events from system server. */
+ public void attach(NotificationListener notificationListener) {
+ notificationListener.addNotificationListener(mNotifListener);
+ }
+
/** Adds a {@link NotificationEntryListener}. */
public void addNotificationEntryListener(NotificationEntryListener listener) {
mNotificationEntryListeners.add(listener);
@@ -318,6 +325,36 @@ public class NotificationEntryManager implements
}
}
+ private final NotifServiceListener mNotifListener = new NotifServiceListener() {
+ @Override
+ public void onNotificationPosted(StatusBarNotification sbn, RankingMap rankingMap) {
+ final boolean isUpdate = mActiveNotifications.containsKey(sbn.getKey());
+ if (isUpdate) {
+ updateNotification(sbn, rankingMap);
+ } else {
+ addNotification(sbn, rankingMap);
+ }
+ }
+
+ @Override
+ public void onNotificationRemoved(StatusBarNotification sbn, RankingMap rankingMap) {
+ removeNotification(sbn.getKey(), rankingMap, UNDEFINED_DISMISS_REASON);
+ }
+
+ @Override
+ public void onNotificationRemoved(
+ StatusBarNotification sbn,
+ RankingMap rankingMap,
+ int reason) {
+ removeNotification(sbn.getKey(), rankingMap, reason);
+ }
+
+ @Override
+ public void onNotificationRankingUpdate(RankingMap rankingMap) {
+ updateNotificationRanking(rankingMap);
+ }
+ };
+
/**
* Equivalent to the old NotificationData#add
* @param entry - an entry which is prepared for display
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationFilter.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationFilter.java
index 6c61923332ea..3afd6235b287 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationFilter.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationFilter.java
@@ -32,7 +32,6 @@ import com.android.systemui.statusbar.NotificationLockscreenUserManager;
import com.android.systemui.statusbar.notification.collection.NotificationEntry;
import com.android.systemui.statusbar.phone.NotificationGroupManager;
import com.android.systemui.statusbar.phone.ShadeController;
-import com.android.systemui.statusbar.phone.StatusBar;
import javax.inject.Inject;
import javax.inject.Singleton;
@@ -120,11 +119,6 @@ public class NotificationFilter {
return true;
}
- if (!StatusBar.ENABLE_CHILD_NOTIFICATIONS
- && mGroupManager.isChildInGroupWithSummary(sbn)) {
- return true;
- }
-
if (getFsc().isDisclosureNotification(sbn)
&& !getFsc().isDisclosureNeededForUser(sbn.getUserId())) {
// this is a foreground-service disclosure for a user that does not need to show one
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotifCollection.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotifCollection.java
index 6f085c0ce7c0..7f85c88865f6 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotifCollection.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotifCollection.java
@@ -116,7 +116,7 @@ public class NotifCollection {
}
mAttached = true;
- listenerService.setDownstreamListener(mNotifServiceListener);
+ listenerService.addNotificationListener(mNotifServiceListener);
}
/**
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRow.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRow.java
index 9ac5b44f8639..65423e970cf1 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRow.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRow.java
@@ -813,15 +813,14 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
* @param parent the new parent notification
*/
public void setIsChildInGroup(boolean isChildInGroup, ExpandableNotificationRow parent) {
- boolean childInGroup = StatusBar.ENABLE_CHILD_NOTIFICATIONS && isChildInGroup;
if (mExpandAnimationRunning && !isChildInGroup && mNotificationParent != null) {
mNotificationParent.setChildIsExpanding(false);
mNotificationParent.setExtraWidthForClipping(0.0f);
mNotificationParent.setMinimumHeightForClipping(0);
}
- mNotificationParent = childInGroup ? parent : null;
- mPrivateLayout.setIsChildInGroup(childInGroup);
- mNotificationInflater.setIsChildInGroup(childInGroup);
+ mNotificationParent = isChildInGroup ? parent : null;
+ mPrivateLayout.setIsChildInGroup(isChildInGroup);
+ mNotificationInflater.setIsChildInGroup(isChildInGroup);
resetBackgroundAlpha();
updateBackgroundForGroupState();
updateClickAndFocus();
@@ -2354,8 +2353,8 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
}
private void onChildrenCountChanged() {
- mIsSummaryWithChildren = StatusBar.ENABLE_CHILD_NOTIFICATIONS
- && mChildrenContainer != null && mChildrenContainer.getNotificationChildCount() > 0;
+ mIsSummaryWithChildren = mChildrenContainer != null
+ && mChildrenContainer.getNotificationChildCount() > 0;
if (mIsSummaryWithChildren && mChildrenContainer.getHeaderView() == null) {
mChildrenContainer.recreateNotificationHeader(mExpandClickListener
);
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java
index 7e3258101d33..4657de275e38 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java
@@ -246,9 +246,6 @@ public class StatusBar extends SystemUI implements DemoMode,
StatusBarStateController.StateListener, ActivityLaunchAnimator.Callback {
public static final boolean MULTIUSER_DEBUG = false;
- public static final boolean ENABLE_CHILD_NOTIFICATIONS
- = SystemProperties.getBoolean("debug.child_notifs", true);
-
protected static final int MSG_HIDE_RECENT_APPS = 1020;
protected static final int MSG_PRELOAD_RECENT_APPS = 1022;
protected static final int MSG_CANCEL_PRELOAD_RECENT_APPS = 1023;
@@ -1270,6 +1267,7 @@ public class StatusBar extends SystemUI implements DemoMode,
if (mFeatureFlags.isNewNotifPipelineEnabled()) {
mNewNotifPipeline.get().initialize(mNotificationListener);
}
+ mEntryManager.attach(mNotificationListener);
}
/**
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 8e6f4d7dd793..d580234725ac 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationListenerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationListenerTest.java
@@ -27,7 +27,8 @@ import android.app.Notification;
import android.app.NotificationManager;
import android.os.Handler;
import android.os.UserHandle;
-import android.service.notification.NotificationListenerService;
+import android.service.notification.NotificationListenerService.Ranking;
+import android.service.notification.NotificationListenerService.RankingMap;
import android.service.notification.StatusBarNotification;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;
@@ -35,8 +36,7 @@ import android.testing.TestableLooper;
import androidx.test.filters.SmallTest;
import com.android.systemui.SysuiTestCase;
-import com.android.systemui.statusbar.notification.NotificationEntryManager;
-import com.android.systemui.statusbar.phone.NotificationGroupManager;
+import com.android.systemui.statusbar.NotificationListener.NotifServiceListener;
import org.junit.Before;
import org.junit.Test;
@@ -51,52 +51,39 @@ public class NotificationListenerTest extends SysuiTestCase {
private static final String TEST_PACKAGE_NAME = "test";
private static final int TEST_UID = 0;
- @Mock private NotificationListenerService.RankingMap mRanking;
-
- // Dependency mocks:
- @Mock private NotificationEntryManager mEntryManager;
+ @Mock private NotifServiceListener mServiceListener;
@Mock private NotificationManager mNotificationManager;
- @Mock private NotificationGroupManager mNotificationGroupManager;
private NotificationListener mListener;
private StatusBarNotification mSbn;
+ private RankingMap mRanking = new RankingMap(new Ranking[0]);
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
- mContext.addMockSystemService(NotificationManager.class, mNotificationManager);
- mListener = new NotificationListener(mContext,
- new Handler(TestableLooper.get(this).getLooper()), mEntryManager,
- mNotificationGroupManager);
+ mListener = new NotificationListener(
+ mContext,
+ mNotificationManager,
+ new Handler(TestableLooper.get(this).getLooper()));
mSbn = new StatusBarNotification(TEST_PACKAGE_NAME, TEST_PACKAGE_NAME, 0, null, TEST_UID, 0,
new Notification(), UserHandle.CURRENT, null, 0);
- }
- @Test
- public void testNotificationAddCallsAddNotification() {
- mListener.onNotificationPosted(mSbn, mRanking);
- TestableLooper.get(this).processAllMessages();
- verify(mEntryManager).addNotification(mSbn, mRanking);
+ mListener.addNotificationListener(mServiceListener);
}
@Test
- public void testNotificationUpdateCallsUpdateNotification() {
- when(mEntryManager.getActiveNotificationUnfiltered(mSbn.getKey()))
- .thenReturn(
- new NotificationEntryBuilder()
- .setSbn(mSbn)
- .build());
+ public void testNotificationAddCallsAddNotification() {
mListener.onNotificationPosted(mSbn, mRanking);
TestableLooper.get(this).processAllMessages();
- verify(mEntryManager).updateNotification(mSbn, mRanking);
+ verify(mServiceListener).onNotificationPosted(mSbn, mRanking);
}
@Test
public void testNotificationRemovalCallsRemoveNotification() {
mListener.onNotificationRemoved(mSbn, mRanking);
TestableLooper.get(this).processAllMessages();
- verify(mEntryManager).removeNotification(eq(mSbn.getKey()), eq(mRanking), anyInt());
+ verify(mServiceListener).onNotificationRemoved(eq(mSbn), eq(mRanking), anyInt());
}
@Test
@@ -104,7 +91,7 @@ public class NotificationListenerTest extends SysuiTestCase {
mListener.onNotificationRankingUpdate(mRanking);
TestableLooper.get(this).processAllMessages();
// RankingMap may be modified by plugins.
- verify(mEntryManager).updateNotificationRanking(any());
+ verify(mServiceListener).onNotificationRankingUpdate(any());
}
@Test
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/NotifCollectionTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/NotifCollectionTest.java
index e1beb34db6bd..8d9537d9afc3 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/NotifCollectionTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/NotifCollectionTest.java
@@ -99,7 +99,7 @@ public class NotifCollectionTest extends SysuiTestCase {
// Capture the listener object that the collection registers with the listener service so
// we can simulate listener service events in tests below
- verify(mListenerService).setDownstreamListener(mListenerCaptor.capture());
+ verify(mListenerService).addNotificationListener(mListenerCaptor.capture());
mServiceListener = checkNotNull(mListenerCaptor.getValue());
mNoMan = new NoManSimulator(mServiceListener);