diff --git a/api/current.txt b/api/current.txt index b712ae6fa8130..b014ce3821ffd 100644 --- a/api/current.txt +++ b/api/current.txt @@ -27319,6 +27319,7 @@ package android.service.notification { method public final void cancelNotification(java.lang.String); method public final void cancelNotifications(java.lang.String[]); method public android.service.notification.StatusBarNotification[] getActiveNotifications(); + method public android.service.notification.StatusBarNotification[] getActiveNotifications(java.lang.String[]); method public final int getCurrentListenerHints(); method public android.service.notification.NotificationListenerService.RankingMap getCurrentRanking(); method public android.os.IBinder onBind(android.content.Intent); diff --git a/core/java/android/app/INotificationManager.aidl b/core/java/android/app/INotificationManager.aidl index 2b97c6bdebf44..07e9a94f307c8 100644 --- a/core/java/android/app/INotificationManager.aidl +++ b/core/java/android/app/INotificationManager.aidl @@ -58,7 +58,7 @@ interface INotificationManager void cancelNotificationFromListener(in INotificationListener token, String pkg, String tag, int id); void cancelNotificationsFromListener(in INotificationListener token, in String[] keys); - ParceledListSlice getActiveNotificationsFromListener(in INotificationListener token); + ParceledListSlice getActiveNotificationsFromListener(in INotificationListener token, in String[] keys); void requestHintsFromListener(in INotificationListener token, int hints); int getHintsFromListener(in INotificationListener token); @@ -71,4 +71,4 @@ interface INotificationManager oneway void setZenModeCondition(in Condition condition); oneway void setAutomaticZenModeConditions(in Uri[] conditionIds); Condition[] getAutomaticZenModeConditions(); -} \ No newline at end of file +} diff --git a/core/java/android/service/notification/NotificationListenerService.java b/core/java/android/service/notification/NotificationListenerService.java index 119f7f6c973f2..4651d7e898703 100644 --- a/core/java/android/service/notification/NotificationListenerService.java +++ b/core/java/android/service/notification/NotificationListenerService.java @@ -307,10 +307,22 @@ public abstract class NotificationListenerService extends Service { * @return An array of active notifications, sorted in natural order. */ public StatusBarNotification[] getActiveNotifications() { + return getActiveNotifications(null); + } + + /** + * Request one or more notifications by key. Useful if you have been keeping track of + * notifications but didn't want to retain the bits, and now need to go back and extract + * more data out of those notifications. + * + * @return An array of notifications corresponding to the requested keys, in the + * same order as the key list. + */ + public StatusBarNotification[] getActiveNotifications(String[] keys) { if (!isBound()) return null; try { ParceledListSlice parceledList = - getNotificationInterface().getActiveNotificationsFromListener(mWrapper); + getNotificationInterface().getActiveNotificationsFromListener(mWrapper, keys); List list = parceledList.getList(); int N = list.size(); diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index c390f9b7cd03e..6fd4eb7aa91ec 100644 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -1277,21 +1277,29 @@ public class NotificationManagerService extends SystemService { * should be used. * * @param token The binder for the listener, to check that the caller is allowed + * @param keys An array of notification keys to fetch, or null to fetch everything * @returns The return value will contain the notifications specified in keys, in that * order, or if keys is null, all the notifications, in natural order. */ @Override public ParceledListSlice getActiveNotificationsFromListener( - INotificationListener token) { + INotificationListener token, String[] keys) { synchronized (mNotificationList) { final ManagedServiceInfo info = mListeners.checkServiceTokenLocked(token); final ArrayList list = new ArrayList(); - final int N = mNotificationList.size(); + final boolean getKeys = keys != null; + final int N = getKeys ? keys.length : mNotificationList.size(); + list.ensureCapacity(N); for (int i=0; i(list);