summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--api/current.txt12
-rw-r--r--core/java/android/service/notification/INotificationListener.aidl10
-rw-r--r--core/java/android/service/notification/NotificationListenerService.java217
-rw-r--r--core/java/android/service/notification/NotificationOrderUpdate.java62
-rw-r--r--core/java/android/service/notification/NotificationRankingUpdate.aidl (renamed from core/java/android/service/notification/NotificationOrderUpdate.aidl)2
-rw-r--r--core/java/android/service/notification/NotificationRankingUpdate.java77
-rw-r--r--services/core/java/com/android/server/notification/NotificationManagerService.java144
7 files changed, 348 insertions, 176 deletions
diff --git a/api/current.txt b/api/current.txt
index e3c8431..5f8b90c 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -25589,20 +25589,24 @@ package android.service.notification {
method public final deprecated void cancelNotification(java.lang.String, java.lang.String, int);
method public final void cancelNotification(java.lang.String);
method public final void cancelNotifications(java.lang.String[]);
+ method public java.lang.String[] getActiveNotificationKeys();
method public android.service.notification.StatusBarNotification[] getActiveNotifications();
method public android.service.notification.StatusBarNotification[] getActiveNotifications(java.lang.String[]);
- method public java.lang.String[] getOrderedNotificationKeys();
+ method public android.service.notification.NotificationListenerService.Ranking getCurrentRanking();
method public android.os.IBinder onBind(android.content.Intent);
method public void onListenerConnected(java.lang.String[]);
- method public void onNotificationOrderUpdate();
method public abstract void onNotificationPosted(android.service.notification.StatusBarNotification);
+ method public void onNotificationRankingUpdate();
method public abstract void onNotificationRemoved(android.service.notification.StatusBarNotification);
field public static final java.lang.String SERVICE_INTERFACE = "android.service.notification.NotificationListenerService";
}
- public class NotificationOrderUpdate implements android.os.Parcelable {
- ctor public NotificationOrderUpdate(android.os.Parcel);
+ public static class NotificationListenerService.Ranking implements android.os.Parcelable {
method public int describeContents();
+ method public int getIndexOfKey(java.lang.String);
+ method public java.lang.String[] getOrderedKeys();
+ method public boolean isAmbient(java.lang.String);
+ method public boolean isInterceptedByDoNotDisturb(java.lang.String);
method public void writeToParcel(android.os.Parcel, int);
field public static final android.os.Parcelable.Creator CREATOR;
}
diff --git a/core/java/android/service/notification/INotificationListener.aidl b/core/java/android/service/notification/INotificationListener.aidl
index d4919eb..b3705d8 100644
--- a/core/java/android/service/notification/INotificationListener.aidl
+++ b/core/java/android/service/notification/INotificationListener.aidl
@@ -17,15 +17,15 @@
package android.service.notification;
import android.service.notification.StatusBarNotification;
-import android.service.notification.NotificationOrderUpdate;
+import android.service.notification.NotificationRankingUpdate;
/** @hide */
oneway interface INotificationListener
{
- void onListenerConnected(in NotificationOrderUpdate update);
+ void onListenerConnected(in NotificationRankingUpdate update);
void onNotificationPosted(in StatusBarNotification notification,
- in NotificationOrderUpdate update);
+ in NotificationRankingUpdate update);
void onNotificationRemoved(in StatusBarNotification notification,
- in NotificationOrderUpdate update);
- void onNotificationOrderUpdate(in NotificationOrderUpdate update);
+ in NotificationRankingUpdate update);
+ void onNotificationRankingUpdate(in NotificationRankingUpdate update);
} \ 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 e2e9ff4..7f84877 100644
--- a/core/java/android/service/notification/NotificationListenerService.java
+++ b/core/java/android/service/notification/NotificationListenerService.java
@@ -24,12 +24,15 @@ import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.os.IBinder;
+import android.os.Parcel;
+import android.os.Parcelable;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.util.Log;
/**
- * A service that receives calls from the system when new notifications are posted or removed.
+ * A service that receives calls from the system when new notifications are
+ * posted or removed, or their ranking changed.
* <p>To extend this class, you must declare the service in your manifest file with
* the {@link android.Manifest.permission#BIND_NOTIFICATION_LISTENER_SERVICE} permission
* and include an intent filter with the {@link #SERVICE_INTERFACE} action. For example:</p>
@@ -48,7 +51,7 @@ public abstract class NotificationListenerService extends Service {
+ "[" + getClass().getSimpleName() + "]";
private INotificationListenerWrapper mWrapper = null;
- private String[] mNotificationKeys;
+ private Ranking mRanking;
private INotificationManager mNoMan;
@@ -102,11 +105,11 @@ public abstract class NotificationListenerService extends Service {
}
/**
- * Implement this method to be notified when the notification order cahnges.
- *
- * Call {@link #getOrderedNotificationKeys()} to retrieve the new order.
+ * Implement this method to be notified when the notification ranking changes.
+ * <P>
+ * Call {@link #getCurrentRanking()} to retrieve the new ranking.
*/
- public void onNotificationOrderUpdate() {
+ public void onNotificationRankingUpdate() {
// optional
}
@@ -224,6 +227,19 @@ public abstract class NotificationListenerService extends Service {
}
/**
+ * Request the list of notification keys in their current ranking order.
+ * <p>
+ * You can use the notification keys for subsequent retrieval via
+ * {@link #getActiveNotifications(String[]) or dismissal via
+ * {@link #cancelNotifications(String[]).
+ *
+ * @return An array of active notification keys, in their ranking order.
+ */
+ public String[] getActiveNotificationKeys() {
+ return mRanking.getOrderedKeys();
+ }
+
+ /**
* Request the list of outstanding notifications (that is, those that are visible to the
* current user). Useful when you don't know what's already been posted.
*
@@ -242,15 +258,20 @@ public abstract class NotificationListenerService extends Service {
}
/**
- * Request the list of notification keys in their current natural order.
- * You can use the notification keys for subsequent retrieval via
- * {@link #getActiveNotifications(String[]) or dismissal via
- * {@link #cancelNotifications(String[]).
+ * Returns current ranking information.
+ *
+ * <p>
+ * The returned object represents the current ranking snapshot and only
+ * applies for currently active notifications. Hence you must retrieve a
+ * new Ranking after each notification event such as
+ * {@link #onNotificationPosted(StatusBarNotification)},
+ * {@link #onNotificationRemoved(StatusBarNotification)}, etc.
*
- * @return An array of active notification keys, in their natural order.
+ * @return A {@link NotificationListenerService.Ranking} object providing
+ * access to ranking information
*/
- public String[] getOrderedNotificationKeys() {
- return mNotificationKeys;
+ public Ranking getCurrentRanking() {
+ return mRanking;
}
@Override
@@ -308,59 +329,163 @@ public abstract class NotificationListenerService extends Service {
private class INotificationListenerWrapper extends INotificationListener.Stub {
@Override
public void onNotificationPosted(StatusBarNotification sbn,
- NotificationOrderUpdate update) {
- try {
- // protect subclass from concurrent modifications of (@link mNotificationKeys}.
- synchronized (mWrapper) {
- updateNotificationKeys(update);
+ NotificationRankingUpdate update) {
+ // protect subclass from concurrent modifications of (@link mNotificationKeys}.
+ synchronized (mWrapper) {
+ applyUpdate(update);
+ try {
NotificationListenerService.this.onNotificationPosted(sbn);
+ } catch (Throwable t) {
+ Log.w(TAG, "Error running onNotificationPosted", t);
}
- } catch (Throwable t) {
- Log.w(TAG, "Error running onOrderedNotificationPosted", t);
}
}
@Override
public void onNotificationRemoved(StatusBarNotification sbn,
- NotificationOrderUpdate update) {
- try {
- // protect subclass from concurrent modifications of (@link mNotificationKeys}.
- synchronized (mWrapper) {
- updateNotificationKeys(update);
+ NotificationRankingUpdate update) {
+ // protect subclass from concurrent modifications of (@link mNotificationKeys}.
+ synchronized (mWrapper) {
+ applyUpdate(update);
+ try {
NotificationListenerService.this.onNotificationRemoved(sbn);
+ } catch (Throwable t) {
+ Log.w(TAG, "Error running onNotificationRemoved", t);
}
- } catch (Throwable t) {
- Log.w(TAG, "Error running onNotificationRemoved", t);
}
}
@Override
- public void onListenerConnected(NotificationOrderUpdate update) {
- try {
- // protect subclass from concurrent modifications of (@link mNotificationKeys}.
- synchronized (mWrapper) {
- updateNotificationKeys(update);
- NotificationListenerService.this.onListenerConnected(mNotificationKeys);
+ public void onListenerConnected(NotificationRankingUpdate update) {
+ // protect subclass from concurrent modifications of (@link mNotificationKeys}.
+ synchronized (mWrapper) {
+ applyUpdate(update);
+ try {
+ NotificationListenerService.this.onListenerConnected(
+ mRanking.getOrderedKeys());
+ } catch (Throwable t) {
+ Log.w(TAG, "Error running onListenerConnected", t);
}
- } catch (Throwable t) {
- Log.w(TAG, "Error running onListenerConnected", t);
}
}
@Override
- public void onNotificationOrderUpdate(NotificationOrderUpdate update)
+ public void onNotificationRankingUpdate(NotificationRankingUpdate update)
throws RemoteException {
- try {
- // protect subclass from concurrent modifications of (@link mNotificationKeys}.
- synchronized (mWrapper) {
- updateNotificationKeys(update);
- NotificationListenerService.this.onNotificationOrderUpdate();
+ // protect subclass from concurrent modifications of (@link mNotificationKeys}.
+ synchronized (mWrapper) {
+ applyUpdate(update);
+ try {
+ NotificationListenerService.this.onNotificationRankingUpdate();
+ } catch (Throwable t) {
+ Log.w(TAG, "Error running onNotificationRankingUpdate", t);
}
- } catch (Throwable t) {
- Log.w(TAG, "Error running onNotificationOrderUpdate", t);
}
}
}
- private void updateNotificationKeys(NotificationOrderUpdate update) {
- // TODO: avoid garbage by comparing the lists
- mNotificationKeys = update.getOrderedKeys();
+ private void applyUpdate(NotificationRankingUpdate update) {
+ mRanking = new Ranking(update);
+ }
+
+ /**
+ * Provides access to ranking information on currently active
+ * notifications.
+ *
+ * <p>
+ * Note that this object represents a ranking snapshot that only applies to
+ * notifications active at the time of retrieval.
+ */
+ public static class Ranking implements Parcelable {
+ private final NotificationRankingUpdate mRankingUpdate;
+
+ private Ranking(NotificationRankingUpdate rankingUpdate) {
+ mRankingUpdate = rankingUpdate;
+ }
+
+ /**
+ * Request the list of notification keys in their current ranking
+ * order.
+ *
+ * @return An array of active notification keys, in their ranking order.
+ */
+ public String[] getOrderedKeys() {
+ return mRankingUpdate.getOrderedKeys();
+ }
+
+ /**
+ * Returns the rank of the notification with the given key, that is the
+ * index of <code>key</code> in the array of keys returned by
+ * {@link #getOrderedKeys()}.
+ *
+ * @return The rank of the notification with the given key; -1 when the
+ * given key is unknown.
+ */
+ public int getIndexOfKey(String key) {
+ // TODO: Optimize.
+ String[] orderedKeys = mRankingUpdate.getOrderedKeys();
+ for (int i = 0; i < orderedKeys.length; i++) {
+ if (orderedKeys[i].equals(key)) {
+ return i;
+ }
+ }
+ return -1;
+ }
+
+ /**
+ * Returns whether the notification with the given key was intercepted
+ * by &quot;Do not disturb&quot;.
+ */
+ public boolean isInterceptedByDoNotDisturb(String key) {
+ // TODO: Optimize.
+ for (String interceptedKey : mRankingUpdate.getDndInterceptedKeys()) {
+ if (interceptedKey.equals(key)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Returns whether the notification with the given key is an ambient
+ * notification, that is a notification that doesn't require the user's
+ * immediate attention.
+ */
+ public boolean isAmbient(String key) {
+ // TODO: Optimize.
+ int firstAmbientIndex = mRankingUpdate.getFirstAmbientIndex();
+ if (firstAmbientIndex < 0) {
+ return false;
+ }
+ String[] orderedKeys = mRankingUpdate.getOrderedKeys();
+ for (int i = firstAmbientIndex; i < orderedKeys.length; i++) {
+ if (orderedKeys[i].equals(key)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ // ----------- Parcelable
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ @Override
+ public void writeToParcel(Parcel dest, int flags) {
+ dest.writeParcelable(mRankingUpdate, flags);
+ }
+
+ public static final Creator<Ranking> CREATOR = new Creator<Ranking>() {
+ @Override
+ public Ranking createFromParcel(Parcel source) {
+ NotificationRankingUpdate rankingUpdate = source.readParcelable(null);
+ return new Ranking(rankingUpdate);
+ }
+
+ @Override
+ public Ranking[] newArray(int size) {
+ return new Ranking[size];
+ }
+ };
}
}
diff --git a/core/java/android/service/notification/NotificationOrderUpdate.java b/core/java/android/service/notification/NotificationOrderUpdate.java
deleted file mode 100644
index 20e19a3..0000000
--- a/core/java/android/service/notification/NotificationOrderUpdate.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Copyright (C) 2014 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package android.service.notification;
-
-import android.os.Parcel;
-import android.os.Parcelable;
-
-public class NotificationOrderUpdate implements Parcelable {
- // TODO replace this with an update instead of the whole array
- private final String[] mKeys;
-
- /** @hide */
- public NotificationOrderUpdate(String[] keys) {
- this.mKeys = keys;
- }
-
- public NotificationOrderUpdate(Parcel in) {
- this.mKeys = in.readStringArray();
- }
-
- @Override
- public int describeContents() {
- return 0;
- }
-
- @Override
- public void writeToParcel(Parcel out, int flags) {
- out.writeStringArray(this.mKeys);
- }
-
- public static final Parcelable.Creator<NotificationOrderUpdate> CREATOR
- = new Parcelable.Creator<NotificationOrderUpdate>() {
- public NotificationOrderUpdate createFromParcel(Parcel parcel) {
- return new NotificationOrderUpdate(parcel);
- }
-
- public NotificationOrderUpdate[] newArray(int size) {
- return new NotificationOrderUpdate[size];
- }
- };
-
- /**
- * @hide
- * @return ordered list of keys
- */
- String[] getOrderedKeys() {
- return mKeys;
- }
-}
diff --git a/core/java/android/service/notification/NotificationOrderUpdate.aidl b/core/java/android/service/notification/NotificationRankingUpdate.aidl
index 5d50641..1393cb9 100644
--- a/core/java/android/service/notification/NotificationOrderUpdate.aidl
+++ b/core/java/android/service/notification/NotificationRankingUpdate.aidl
@@ -16,4 +16,4 @@
package android.service.notification;
-parcelable NotificationOrderUpdate;
+parcelable NotificationRankingUpdate;
diff --git a/core/java/android/service/notification/NotificationRankingUpdate.java b/core/java/android/service/notification/NotificationRankingUpdate.java
new file mode 100644
index 0000000..4b13d95
--- /dev/null
+++ b/core/java/android/service/notification/NotificationRankingUpdate.java
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package android.service.notification;
+
+import android.os.Parcel;
+import android.os.Parcelable;
+
+/**
+ * @hide
+ */
+public class NotificationRankingUpdate implements Parcelable {
+ // TODO: Support incremental updates.
+ private final String[] mKeys;
+ private final String[] mDndInterceptedKeys;
+ private final int mFirstAmbientIndex;
+
+ public NotificationRankingUpdate(String[] keys, String[] dndInterceptedKeys,
+ int firstAmbientIndex) {
+ mKeys = keys;
+ mFirstAmbientIndex = firstAmbientIndex;
+ mDndInterceptedKeys = dndInterceptedKeys;
+ }
+
+ public NotificationRankingUpdate(Parcel in) {
+ mKeys = in.readStringArray();
+ mFirstAmbientIndex = in.readInt();
+ mDndInterceptedKeys = in.readStringArray();
+ }
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ @Override
+ public void writeToParcel(Parcel out, int flags) {
+ out.writeStringArray(mKeys);
+ out.writeInt(mFirstAmbientIndex);
+ out.writeStringArray(mDndInterceptedKeys);
+ }
+
+ public static final Parcelable.Creator<NotificationRankingUpdate> CREATOR
+ = new Parcelable.Creator<NotificationRankingUpdate>() {
+ public NotificationRankingUpdate createFromParcel(Parcel parcel) {
+ return new NotificationRankingUpdate(parcel);
+ }
+
+ public NotificationRankingUpdate[] newArray(int size) {
+ return new NotificationRankingUpdate[size];
+ }
+ };
+
+ public String[] getOrderedKeys() {
+ return mKeys;
+ }
+
+ public int getFirstAmbientIndex() {
+ return mFirstAmbientIndex;
+ }
+
+ public String[] getDndInterceptedKeys() {
+ return mDndInterceptedKeys;
+ }
+}
diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java
index 1734a33..9569c0d 100644
--- a/services/core/java/com/android/server/notification/NotificationManagerService.java
+++ b/services/core/java/com/android/server/notification/NotificationManagerService.java
@@ -63,7 +63,7 @@ import android.service.notification.INotificationListener;
import android.service.notification.IConditionListener;
import android.service.notification.IConditionProvider;
import android.service.notification.NotificationListenerService;
-import android.service.notification.NotificationOrderUpdate;
+import android.service.notification.NotificationRankingUpdate;
import android.service.notification.StatusBarNotification;
import android.service.notification.Condition;
import android.service.notification.ZenModeConfig;
@@ -1744,7 +1744,7 @@ public class NotificationManagerService extends SystemService {
sendAccessibilityEvent(notification, pkg);
}
- mListeners.notifyPostedLocked(r.sbn);
+ mListeners.notifyPostedLocked(r.sbn, cloneNotificationListLocked());
} else {
Slog.e(TAG, "Not posting notification with icon==0: " + notification);
if (old != null && old.statusBarKey != null) {
@@ -1755,7 +1755,7 @@ public class NotificationManagerService extends SystemService {
Binder.restoreCallingIdentity(identity);
}
- mListeners.notifyRemovedLocked(r.sbn);
+ mListeners.notifyRemovedLocked(r.sbn, cloneNotificationListLocked());
}
// ATTENTION: in a future release we will bail out here
// so that we do not play sounds, show lights, etc. for invalid
@@ -2041,14 +2041,17 @@ public class NotificationManagerService extends SystemService {
private void handleSendRankingUpdate() {
synchronized (mNotificationList) {
- final int N = mNotificationList.size();
- ArrayList<StatusBarNotification> sbns =
- new ArrayList<StatusBarNotification>(N);
- for (int i = 0; i < N; i++ ) {
- sbns.add(mNotificationList.get(i).sbn);
- }
- mListeners.notifyOrderUpdateLocked(sbns);
+ mListeners.notifyRankingUpdateLocked(cloneNotificationListLocked());
+ }
+ }
+
+ private ArrayList<StatusBarNotification> cloneNotificationListLocked() {
+ final int N = mNotificationList.size();
+ ArrayList<StatusBarNotification> sbns = new ArrayList<StatusBarNotification>(N);
+ for (int i = 0; i < N; i++) {
+ sbns.add(mNotificationList.get(i).sbn);
}
+ return sbns;
}
private final class WorkerHandler extends Handler
@@ -2136,7 +2139,7 @@ public class NotificationManagerService extends SystemService {
Binder.restoreCallingIdentity(identity);
}
r.statusBarKey = null;
- mListeners.notifyRemovedLocked(r.sbn);
+ mListeners.notifyRemovedLocked(r.sbn, cloneNotificationListLocked());
}
// sound
@@ -2442,6 +2445,33 @@ public class NotificationManagerService extends SystemService {
}
}
+ /**
+ * Generates a NotificationRankingUpdate from 'sbns', considering only
+ * notifications visible to the given listener.
+ */
+ private static NotificationRankingUpdate makeRankingUpdateForListener(ManagedServiceInfo info,
+ ArrayList<StatusBarNotification> sbns) {
+ int speedBumpIndex = -1;
+ ArrayList<String> keys = new ArrayList<String>(sbns.size());
+ ArrayList<String> dndKeys = new ArrayList<String>(sbns.size());
+ for (StatusBarNotification sbn: sbns) {
+ if (!info.enabledAndUserMatches(sbn.getUserId())) {
+ continue;
+ }
+ keys.add(sbn.getKey());
+ if (sbn.getNotification().extras.getBoolean(EXTRA_INTERCEPT)) {
+ dndKeys.add(sbn.getKey());
+ }
+ if (speedBumpIndex == -1 &&
+ sbn.getNotification().priority == Notification.PRIORITY_MIN) {
+ speedBumpIndex = keys.size() - 1;
+ }
+ }
+ String[] keysAr = keys.toArray(new String[keys.size()]);
+ String[] dndKeysAr = dndKeys.toArray(new String[dndKeys.size()]);
+ return new NotificationRankingUpdate(keysAr, dndKeysAr, speedBumpIndex);
+ }
+
public class NotificationListeners extends ManagedServices {
public NotificationListeners() {
@@ -2468,9 +2498,12 @@ public class NotificationManagerService extends SystemService {
@Override
public void onServiceAdded(ManagedServiceInfo info) {
final INotificationListener listener = (INotificationListener) info.service;
- final String[] keys = getActiveNotificationKeys(listener);
+ final ArrayList<StatusBarNotification> sbns;
+ synchronized (mNotificationList) {
+ sbns = cloneNotificationListLocked();
+ }
try {
- listener.onListenerConnected(new NotificationOrderUpdate(keys));
+ listener.onListenerConnected(makeRankingUpdateForListener(info, sbns));
} catch (RemoteException e) {
// we tried
}
@@ -2479,44 +2512,47 @@ public class NotificationManagerService extends SystemService {
/**
* asynchronously notify all listeners about a new notification
*/
- public void notifyPostedLocked(StatusBarNotification sbn) {
+ public void notifyPostedLocked(StatusBarNotification sbn,
+ final ArrayList<StatusBarNotification> sbns) {
// make a copy in case changes are made to the underlying Notification object
final StatusBarNotification sbnClone = sbn.clone();
for (final ManagedServiceInfo info : mServices) {
- if (info.isEnabledForCurrentProfiles()) {
- final INotificationListener listener = (INotificationListener) info.service;
- final String[] keys = getActiveNotificationKeys(listener);
- if (keys.length > 0) {
- mHandler.post(new Runnable() {
- @Override
- public void run() {
- notifyPostedIfUserMatch(info, sbnClone, keys);
- }
- });
- }
+ if (!info.isEnabledForCurrentProfiles()) {
+ continue;
}
+ final NotificationRankingUpdate update = makeRankingUpdateForListener(info, sbns);
+ if (update.getOrderedKeys().length == 0) {
+ continue;
+ }
+ mHandler.post(new Runnable() {
+ @Override
+ public void run() {
+ notifyPostedIfUserMatch(info, sbnClone, update);
+ }
+ });
}
}
/**
* asynchronously notify all listeners about a removed notification
*/
- public void notifyRemovedLocked(StatusBarNotification sbn) {
+ public void notifyRemovedLocked(StatusBarNotification sbn,
+ final ArrayList<StatusBarNotification> sbns) {
// make a copy in case changes are made to the underlying Notification object
// NOTE: this copy is lightweight: it doesn't include heavyweight parts of the
// notification
final StatusBarNotification sbnLight = sbn.cloneLight();
for (final ManagedServiceInfo info : mServices) {
- if (info.isEnabledForCurrentProfiles()) {
- final INotificationListener listener = (INotificationListener) info.service;
- final String[] keys = getActiveNotificationKeys(listener);
- mHandler.post(new Runnable() {
- @Override
- public void run() {
- notifyRemovedIfUserMatch(info, sbnLight, keys);
- }
- });
+ if (!info.isEnabledForCurrentProfiles()) {
+ continue;
}
+ mHandler.post(new Runnable() {
+ @Override
+ public void run() {
+ notifyRemovedIfUserMatch(info, sbnLight,
+ makeRankingUpdateForListener(info, sbns));
+ }
+ });
}
}
@@ -2526,60 +2562,52 @@ public class NotificationManagerService extends SystemService {
* must not rely on mutable members of these objects, such as the
* {@link Notification}.
*/
- public void notifyOrderUpdateLocked(final ArrayList<StatusBarNotification> sbns) {
+ public void notifyRankingUpdateLocked(final ArrayList<StatusBarNotification> sbns) {
for (final ManagedServiceInfo serviceInfo : mServices) {
+ if (!serviceInfo.isEnabledForCurrentProfiles()) {
+ continue;
+ }
mHandler.post(new Runnable() {
@Override
public void run() {
- notifyOrderUpdateIfUserMatch(serviceInfo, sbns);
+ notifyRankingUpdate(serviceInfo,
+ makeRankingUpdateForListener(serviceInfo, sbns));
}
});
}
}
private void notifyPostedIfUserMatch(final ManagedServiceInfo info,
- final StatusBarNotification sbn, String[] keys) {
+ final StatusBarNotification sbn, NotificationRankingUpdate rankingUpdate) {
if (!info.enabledAndUserMatches(sbn.getUserId())) {
return;
}
final INotificationListener listener = (INotificationListener)info.service;
try {
- listener.onNotificationPosted(sbn, new NotificationOrderUpdate(keys));
+ listener.onNotificationPosted(sbn, rankingUpdate);
} catch (RemoteException ex) {
Log.e(TAG, "unable to notify listener (posted): " + listener, ex);
}
}
private void notifyRemovedIfUserMatch(ManagedServiceInfo info, StatusBarNotification sbn,
- String[] keys) {
+ NotificationRankingUpdate rankingUpdate) {
if (!info.enabledAndUserMatches(sbn.getUserId())) {
return;
}
- final INotificationListener listener = (INotificationListener)info.service;
+ final INotificationListener listener = (INotificationListener) info.service;
try {
- listener.onNotificationRemoved(sbn, new NotificationOrderUpdate(keys));
+ listener.onNotificationRemoved(sbn, rankingUpdate);
} catch (RemoteException ex) {
Log.e(TAG, "unable to notify listener (removed): " + listener, ex);
}
}
- /**
- * @param sbns an array of {@link StatusBarNotification}s to consider. This code
- * must not rely on mutable members of these objects, such as the
- * {@link Notification}.
- */
- public void notifyOrderUpdateIfUserMatch(ManagedServiceInfo info,
- ArrayList<StatusBarNotification> sbns) {
- ArrayList<String> keys = new ArrayList<String>(sbns.size());
- for (StatusBarNotification sbn: sbns) {
- if (info.enabledAndUserMatches(sbn.getUserId())) {
- keys.add(sbn.getKey());
- }
- }
- final INotificationListener listener = (INotificationListener)info.service;
+ private void notifyRankingUpdate(ManagedServiceInfo info,
+ NotificationRankingUpdate rankingUpdate) {
+ final INotificationListener listener = (INotificationListener) info.service;
try {
- listener.onNotificationOrderUpdate(
- new NotificationOrderUpdate(keys.toArray(new String[keys.size()])));
+ listener.onNotificationRankingUpdate(rankingUpdate);
} catch (RemoteException ex) {
Log.e(TAG, "unable to notify listener (ranking update): " + listener, ex);
}