Allow listeners to fetch current notifications by key.

Bug: 16574195
Change-Id: I269dbcc7fc8912d84229f6a3d950b0015625ae7a
This commit is contained in:
Dan Sandler
2014-08-12 12:29:19 -04:00
parent f710befdab
commit ea75fddbb4
4 changed files with 29 additions and 8 deletions

View File

@@ -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();
}
}

View File

@@ -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();