summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Julia Reynolds <juliacr@google.com> 2018-12-17 14:06:04 -0500
committer Julia Reynolds <juliacr@google.com> 2018-12-17 19:10:54 +0000
commitd12392c42714a89b64a3a58d2958844304f34a52 (patch)
tree7b7f17295e31512f01d1ea0a7b798628e90ea8ad
parent1519a9a9a421add349c2c03ed234c3ed7e75cb57 (diff)
Allow delegates to see the notifications they post
Via getActiveNotifications(). Test: cts Bug: 116512137 Change-Id: Ic5a95725ab4297b25d75d375f6fdb2bd34b55306
-rw-r--r--core/java/android/app/NotificationManager.java7
-rw-r--r--services/core/java/com/android/server/notification/NotificationManagerService.java26
2 files changed, 22 insertions, 11 deletions
diff --git a/core/java/android/app/NotificationManager.java b/core/java/android/app/NotificationManager.java
index 25fa897f2a56..8e2a3045ed54 100644
--- a/core/java/android/app/NotificationManager.java
+++ b/core/java/android/app/NotificationManager.java
@@ -1759,12 +1759,17 @@ public class NotificationManager {
* Recover a list of active notifications: ones that have been posted by the calling app that
* have not yet been dismissed by the user or {@link #cancel(String, int)}ed by the app.
*
- * Each notification is embedded in a {@link StatusBarNotification} object, including the
+ * <p><Each notification is embedded in a {@link StatusBarNotification} object, including the
* original <code>tag</code> and <code>id</code> supplied to
* {@link #notify(String, int, Notification) notify()}
* (via {@link StatusBarNotification#getTag() getTag()} and
* {@link StatusBarNotification#getId() getId()}) as well as a copy of the original
* {@link Notification} object (via {@link StatusBarNotification#getNotification()}).
+ * </p>
+ * <p>From {@link Build.VERSION_CODES#Q}, will also return notifications you've posted as an
+ * app's notification delegate via
+ * {@link NotificationManager#notifyAsPackage(String, String, int, Notification)}.
+ * </p>
*
* @return An array of {@link StatusBarNotification}.
*/
diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java
index 3d8763439086..bb99407ffe8b 100644
--- a/services/core/java/com/android/server/notification/NotificationManagerService.java
+++ b/services/core/java/com/android/server/notification/NotificationManagerService.java
@@ -2632,6 +2632,10 @@ public class NotificationManagerService extends SystemService {
* Note that since notification posting is done asynchronously, this will not return
* notifications that are in the process of being posted.
*
+ * From {@link Build.VERSION_CODES#Q}, will also return notifications you've posted as
+ * an app's notification delegate via
+ * {@link NotificationManager#notifyAsPackage(String, String, int, Notification)}.
+ *
* @returns A list of all the package's notifications, in natural order.
*/
@Override
@@ -2674,16 +2678,18 @@ public class NotificationManagerService extends SystemService {
private StatusBarNotification sanitizeSbn(String pkg, int userId,
StatusBarNotification sbn) {
- if (sbn.getPackageName().equals(pkg) && sbn.getUserId() == userId) {
- // 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
- // very well.
- return new StatusBarNotification(
- sbn.getPackageName(),
- sbn.getOpPkg(),
- sbn.getId(), sbn.getTag(), sbn.getUid(), sbn.getInitialPid(),
- sbn.getNotification().clone(),
- sbn.getUser(), sbn.getOverrideGroupKey(), sbn.getPostTime());
+ if (sbn.getUserId() == userId) {
+ if (sbn.getPackageName().equals(pkg) || sbn.getOpPkg().equals(pkg)) {
+ // 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
+ // very well.
+ return new StatusBarNotification(
+ sbn.getPackageName(),
+ sbn.getOpPkg(),
+ sbn.getId(), sbn.getTag(), sbn.getUid(), sbn.getInitialPid(),
+ sbn.getNotification().clone(),
+ sbn.getUser(), sbn.getOverrideGroupKey(), sbn.getPostTime());
+ }
}
return null;
}