summaryrefslogtreecommitdiffstats
path: root/services
diff options
context:
space:
mode:
authorDan Sandler <dsandler@android.com>2015-04-15 11:02:54 -0400
committerDaniel Sandler <dsandler@android.com>2015-04-21 17:14:17 +0000
commit994349c61e8697e626a7cd2b241a16b2b7669305 (patch)
tree52acb2617d6f89719513cf59cd84446508d8d671 /services
parent8d505ff025f16715d47f97d0f74a0cbba6c6391d (diff)
downloadframeworks_base-994349c61e8697e626a7cd2b241a16b2b7669305.zip
frameworks_base-994349c61e8697e626a7cd2b241a16b2b7669305.tar.gz
frameworks_base-994349c61e8697e626a7cd2b241a16b2b7669305.tar.bz2
Rediscover your own notifications.
This new API, NotificationManager.getActiveNotifications(), allows an app to recover the set of notifications it has posted that are still active (un-cleared, un-canceled, visible by the user). Along with the Notification object you'll get the original tag and id you used to post it, wrapped up in the somewhat awkwardly-named StatusBarNotification data structure (previously only used internally by NoMan/SysUI and NotificationListenerServices). Bug: 17320461 Change-Id: I8cd610956fafed4e31526b663cebdc31231ad930
Diffstat (limited to 'services')
-rw-r--r--services/core/java/com/android/server/notification/NotificationManagerService.java38
1 files changed, 38 insertions, 0 deletions
diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java
index b6f8e98..2df79b2 100644
--- a/services/core/java/com/android/server/notification/NotificationManagerService.java
+++ b/services/core/java/com/android/server/notification/NotificationManagerService.java
@@ -1282,6 +1282,44 @@ public class NotificationManagerService extends SystemService {
}
/**
+ * Public API for getting a list of current notifications for the calling package/uid.
+ *
+ * @returns A list of all the package's notifications, in natural order.
+ */
+ @Override
+ public ParceledListSlice<StatusBarNotification> getAppActiveNotifications(String pkg,
+ int incomingUserId) {
+ checkCallerIsSystemOrSameApp(pkg);
+ int userId = ActivityManager.handleIncomingUser(Binder.getCallingPid(),
+ Binder.getCallingUid(), incomingUserId, true, false,
+ "getAppActiveNotifications", pkg);
+
+ final int N = mNotificationList.size();
+ final ArrayList<StatusBarNotification> list = new ArrayList<StatusBarNotification>(N);
+
+ synchronized (mNotificationList) {
+ for (int i = 0; i < N; i++) {
+ final StatusBarNotification sbn = mNotificationList.get(i).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.
+ final StatusBarNotification sbnOut = new StatusBarNotification(
+ sbn.getPackageName(),
+ sbn.getOpPkg(),
+ sbn.getId(), sbn.getTag(), sbn.getUid(), sbn.getInitialPid(),
+ 0, // hide score from apps
+ sbn.getNotification().clone(),
+ sbn.getUser(), sbn.getPostTime());
+ list.add(sbnOut);
+ }
+ }
+ }
+
+ return new ParceledListSlice<StatusBarNotification>(list);
+ }
+
+ /**
* System-only API for getting a list of recent (cleared, no longer shown) notifications.
*
* Requires ACCESS_NOTIFICATIONS which is signature|system.