diff options
author | Tony Wickham <twickham@google.com> | 2017-02-10 08:03:22 -0800 |
---|---|---|
committer | Tony <twickham@google.com> | 2017-02-13 07:02:26 -0800 |
commit | 988f34b7f2bb7e57d99ec19fbe9b7024da1fe52f (patch) | |
tree | d0fa2bb4e661e30c9f68bf535f317176f1768604 | |
parent | ee544c5d243698e64990e07917df1de804ffbe44 (diff) | |
download | android_packages_apps_Trebuchet-988f34b7f2bb7e57d99ec19fbe9b7024da1fe52f.tar.gz android_packages_apps_Trebuchet-988f34b7f2bb7e57d99ec19fbe9b7024da1fe52f.tar.bz2 android_packages_apps_Trebuchet-988f34b7f2bb7e57d99ec19fbe9b7024da1fe52f.zip |
Ensure that filtered notifications are removed from BadgeInfo.
There are cases where a BadgeInfo can contain a key that is later
used for a notification that should be filtered out. So instead
of simply not sending filtered notifications to PopupDataProvider,
now we explicitly send them and remove the corresponding key from
the BadgeInfo if it exists.
Bug: 35239510
Change-Id: I9532f47b1f07b44234f8707657b15b0de519b347
-rw-r--r-- | src/com/android/launcher3/notification/NotificationListener.java | 40 | ||||
-rw-r--r-- | src/com/android/launcher3/popup/PopupDataProvider.java | 23 |
2 files changed, 40 insertions, 23 deletions
diff --git a/src/com/android/launcher3/notification/NotificationListener.java b/src/com/android/launcher3/notification/NotificationListener.java index 206bb31d4..5c16176f5 100644 --- a/src/com/android/launcher3/notification/NotificationListener.java +++ b/src/com/android/launcher3/notification/NotificationListener.java @@ -80,9 +80,9 @@ public class NotificationListener extends NotificationListenerService { switch (message.what) { case MSG_NOTIFICATION_POSTED: if (sNotificationsChangedListener != null) { - Pair<PackageUserKey, String> pair - = (Pair<PackageUserKey, String>) message.obj; - sNotificationsChangedListener.onNotificationPosted(pair.first, pair.second); + NotificationPostedMsg msg = (NotificationPostedMsg) message.obj; + sNotificationsChangedListener.onNotificationPosted(msg.packageUserKey, + msg.notificationKey, msg.shouldBeFilteredOut); } break; case MSG_NOTIFICATION_REMOVED: @@ -149,23 +149,32 @@ public class NotificationListener extends NotificationListenerService { @Override public void onNotificationPosted(final StatusBarNotification sbn) { super.onNotificationPosted(sbn); - if (!shouldBeFilteredOut(sbn.getNotification())) { - Pair<PackageUserKey, String> packageUserKeyAndNotificationKey - = new Pair<>(PackageUserKey.fromNotification(sbn), sbn.getKey()); - mWorkerHandler.obtainMessage(MSG_NOTIFICATION_POSTED, packageUserKeyAndNotificationKey) - .sendToTarget(); + mWorkerHandler.obtainMessage(MSG_NOTIFICATION_POSTED, new NotificationPostedMsg(sbn)) + .sendToTarget(); + } + + /** + * An object containing data to send to MSG_NOTIFICATION_POSTED targets. + */ + private class NotificationPostedMsg { + PackageUserKey packageUserKey; + String notificationKey; + boolean shouldBeFilteredOut; + + NotificationPostedMsg(StatusBarNotification sbn) { + packageUserKey = PackageUserKey.fromNotification(sbn); + notificationKey = sbn.getKey(); + shouldBeFilteredOut = shouldBeFilteredOut(sbn.getNotification()); } } @Override public void onNotificationRemoved(final StatusBarNotification sbn) { super.onNotificationRemoved(sbn); - if (!shouldBeFilteredOut(sbn.getNotification())) { - Pair<PackageUserKey, String> packageUserKeyAndNotificationKey - = new Pair<>(PackageUserKey.fromNotification(sbn), sbn.getKey()); - mWorkerHandler.obtainMessage(MSG_NOTIFICATION_REMOVED, packageUserKeyAndNotificationKey) - .sendToTarget(); - } + Pair<PackageUserKey, String> packageUserKeyAndNotificationKey + = new Pair<>(PackageUserKey.fromNotification(sbn), sbn.getKey()); + mWorkerHandler.obtainMessage(MSG_NOTIFICATION_REMOVED, packageUserKeyAndNotificationKey) + .sendToTarget(); } /** This makes a potentially expensive binder call and should be run on a background thread. */ @@ -206,7 +215,8 @@ public class NotificationListener extends NotificationListenerService { } public interface NotificationsChangedListener { - void onNotificationPosted(PackageUserKey postedPackageUserKey, String notificationKey); + void onNotificationPosted(PackageUserKey postedPackageUserKey, String notificationKey, + boolean shouldBeFilteredOut); void onNotificationRemoved(PackageUserKey removedPackageUserKey, String notificationKey); void onNotificationFullRefresh(List<StatusBarNotification> activeNotifications); } diff --git a/src/com/android/launcher3/popup/PopupDataProvider.java b/src/com/android/launcher3/popup/PopupDataProvider.java index c754fda99..e314b646b 100644 --- a/src/com/android/launcher3/popup/PopupDataProvider.java +++ b/src/com/android/launcher3/popup/PopupDataProvider.java @@ -58,19 +58,26 @@ public class PopupDataProvider implements NotificationListener.NotificationsChan } @Override - public void onNotificationPosted(PackageUserKey postedPackageUserKey, String notificationKey) { + public void onNotificationPosted(PackageUserKey postedPackageUserKey, String notificationKey, + boolean shouldBeFilteredOut) { BadgeInfo badgeInfo = mPackageUserToBadgeInfos.get(postedPackageUserKey); - boolean notificationWasAdded; // As opposed to updated. + boolean notificationWasAddedOrRemoved; // As opposed to updated. if (badgeInfo == null) { - BadgeInfo newBadgeInfo = new BadgeInfo(postedPackageUserKey); - newBadgeInfo.addNotificationKeyIfNotExists(notificationKey); - mPackageUserToBadgeInfos.put(postedPackageUserKey, newBadgeInfo); - notificationWasAdded = true; + if (!shouldBeFilteredOut) { + BadgeInfo newBadgeInfo = new BadgeInfo(postedPackageUserKey); + newBadgeInfo.addNotificationKeyIfNotExists(notificationKey); + mPackageUserToBadgeInfos.put(postedPackageUserKey, newBadgeInfo); + notificationWasAddedOrRemoved = true; + } else { + notificationWasAddedOrRemoved = false; + } } else { - notificationWasAdded = badgeInfo.addNotificationKeyIfNotExists(notificationKey); + notificationWasAddedOrRemoved = shouldBeFilteredOut + ? badgeInfo.removeNotificationKey(notificationKey) + : badgeInfo.addNotificationKeyIfNotExists(notificationKey); } updateLauncherIconBadges(Utilities.singletonHashSet(postedPackageUserKey), - notificationWasAdded); + notificationWasAddedOrRemoved); } @Override |