Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 78d0d25d authored by Daniel Sandler's avatar Daniel Sandler
Browse files

Historical notification access API.

Similar to getActiveNotifications(),
getHistoricalNotifications() returns a list of all
notifications that have been posted, in
reverse-chronological order. It currently includes duplicate
entries for notifications that have been updated (so it
really is tracking every notification that has been posted
to the system).

Change-Id: Icce8d6f96bbe76710c989fd0068ff971c6498605
parent bde3104d
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -38,5 +38,6 @@ interface INotificationManager
    boolean areNotificationsEnabledForPackage(String pkg, int uid);

    StatusBarNotification[] getActiveNotifications(String callingPkg);
    StatusBarNotification[] getHistoricalNotifications(String callingPkg, int count);
}
+42 −2
Original line number Diff line number Diff line
@@ -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;