From cef37cf5c749d140070d6d1bcf1cf41072843962 Mon Sep 17 00:00:00 2001 From: Christoph Studer Date: Fri, 25 Jul 2014 14:18:17 +0200 Subject: [PATCH] NoMan: Filter group children for pre-L listeners Bug: 16189575 Change-Id: I5297b5273ab0aaee599981738eb736a49f21ce53 --- .../NotificationManagerService.java | 66 +++++++++++++------ 1 file changed, 45 insertions(+), 21 deletions(-) diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index a277f91cd453c..10fa563fbccd1 100644 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -50,6 +50,7 @@ import android.media.AudioManager; import android.media.IRingtonePlayer; import android.net.Uri; import android.os.Binder; +import android.os.Build; import android.os.Environment; import android.os.Handler; import android.os.HandlerThread; @@ -1273,7 +1274,7 @@ public class NotificationManagerService extends SystemService { final int N = mNotificationList.size(); for (int i=0; i interceptedKeys = new ArrayList(N); for (int i = 0; i < N; i++) { NotificationRecord record = mNotificationList.get(i); - if (!info.enabledAndUserMatches(record.sbn.getUserId())) { + if (!isVisibleToListener(record.sbn, info)) { continue; } keys.add(record.sbn.getKey()); @@ -2504,6 +2503,18 @@ public class NotificationManagerService extends SystemService { return new NotificationRankingUpdate(keysAr, interceptedKeysAr, speedBumpIndex); } + private boolean isVisibleToListener(StatusBarNotification sbn, ManagedServiceInfo listener) { + if (!listener.enabledAndUserMatches(sbn.getUserId())) { + return false; + } + Notification n = sbn.getNotification(); + if (listener.targetSdkVersion < Build.VERSION_CODES.L && + n.getGroup() != null && (n.flags & Notification.FLAG_GROUP_SUMMARY) == 0) { + return false; + } + return true; + } + public class NotificationListeners extends ManagedServices { public NotificationListeners() { @@ -2550,22 +2561,39 @@ public class NotificationManagerService extends SystemService { /** * asynchronously notify all listeners about a new notification + * + *

+ * Also takes care of removing a notification that has been visible to a listener before, + * but isn't anymore. */ - public void notifyPostedLocked(StatusBarNotification sbn) { + public void notifyPostedLocked(StatusBarNotification sbn, StatusBarNotification oldSbn) { // make a copy in case changes are made to the underlying Notification object final StatusBarNotification sbnClone = sbn.clone(); for (final ManagedServiceInfo info : mServices) { - if (!info.isEnabledForCurrentProfiles()) { + boolean sbnVisible = isVisibleToListener(sbn, info); + boolean oldSbnVisible = oldSbn != null ? isVisibleToListener(oldSbn, info) : false; + // This notification hasn't been and still isn't visible -> ignore. + if (!oldSbnVisible && !sbnVisible) { continue; } final NotificationRankingUpdate update = makeRankingUpdateLocked(info); - if (update.getOrderedKeys().length == 0) { + + // This notification became invisible -> remove the old one. + if (oldSbnVisible && !sbnVisible) { + final StatusBarNotification oldSbnLightClone = oldSbn.cloneLight(); + mHandler.post(new Runnable() { + @Override + public void run() { + notifyRemoved(info, oldSbnLightClone, update); + } + }); continue; } + mHandler.post(new Runnable() { @Override public void run() { - notifyPostedIfUserMatch(info, sbnClone, update); + notifyPosted(info, sbnClone, update); } }); } @@ -2580,14 +2608,14 @@ public class NotificationManagerService extends SystemService { // notification final StatusBarNotification sbnLight = sbn.cloneLight(); for (final ManagedServiceInfo info : mServices) { - if (!info.isEnabledForCurrentProfiles()) { + if (!isVisibleToListener(sbn, info)) { continue; } final NotificationRankingUpdate update = makeRankingUpdateLocked(info); mHandler.post(new Runnable() { @Override public void run() { - notifyRemovedIfUserMatch(info, sbnLight, update); + notifyRemoved(info, sbnLight, update); } }); } @@ -2601,8 +2629,7 @@ public class NotificationManagerService extends SystemService { if (!serviceInfo.isEnabledForCurrentProfiles()) { continue; } - final NotificationRankingUpdate update = - makeRankingUpdateLocked(serviceInfo); + final NotificationRankingUpdate update = makeRankingUpdateLocked(serviceInfo); mHandler.post(new Runnable() { @Override public void run() { @@ -2626,11 +2653,8 @@ public class NotificationManagerService extends SystemService { } } - private void notifyPostedIfUserMatch(final ManagedServiceInfo info, + private void notifyPosted(final ManagedServiceInfo info, final StatusBarNotification sbn, NotificationRankingUpdate rankingUpdate) { - if (!info.enabledAndUserMatches(sbn.getUserId())) { - return; - } final INotificationListener listener = (INotificationListener)info.service; try { listener.onNotificationPosted(sbn, rankingUpdate); @@ -2639,7 +2663,7 @@ public class NotificationManagerService extends SystemService { } } - private void notifyRemovedIfUserMatch(ManagedServiceInfo info, StatusBarNotification sbn, + private void notifyRemoved(ManagedServiceInfo info, StatusBarNotification sbn, NotificationRankingUpdate rankingUpdate) { if (!info.enabledAndUserMatches(sbn.getUserId())) { return;