From 2f5bb169154d25bc8c164f057117fb056ad2de96 Mon Sep 17 00:00:00 2001 From: Tony Wickham Date: Fri, 24 Mar 2017 11:31:12 -0700 Subject: De-dupe shortcuts with the same id as the main notification. - Pass NotificationKeyData, which includes the shortcut id, instead of just the notification key from NotificationListener - Remove the shortcut with the same shortcut id as the first notification, if it has one, in PopupPopulator#sortAndFilterShorcuts() - Add some unit tests Bug: 36571718 Change-Id: I308941b34c525b34686583476e3f82ccb8b7e2d8 --- .../notification/NotificationListener.java | 25 ++++++++++++---------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'src/com/android/launcher3/notification/NotificationListener.java') diff --git a/src/com/android/launcher3/notification/NotificationListener.java b/src/com/android/launcher3/notification/NotificationListener.java index 16cb5fbb0..75a1b8ab5 100644 --- a/src/com/android/launcher3/notification/NotificationListener.java +++ b/src/com/android/launcher3/notification/NotificationListener.java @@ -94,8 +94,8 @@ public class NotificationListener extends NotificationListenerService { break; case MSG_NOTIFICATION_REMOVED: if (sNotificationsChangedListener != null) { - Pair pair - = (Pair) message.obj; + Pair pair + = (Pair) message.obj; sNotificationsChangedListener.onNotificationRemoved(pair.first, pair.second); } break; @@ -165,12 +165,12 @@ public class NotificationListener extends NotificationListenerService { */ private class NotificationPostedMsg { PackageUserKey packageUserKey; - String notificationKey; + NotificationKeyData notificationKey; boolean shouldBeFilteredOut; NotificationPostedMsg(StatusBarNotification sbn) { packageUserKey = PackageUserKey.fromNotification(sbn); - notificationKey = sbn.getKey(); + notificationKey = NotificationKeyData.fromNotification(sbn); shouldBeFilteredOut = shouldBeFilteredOut(sbn); } } @@ -178,16 +178,18 @@ public class NotificationListener extends NotificationListenerService { @Override public void onNotificationRemoved(final StatusBarNotification sbn) { super.onNotificationRemoved(sbn); - Pair packageUserKeyAndNotificationKey - = new Pair<>(PackageUserKey.fromNotification(sbn), sbn.getKey()); + Pair packageUserKeyAndNotificationKey + = new Pair<>(PackageUserKey.fromNotification(sbn), + NotificationKeyData.fromNotification(sbn)); mWorkerHandler.obtainMessage(MSG_NOTIFICATION_REMOVED, packageUserKeyAndNotificationKey) .sendToTarget(); } /** This makes a potentially expensive binder call and should be run on a background thread. */ - public List getNotificationsForKeys(String[] keys) { + public List getNotificationsForKeys(List keys) { StatusBarNotification[] notifications = NotificationListener.this - .getActiveNotifications(keys); + .getActiveNotifications(NotificationKeyData.extractKeysOnly(keys) + .toArray(new String[keys.size()])); return notifications == null ? Collections.EMPTY_LIST : Arrays.asList(notifications); } @@ -238,9 +240,10 @@ public class NotificationListener extends NotificationListenerService { } public interface NotificationsChangedListener { - void onNotificationPosted(PackageUserKey postedPackageUserKey, String notificationKey, - boolean shouldBeFilteredOut); - void onNotificationRemoved(PackageUserKey removedPackageUserKey, String notificationKey); + void onNotificationPosted(PackageUserKey postedPackageUserKey, + NotificationKeyData notificationKey, boolean shouldBeFilteredOut); + void onNotificationRemoved(PackageUserKey removedPackageUserKey, + NotificationKeyData notificationKey); void onNotificationFullRefresh(List activeNotifications); } } -- cgit v1.2.3