diff options
-rw-r--r-- | core/java/android/app/INotificationManager.aidl | 1 | ||||
-rw-r--r-- | services/java/com/android/server/NotificationManagerService.java | 44 |
2 files changed, 43 insertions, 2 deletions
diff --git a/core/java/android/app/INotificationManager.aidl b/core/java/android/app/INotificationManager.aidl index bb10f62..1f4c81d 100644 --- a/core/java/android/app/INotificationManager.aidl +++ b/core/java/android/app/INotificationManager.aidl @@ -38,5 +38,6 @@ interface INotificationManager boolean areNotificationsEnabledForPackage(String pkg, int uid); StatusBarNotification[] getActiveNotifications(String callingPkg); + StatusBarNotification[] getHistoricalNotifications(String callingPkg, int count); } diff --git a/services/java/com/android/server/NotificationManagerService.java b/services/java/com/android/server/NotificationManagerService.java index 1a2c3de..13bf39f 100644 --- a/services/java/com/android/server/NotificationManagerService.java +++ b/services/java/com/android/server/NotificationManagerService.java @@ -235,6 +235,31 @@ public class NotificationManagerService extends INotificationManager.Stub } }; } + + public StatusBarNotification[] getArray(int count) { + if (count == 0) count = Archive.BUFFER_SIZE; + final StatusBarNotification[] a + = new StatusBarNotification[Math.min(count, mBuffer.size())]; + Iterator<StatusBarNotification> iter = descendingIterator(); + int i=0; + while (iter.hasNext() && i < count) { + a[i++] = iter.next(); + } + return a; + } + + public StatusBarNotification[] getArray(int count, String pkg, int userId) { + if (count == 0) count = Archive.BUFFER_SIZE; + final StatusBarNotification[] a + = new StatusBarNotification[Math.min(count, mBuffer.size())]; + Iterator<StatusBarNotification> iter = filter(descendingIterator(), pkg, userId); + int i=0; + while (iter.hasNext() && i < count) { + a[i++] = iter.next(); + } + return a; + } + } Archive mArchive = new Archive(); @@ -347,10 +372,9 @@ public class NotificationManagerService extends INotificationManager.Stub public StatusBarNotification[] getActiveNotifications(String callingPkg) { mContext.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NOTIFICATIONS, - "NotificationManagerService"); + "NotificationManagerService.getActiveNotifications"); StatusBarNotification[] tmp = null; - int userId = UserHandle.getCallingUserId(); int uid = Binder.getCallingUid(); if (mAppOps.noteOpNoThrow(AppOpsManager.OP_ACCESS_NOTIFICATIONS, uid, callingPkg) @@ -366,6 +390,22 @@ public class NotificationManagerService extends INotificationManager.Stub return tmp; } + public StatusBarNotification[] getHistoricalNotifications(String callingPkg, int count) { + mContext.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NOTIFICATIONS, + "NotificationManagerService.getHistoricalNotifications"); + + StatusBarNotification[] tmp = null; + int uid = Binder.getCallingUid(); + + if (mAppOps.noteOpNoThrow(AppOpsManager.OP_ACCESS_NOTIFICATIONS, uid, callingPkg) + == AppOpsManager.MODE_ALLOWED) { + synchronized (mArchive) { + tmp = mArchive.getArray(count); + } + } + return tmp; + } + public static final class NotificationRecord { final StatusBarNotification sbn; |