diff options
author | Christoph Studer <chstuder@google.com> | 2014-05-20 17:02:04 +0200 |
---|---|---|
committer | Christoph Studer <chstuder@google.com> | 2014-05-22 21:41:13 +0000 |
commit | 71f18fd1b64071e486bafff237b1f87a56d4aead (patch) | |
tree | a821f54079e84ec8ad246408e94b156f81653fb8 /services | |
parent | 42b30e1b832df5bbf109db2f4f864f8ba4cfd44a (diff) | |
download | frameworks_base-71f18fd1b64071e486bafff237b1f87a56d4aead.zip frameworks_base-71f18fd1b64071e486bafff237b1f87a56d4aead.tar.gz frameworks_base-71f18fd1b64071e486bafff237b1f87a56d4aead.tar.bz2 |
SysUI: Use SBN keys instead of IBinder keys DO NOT MERGE
In preparation of migrating to NotificationListenerService,
remove dependence on IBinder keys for notifications and switch
to SBN.getKey() instead.
Bug: 15131411
Change-Id: Ic272e4a05fde6481c734144c5b34c49b2f021649
(cherry picked from commit 7c96ae873d9a54ebaeb5b7ef21b48224dc42d094)
Diffstat (limited to 'services')
3 files changed, 41 insertions, 36 deletions
diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index 0b3e02a..b9a69ab 100644 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -457,7 +457,7 @@ public class NotificationManagerService extends SystemService { { final StatusBarNotification sbn; SingleNotificationStats stats; - IBinder statusBarKey; + boolean isCanceled; // These members are used by NotificationSignalExtractors // to communicate with the ranking module. @@ -472,6 +472,7 @@ public class NotificationManagerService extends SystemService { public Notification getNotification() { return sbn.getNotification(); } public int getFlags() { return sbn.getNotification().flags; } public int getUserId() { return sbn.getUserId(); } + public String getKey() { return sbn.getKey(); } void dump(PrintWriter pw, String prefix, Context baseContext) { final Notification notification = sbn.getNotification(); @@ -1668,7 +1669,7 @@ public class NotificationManagerService extends SystemService { "pkg=" + pkg + " canInterrupt=" + canInterrupt + " intercept=" + intercept); synchronized (mNotificationList) { NotificationRecord old = null; - int index = indexOfNotificationLocked(pkg, tag, id, userId); + int index = indexOfNotificationLocked(n.getKey()); if (index < 0) { mNotificationList.add(r); mUsageStats.registerPostedByApp(r); @@ -1677,12 +1678,8 @@ public class NotificationManagerService extends SystemService { mNotificationList.set(index, r); mUsageStats.registerUpdatedByApp(r, old); // Make sure we don't lose the foreground service state. - if (old != null) { - notification.flags |= - old.getNotification().flags & Notification.FLAG_FOREGROUND_SERVICE; - } - } - if (old != null) { + notification.flags |= + old.getNotification().flags & Notification.FLAG_FOREGROUND_SERVICE; mNotificationsByKey.remove(old.sbn.getKey()); } mNotificationsByKey.put(n.getKey(), r); @@ -1705,18 +1702,17 @@ public class NotificationManagerService extends SystemService { } if (notification.icon != 0) { - if (old != null && old.statusBarKey != null) { - r.statusBarKey = old.statusBarKey; + if (old != null && !old.isCanceled) { final long identity = Binder.clearCallingIdentity(); try { - mStatusBar.updateNotification(r.statusBarKey, n); + mStatusBar.updateNotification(n); } finally { Binder.restoreCallingIdentity(identity); } } else { final long identity = Binder.clearCallingIdentity(); try { - r.statusBarKey = mStatusBar.addNotification(n); + mStatusBar.addNotification(n); if ((n.getNotification().flags & Notification.FLAG_SHOW_LIGHTS) != 0 && canInterrupt) { mAttentionLight.pulse(); @@ -1733,10 +1729,10 @@ public class NotificationManagerService extends SystemService { mListeners.notifyPostedLocked(r.sbn, cloneNotificationListLocked()); } else { Slog.e(TAG, "Not posting notification with icon==0: " + notification); - if (old != null && old.statusBarKey != null) { + if (old != null && !old.isCanceled) { final long identity = Binder.clearCallingIdentity(); try { - mStatusBar.removeNotification(old.statusBarKey); + mStatusBar.removeNotification(r.getKey()); } finally { Binder.restoreCallingIdentity(identity); } @@ -2120,11 +2116,11 @@ public class NotificationManagerService extends SystemService { if (r.getNotification().icon != 0) { final long identity = Binder.clearCallingIdentity(); try { - mStatusBar.removeNotification(r.statusBarKey); + mStatusBar.removeNotification(r.getKey()); } finally { Binder.restoreCallingIdentity(identity); } - r.statusBarKey = null; + r.isCanceled = true; mListeners.notifyRemovedLocked(r.sbn, cloneNotificationListLocked()); } @@ -2392,6 +2388,18 @@ public class NotificationManagerService extends SystemService { return -1; } + // lock on mNotificationList + int indexOfNotificationLocked(String key) { + NotificationRecord r = mNotificationsByKey.get(key); + if (r == null) { + return -1; + } + int index = Collections.binarySearch(mNotificationList, r, mRankingComparator); + // Guarantee to return -1 when not found. + return (index >= 0) ? index : -1; + } + + private void updateNotificationPulse() { synchronized (mNotificationList) { updateLightsLocked(); diff --git a/services/core/java/com/android/server/statusbar/StatusBarManagerInternal.java b/services/core/java/com/android/server/statusbar/StatusBarManagerInternal.java index 4f75189..8d905ba 100644 --- a/services/core/java/com/android/server/statusbar/StatusBarManagerInternal.java +++ b/services/core/java/com/android/server/statusbar/StatusBarManagerInternal.java @@ -23,7 +23,7 @@ import android.service.notification.StatusBarNotification; public interface StatusBarManagerInternal { void setNotificationDelegate(NotificationDelegate delegate); - IBinder addNotification(StatusBarNotification notification); - void updateNotification(IBinder key, StatusBarNotification notification); - void removeNotification(IBinder key); + void addNotification(StatusBarNotification notification); + void updateNotification(StatusBarNotification notification); + void removeNotification(String key); } diff --git a/services/core/java/com/android/server/statusbar/StatusBarManagerService.java b/services/core/java/com/android/server/statusbar/StatusBarManagerService.java index 8b8c73d..55b5e3b 100644 --- a/services/core/java/com/android/server/statusbar/StatusBarManagerService.java +++ b/services/core/java/com/android/server/statusbar/StatusBarManagerService.java @@ -60,8 +60,8 @@ public class StatusBarManagerService extends IStatusBarService.Stub private NotificationDelegate mNotificationDelegate; private volatile IStatusBar mBar; private StatusBarIconList mIcons = new StatusBarIconList(); - private HashMap<IBinder,StatusBarNotification> mNotifications - = new HashMap<IBinder,StatusBarNotification>(); + private HashMap<String,StatusBarNotification> mNotifications + = new HashMap<String,StatusBarNotification>(); // for disabling the status bar private final ArrayList<DisableRecord> mDisableRecords = new ArrayList<DisableRecord>(); @@ -117,30 +117,29 @@ public class StatusBarManagerService extends IStatusBarService.Stub } @Override - public IBinder addNotification(StatusBarNotification notification) { + public void addNotification(StatusBarNotification notification) { synchronized (mNotifications) { - IBinder key = new Binder(); - mNotifications.put(key, notification); + mNotifications.put(notification.getKey(), notification); if (mBar != null) { try { - mBar.addNotification(key, notification); + mBar.addNotification(notification); } catch (RemoteException ex) { } } - return key; } } @Override - public void updateNotification(IBinder key, StatusBarNotification notification) { + public void updateNotification(StatusBarNotification notification) { synchronized (mNotifications) { + String key = notification.getKey(); if (!mNotifications.containsKey(key)) { throw new IllegalArgumentException("updateNotification key not found: " + key); } - mNotifications.put(key, notification); + mNotifications.put(notification.getKey(), notification); if (mBar != null) { try { - mBar.updateNotification(key, notification); + mBar.updateNotification(notification); } catch (RemoteException ex) { } } @@ -148,7 +147,7 @@ public class StatusBarManagerService extends IStatusBarService.Stub } @Override - public void removeNotification(IBinder key) { + public void removeNotification(String key) { synchronized (mNotifications) { final StatusBarNotification n = mNotifications.remove(key); if (n == null) { @@ -512,8 +511,7 @@ public class StatusBarManagerService extends IStatusBarService.Stub // ================================================================================ @Override public void registerStatusBar(IStatusBar bar, StatusBarIconList iconList, - List<IBinder> notificationKeys, List<StatusBarNotification> notifications, - int switches[], List<IBinder> binders) { + List<StatusBarNotification> notifications, int switches[], List<IBinder> binders) { enforceStatusBarService(); Slog.i(TAG, "registerStatusBar bar=" + bar); @@ -522,9 +520,8 @@ public class StatusBarManagerService extends IStatusBarService.Stub iconList.copyFrom(mIcons); } synchronized (mNotifications) { - for (Map.Entry<IBinder,StatusBarNotification> e: mNotifications.entrySet()) { - notificationKeys.add(e.getKey()); - notifications.add(e.getValue()); + for (StatusBarNotification sbn : mNotifications.values()) { + notifications.add(sbn); } } synchronized (mLock) { @@ -714,7 +711,7 @@ public class StatusBarManagerService extends IStatusBarService.Stub synchronized (mNotifications) { int i=0; pw.println("Notification list:"); - for (Map.Entry<IBinder,StatusBarNotification> e: mNotifications.entrySet()) { + for (Map.Entry<String,StatusBarNotification> e: mNotifications.entrySet()) { pw.printf(" %2d: %s\n", i, e.getValue().toString()); i++; } |