diff options
| author | 2014-08-12 12:29:19 -0400 | |
|---|---|---|
| committer | 2014-08-26 04:24:10 +0000 | |
| commit | ea75fddbb452638f286c2fcdbddff145ee1a85cb (patch) | |
| tree | fa659c8d52478a761df309904bbe06ccedf188d9 | |
| parent | f710befdab32abbf2d4569e2db3032af266126b4 (diff) | |
Allow listeners to fetch current notifications by key.
Bug: 16574195
Change-Id: I269dbcc7fc8912d84229f6a3d950b0015625ae7a
4 files changed, 29 insertions, 8 deletions
diff --git a/api/current.txt b/api/current.txt index b712ae6fa813..b014ce3821ff 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 2b97c6bdebf4..07e9a94f307c 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 119f7f6c973f..4651d7e89870 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<StatusBarNotification> parceledList = - getNotificationInterface().getActiveNotificationsFromListener(mWrapper); + getNotificationInterface().getActiveNotificationsFromListener(mWrapper, keys); List<StatusBarNotification> 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 c390f9b7cd03..6fd4eb7aa91e 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<StatusBarNotification> getActiveNotificationsFromListener( - INotificationListener token) { + INotificationListener token, String[] keys) { synchronized (mNotificationList) { final ManagedServiceInfo info = mListeners.checkServiceTokenLocked(token); final ArrayList<StatusBarNotification> list = new ArrayList<StatusBarNotification>(); - 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<N; i++) { - StatusBarNotification sbn = mNotificationList.get(i).sbn; - if (isVisibleToListener(sbn, info)) { - list.add(sbn); + final NotificationRecord r = getKeys + ? mNotificationsByKey.get(keys[i]) + : mNotificationList.get(i); + if (r != null) { + StatusBarNotification sbn = r.sbn; + if (isVisibleToListener(sbn, info)) { + list.add(sbn); + } } } return new ParceledListSlice<StatusBarNotification>(list); |