From 6ecaff15836581336b1e8fad6ac42f3ff4a13544 Mon Sep 17 00:00:00 2001 From: Fred Quintana Date: Fri, 25 Sep 2009 14:23:13 -0700 Subject: [PATCH] add a optional String to the key of notifications to allow users to scope them --- api/current.xml | 32 ++++++++ .../android/app/INotificationManager.aidl | 4 + .../java/android/app/NotificationManager.java | 29 ++++++- .../server/NotificationManagerService.java | 82 ++++++++++++------- .../server/status/NotificationData.java | 4 +- .../server/status/StatusBarService.java | 12 +-- 6 files changed, 122 insertions(+), 41 deletions(-) diff --git a/api/current.xml b/api/current.xml index 3612104e53f0f..54cff8dccba2a 100644 --- a/api/current.xml +++ b/api/current.xml @@ -23166,6 +23166,21 @@ + + + + + + + + + + + + + + mNotificationList; + private final ArrayList mNotificationList = + new ArrayList(); private ArrayList mToastQueue; @@ -152,20 +152,22 @@ class NotificationManagerService extends INotificationManager.Stub private static final class NotificationRecord { - String pkg; - int id; + final String pkg; + final String tag; + final int id; ITransientNotification callback; int duration; - Notification notification; + final Notification notification; IBinder statusBarKey; - NotificationRecord(String pkg, int id, Notification notification) + NotificationRecord(String pkg, String tag, int id, Notification notification) { this.pkg = pkg; + this.tag = tag; this.id = id; this.notification = notification; } - + void dump(PrintWriter pw, String prefix, Context baseContext) { pw.println(prefix + this); pw.println(prefix + " icon=0x" + Integer.toHexString(notification.icon) @@ -189,7 +191,8 @@ class NotificationManagerService extends INotificationManager.Stub return "NotificationRecord{" + Integer.toHexString(System.identityHashCode(this)) + " pkg=" + pkg - + " id=" + Integer.toHexString(id) + "}"; + + " id=" + Integer.toHexString(id) + + " tag=" + tag + "}"; } } @@ -258,8 +261,8 @@ class NotificationManagerService extends INotificationManager.Stub cancelAll(); } - public void onNotificationClick(String pkg, int id) { - cancelNotification(pkg, id, Notification.FLAG_AUTO_CANCEL, + public void onNotificationClick(String pkg, String tag, int id) { + cancelNotification(pkg, tag, id, Notification.FLAG_AUTO_CANCEL, Notification.FLAG_FOREGROUND_SERVICE); } @@ -369,7 +372,6 @@ class NotificationManagerService extends INotificationManager.Stub mSound = new AsyncPlayer(TAG); mSound.setUsesWakeLock(context); mToastQueue = new ArrayList(); - mNotificationList = new ArrayList(); mHandler = new WorkerHandler(); mStatusBarService = statusBar; statusBar.setNotificationCallbacks(mNotificationCallbacks); @@ -582,6 +584,12 @@ class NotificationManagerService extends INotificationManager.Stub // Notifications // ============================================================================ public void enqueueNotification(String pkg, int id, Notification notification, int[] idOut) + { + enqueueNotificationWithTag(pkg, null /* tag */, id, notification, idOut); + } + + public void enqueueNotificationWithTag(String pkg, String tag, int id, + Notification notification, int[] idOut) { checkIncomingCall(pkg); @@ -608,10 +616,10 @@ class NotificationManagerService extends INotificationManager.Stub } synchronized (mNotificationList) { - NotificationRecord r = new NotificationRecord(pkg, id, notification); + NotificationRecord r = new NotificationRecord(pkg, tag, id, notification); NotificationRecord old = null; - int index = indexOfNotificationLocked(pkg, id); + int index = indexOfNotificationLocked(pkg, tag, id); if (index < 0) { mNotificationList.add(r); } else { @@ -645,17 +653,18 @@ class NotificationManagerService extends INotificationManager.Stub } NotificationData n = new NotificationData(); - n.id = id; - n.pkg = pkg; - n.when = notification.when; - n.tickerText = truncatedTicker; - n.ongoingEvent = (notification.flags & Notification.FLAG_ONGOING_EVENT) != 0; - if (!n.ongoingEvent && (notification.flags & Notification.FLAG_NO_CLEAR) == 0) { - n.clearable = true; - } - n.contentView = notification.contentView; - n.contentIntent = notification.contentIntent; - n.deleteIntent = notification.deleteIntent; + n.pkg = pkg; + n.tag = tag; + n.id = id; + n.when = notification.when; + n.tickerText = truncatedTicker; + n.ongoingEvent = (notification.flags & Notification.FLAG_ONGOING_EVENT) != 0; + if (!n.ongoingEvent && (notification.flags & Notification.FLAG_NO_CLEAR) == 0) { + n.clearable = true; + } + n.contentView = notification.contentView; + n.contentIntent = notification.contentIntent; + n.deleteIntent = notification.deleteIntent; if (old != null && old.statusBarKey != null) { r.statusBarKey = old.statusBarKey; long identity = Binder.clearCallingIdentity(); @@ -828,16 +837,14 @@ class NotificationManagerService extends INotificationManager.Stub * Cancels a notification ONLY if it has all of the {@code mustHaveFlags} * and none of the {@code mustNotHaveFlags}. */ - private void cancelNotification(String pkg, int id, int mustHaveFlags, + private void cancelNotification(String pkg, String tag, int id, int mustHaveFlags, int mustNotHaveFlags) { EventLog.writeEvent(EVENT_LOG_CANCEL, pkg, id, mustHaveFlags); synchronized (mNotificationList) { - NotificationRecord r = null; - - int index = indexOfNotificationLocked(pkg, id); + int index = indexOfNotificationLocked(pkg, tag, id); if (index >= 0) { - r = mNotificationList.get(index); + NotificationRecord r = mNotificationList.get(index); if ((r.notification.flags & mustHaveFlags) != mustHaveFlags) { return; @@ -888,9 +895,13 @@ class NotificationManagerService extends INotificationManager.Stub public void cancelNotification(String pkg, int id) { + cancelNotificationWithTag(pkg, null /* tag */, id); + } + + public void cancelNotificationWithTag(String pkg, String tag, int id) { checkIncomingCall(pkg); // Don't allow client applications to cancel foreground service notis. - cancelNotification(pkg, id, 0, + cancelNotification(pkg, tag, id, 0, Binder.getCallingUid() == Process.SYSTEM_UID ? 0 : Notification.FLAG_FOREGROUND_SERVICE); } @@ -999,12 +1010,21 @@ class NotificationManagerService extends INotificationManager.Stub } // lock on mNotificationList - private int indexOfNotificationLocked(String pkg, int id) + private int indexOfNotificationLocked(String pkg, String tag, int id) { ArrayList list = mNotificationList; final int len = list.size(); for (int i=0; i