Loading services/core/java/com/android/server/notification/NotificationManagerService.java +147 −113 Original line number Original line Diff line number Diff line Loading @@ -270,6 +270,7 @@ public class NotificationManagerService extends SystemService { new ArrayList<NotificationRecord>(); new ArrayList<NotificationRecord>(); final ArrayMap<String, NotificationRecord> mNotificationsByKey = final ArrayMap<String, NotificationRecord> mNotificationsByKey = new ArrayMap<String, NotificationRecord>(); new ArrayMap<String, NotificationRecord>(); final ArrayList<NotificationRecord> mEnqueuedNotifications = new ArrayList<>(); final ArrayMap<Integer, ArrayMap<String, String>> mAutobundledSummaries = new ArrayMap<>(); final ArrayMap<Integer, ArrayMap<String, String>> mAutobundledSummaries = new ArrayMap<>(); final ArrayList<ToastRecord> mToastQueue = new ArrayList<ToastRecord>(); final ArrayList<ToastRecord> mToastQueue = new ArrayList<ToastRecord>(); final ArrayMap<String, NotificationRecord> mSummaryByGroupKey = new ArrayMap<>(); final ArrayMap<String, NotificationRecord> mSummaryByGroupKey = new ArrayMap<>(); Loading Loading @@ -1614,33 +1615,58 @@ public class NotificationManagerService extends SystemService { int userId = ActivityManager.handleIncomingUser(Binder.getCallingPid(), int userId = ActivityManager.handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), incomingUserId, true, false, Binder.getCallingUid(), incomingUserId, true, false, "getAppActiveNotifications", pkg); "getAppActiveNotifications", pkg); final ArrayMap<String, StatusBarNotification> map final ArrayList<StatusBarNotification> list = new ArrayMap<>(mNotificationList.size() + mEnqueuedNotifications.size()); = new ArrayList<StatusBarNotification>(mNotificationList.size()); synchronized (mNotificationList) { synchronized (mNotificationList) { final int N = mNotificationList.size(); final int N = mNotificationList.size(); for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { final StatusBarNotification sbn = mNotificationList.get(i).sbn; StatusBarNotification sbn = sanitizeSbn(pkg, userId, mNotificationList.get(i).sbn); if (sbn != null) { map.put(sbn.getKey(), sbn); } } for(NotificationRecord snoozed: mSnoozeHelper.getSnoozed(userId, pkg)) { StatusBarNotification sbn = sanitizeSbn(pkg, userId, snoozed.sbn); if (sbn != null) { map.put(sbn.getKey(), sbn); } } } synchronized (mEnqueuedNotifications) { final int N = mEnqueuedNotifications.size(); for (int i = 0; i < N; i++) { StatusBarNotification sbn = sanitizeSbn(pkg, userId, mEnqueuedNotifications.get(i).sbn); if (sbn != null) { map.put(sbn.getKey(), sbn); // pending update overwrites existing post here } } } final ArrayList<StatusBarNotification> list = new ArrayList<>(map.size()); list.addAll(map.values()); return new ParceledListSlice<StatusBarNotification>(list); } private StatusBarNotification sanitizeSbn(String pkg, int userId, StatusBarNotification sbn) { if (sbn.getPackageName().equals(pkg) && sbn.getUserId() == userId if (sbn.getPackageName().equals(pkg) && sbn.getUserId() == userId && (sbn.getNotification().flags && (sbn.getNotification().flags & Notification.FLAG_AUTOGROUP_SUMMARY) == 0) { & Notification.FLAG_AUTOGROUP_SUMMARY) == 0) { // We could pass back a cloneLight() but clients might get confused and // We could pass back a cloneLight() but clients might get confused and // try to send this thing back to notify() again, which would not work // try to send this thing back to notify() again, which would not work // very well. // very well. final StatusBarNotification sbnOut = new StatusBarNotification( return new StatusBarNotification( sbn.getPackageName(), sbn.getPackageName(), sbn.getOpPkg(), sbn.getOpPkg(), sbn.getNotificationChannel(), sbn.getNotificationChannel(), sbn.getId(), sbn.getTag(), sbn.getUid(), sbn.getInitialPid(), sbn.getId(), sbn.getTag(), sbn.getUid(), sbn.getInitialPid(), sbn.getNotification().clone(), sbn.getNotification().clone(), sbn.getUser(), sbn.getOverrideGroupKey(), sbn.getPostTime()); sbn.getUser(), sbn.getOverrideGroupKey(), sbn.getPostTime()); list.add(sbnOut); } } } } return null; return new ParceledListSlice<StatusBarNotification>(list); } } /** /** Loading Loading @@ -2835,6 +2861,9 @@ public class NotificationManagerService extends SystemService { // setup local book-keeping // setup local book-keeping final NotificationRecord r = new NotificationRecord(getContext(), n); final NotificationRecord r = new NotificationRecord(getContext(), n); synchronized (mEnqueuedNotifications) { mEnqueuedNotifications.add(r); } mHandler.post(new EnqueueNotificationRunnable(userId, r)); mHandler.post(new EnqueueNotificationRunnable(userId, r)); idOut[0] = id; idOut[0] = id; Loading @@ -2851,7 +2880,7 @@ public class NotificationManagerService extends SystemService { @Override @Override public void run() { public void run() { try { synchronized (mNotificationList) { synchronized (mNotificationList) { if (mSnoozeHelper.isSnoozed(userId, r.sbn.getPackageName(), r.getKey())) { if (mSnoozeHelper.isSnoozed(userId, r.sbn.getPackageName(), r.getKey())) { // TODO: log to event log // TODO: log to event log Loading Loading @@ -2967,6 +2996,11 @@ public class NotificationManagerService extends SystemService { buzzBeepBlinkLocked(r); buzzBeepBlinkLocked(r); } } } finally { synchronized (mEnqueuedNotifications) { mEnqueuedNotifications.remove(r); } } } } protected boolean isBlocked(NotificationRecord r, NotificationUsageStats usageStats) { protected boolean isBlocked(NotificationRecord r, NotificationUsageStats usageStats) { Loading services/core/java/com/android/server/notification/SnoozeHelper.java +11 −0 Original line number Original line Diff line number Diff line Loading @@ -36,6 +36,9 @@ import android.util.Slog; import java.io.IOException; import java.io.IOException; import java.io.PrintWriter; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Date; import java.util.Date; import java.util.Map; import java.util.Map; import java.util.Objects; import java.util.Objects; Loading Loading @@ -84,6 +87,14 @@ public class SnoozeHelper { && mSnoozedNotifications.get(userId).get(pkg).containsKey(key); && mSnoozedNotifications.get(userId).get(pkg).containsKey(key); } } protected Collection<NotificationRecord> getSnoozed(int userId, String pkg) { if (mSnoozedNotifications.containsKey(userId) && mSnoozedNotifications.get(userId).containsKey(pkg)) { mSnoozedNotifications.get(userId).get(pkg).values(); } return Collections.EMPTY_LIST; } /** /** * Snoozes a notification and schedules an alarm to repost at that time. * Snoozes a notification and schedules an alarm to repost at that time. */ */ Loading Loading
services/core/java/com/android/server/notification/NotificationManagerService.java +147 −113 Original line number Original line Diff line number Diff line Loading @@ -270,6 +270,7 @@ public class NotificationManagerService extends SystemService { new ArrayList<NotificationRecord>(); new ArrayList<NotificationRecord>(); final ArrayMap<String, NotificationRecord> mNotificationsByKey = final ArrayMap<String, NotificationRecord> mNotificationsByKey = new ArrayMap<String, NotificationRecord>(); new ArrayMap<String, NotificationRecord>(); final ArrayList<NotificationRecord> mEnqueuedNotifications = new ArrayList<>(); final ArrayMap<Integer, ArrayMap<String, String>> mAutobundledSummaries = new ArrayMap<>(); final ArrayMap<Integer, ArrayMap<String, String>> mAutobundledSummaries = new ArrayMap<>(); final ArrayList<ToastRecord> mToastQueue = new ArrayList<ToastRecord>(); final ArrayList<ToastRecord> mToastQueue = new ArrayList<ToastRecord>(); final ArrayMap<String, NotificationRecord> mSummaryByGroupKey = new ArrayMap<>(); final ArrayMap<String, NotificationRecord> mSummaryByGroupKey = new ArrayMap<>(); Loading Loading @@ -1614,33 +1615,58 @@ public class NotificationManagerService extends SystemService { int userId = ActivityManager.handleIncomingUser(Binder.getCallingPid(), int userId = ActivityManager.handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), incomingUserId, true, false, Binder.getCallingUid(), incomingUserId, true, false, "getAppActiveNotifications", pkg); "getAppActiveNotifications", pkg); final ArrayMap<String, StatusBarNotification> map final ArrayList<StatusBarNotification> list = new ArrayMap<>(mNotificationList.size() + mEnqueuedNotifications.size()); = new ArrayList<StatusBarNotification>(mNotificationList.size()); synchronized (mNotificationList) { synchronized (mNotificationList) { final int N = mNotificationList.size(); final int N = mNotificationList.size(); for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { final StatusBarNotification sbn = mNotificationList.get(i).sbn; StatusBarNotification sbn = sanitizeSbn(pkg, userId, mNotificationList.get(i).sbn); if (sbn != null) { map.put(sbn.getKey(), sbn); } } for(NotificationRecord snoozed: mSnoozeHelper.getSnoozed(userId, pkg)) { StatusBarNotification sbn = sanitizeSbn(pkg, userId, snoozed.sbn); if (sbn != null) { map.put(sbn.getKey(), sbn); } } } synchronized (mEnqueuedNotifications) { final int N = mEnqueuedNotifications.size(); for (int i = 0; i < N; i++) { StatusBarNotification sbn = sanitizeSbn(pkg, userId, mEnqueuedNotifications.get(i).sbn); if (sbn != null) { map.put(sbn.getKey(), sbn); // pending update overwrites existing post here } } } final ArrayList<StatusBarNotification> list = new ArrayList<>(map.size()); list.addAll(map.values()); return new ParceledListSlice<StatusBarNotification>(list); } private StatusBarNotification sanitizeSbn(String pkg, int userId, StatusBarNotification sbn) { if (sbn.getPackageName().equals(pkg) && sbn.getUserId() == userId if (sbn.getPackageName().equals(pkg) && sbn.getUserId() == userId && (sbn.getNotification().flags && (sbn.getNotification().flags & Notification.FLAG_AUTOGROUP_SUMMARY) == 0) { & Notification.FLAG_AUTOGROUP_SUMMARY) == 0) { // We could pass back a cloneLight() but clients might get confused and // We could pass back a cloneLight() but clients might get confused and // try to send this thing back to notify() again, which would not work // try to send this thing back to notify() again, which would not work // very well. // very well. final StatusBarNotification sbnOut = new StatusBarNotification( return new StatusBarNotification( sbn.getPackageName(), sbn.getPackageName(), sbn.getOpPkg(), sbn.getOpPkg(), sbn.getNotificationChannel(), sbn.getNotificationChannel(), sbn.getId(), sbn.getTag(), sbn.getUid(), sbn.getInitialPid(), sbn.getId(), sbn.getTag(), sbn.getUid(), sbn.getInitialPid(), sbn.getNotification().clone(), sbn.getNotification().clone(), sbn.getUser(), sbn.getOverrideGroupKey(), sbn.getPostTime()); sbn.getUser(), sbn.getOverrideGroupKey(), sbn.getPostTime()); list.add(sbnOut); } } } } return null; return new ParceledListSlice<StatusBarNotification>(list); } } /** /** Loading Loading @@ -2835,6 +2861,9 @@ public class NotificationManagerService extends SystemService { // setup local book-keeping // setup local book-keeping final NotificationRecord r = new NotificationRecord(getContext(), n); final NotificationRecord r = new NotificationRecord(getContext(), n); synchronized (mEnqueuedNotifications) { mEnqueuedNotifications.add(r); } mHandler.post(new EnqueueNotificationRunnable(userId, r)); mHandler.post(new EnqueueNotificationRunnable(userId, r)); idOut[0] = id; idOut[0] = id; Loading @@ -2851,7 +2880,7 @@ public class NotificationManagerService extends SystemService { @Override @Override public void run() { public void run() { try { synchronized (mNotificationList) { synchronized (mNotificationList) { if (mSnoozeHelper.isSnoozed(userId, r.sbn.getPackageName(), r.getKey())) { if (mSnoozeHelper.isSnoozed(userId, r.sbn.getPackageName(), r.getKey())) { // TODO: log to event log // TODO: log to event log Loading Loading @@ -2967,6 +2996,11 @@ public class NotificationManagerService extends SystemService { buzzBeepBlinkLocked(r); buzzBeepBlinkLocked(r); } } } finally { synchronized (mEnqueuedNotifications) { mEnqueuedNotifications.remove(r); } } } } protected boolean isBlocked(NotificationRecord r, NotificationUsageStats usageStats) { protected boolean isBlocked(NotificationRecord r, NotificationUsageStats usageStats) { Loading
services/core/java/com/android/server/notification/SnoozeHelper.java +11 −0 Original line number Original line Diff line number Diff line Loading @@ -36,6 +36,9 @@ import android.util.Slog; import java.io.IOException; import java.io.IOException; import java.io.PrintWriter; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Date; import java.util.Date; import java.util.Map; import java.util.Map; import java.util.Objects; import java.util.Objects; Loading Loading @@ -84,6 +87,14 @@ public class SnoozeHelper { && mSnoozedNotifications.get(userId).get(pkg).containsKey(key); && mSnoozedNotifications.get(userId).get(pkg).containsKey(key); } } protected Collection<NotificationRecord> getSnoozed(int userId, String pkg) { if (mSnoozedNotifications.containsKey(userId) && mSnoozedNotifications.get(userId).containsKey(pkg)) { mSnoozedNotifications.get(userId).get(pkg).values(); } return Collections.EMPTY_LIST; } /** /** * Snoozes a notification and schedules an alarm to repost at that time. * Snoozes a notification and schedules an alarm to repost at that time. */ */ Loading