4

Android 4.3 and above allows access to a list of historical notifications using the Settings widget. The scope of "historical" is limited to current session of Android and the list is populated with new entries once the system is rebooted.

(Click image to enlarge)

IMG:

So, where does this notification log is stored in Android?

  • I had no luck finding anything good named "notification". I already did a system-wide search with nothing positive to report here.

    find / -iname "*notification*"
    
  • I watched the real-time output of adb logcat -v long (tried with explicit root access as well) but there was no common event when a notification popped up in notification drawer. I was monitoring the ping request (shows up as a notification) to KDE Connect sent from my Slackware Linux, for the test case.

  • The entries that are visible in Notification drawer can be traced back to the output of notification service,

    adb shell dumpsys notification
    

    As said, you get the current ones but not the historical ones.

  • The real name or codename (I suppose) of notification service is android.app.INotificationManager. I attempted to dive into its source code and there is nothing positive to report. It is very likely that being not a programmer, I might have missed a thing or two of importance.

  • I, while being reluctant for being illogical, did peek into the data directory of Settings (com.android.settings) and Settings Storage (com.android.providers.settings) apps. Nothing interesting there.

I presume that either the log is managed in the memory by a program or at some location in storage where the logs are frequently flushed after current Android session ends. I've no idea what I'm talking here.

Edit:

I've the Notification access to Tasker under Settings → Notification manager already enabled. So that's definitely not the roadblock here.

(Asked by Lucky) The intent associated with that Notification log window accessible through Settings widget has the following things:

  • Action: android.intent.action.MAIN
  • Category: com.android.settings.SHORTCUT
  • Flag: 0x10200000
  • Component: com.android.settings/.Settings$NotificationStationActivity

Note

  • I've a rooted OnePlus One running COS12 (Xposed Framework installed) and many Android 5.1 ROMs.
  • I'm absolutely aware about many apps which can record notifications and lets you see them. But as you would've guessed by now, I'm not interested in futuristic past but the past related to present moment. In short, I want access to native raw files or logs to see both the historical and current notifications without depending on third-party apps.

My goal

When a secondary user is in focus, Tasker (running under Primary user) misses any profile which depends upon an incoming notification. Google has noted the fact here:

Notifications for other users do not appear until they are active.

But you can still see those new notifications in the output of adb shell dumpsys notification. So I want to access the logs directly to make my task(s) work, thereby removing the dependence on notifications showing up in Notification drawer.

  • Maybe use a service call. StatusBarNotification[] " getActiveNotifications() " that brings up a list of notifications that have not been dismissed. So there has to be one for all notifications let me go look up the notifications manager info. developer.android.com/reference/android/app/… developer.android.com/reference/android/service/notification/… – Bo Lawson Sep 23 '15 at 2:35
  • Thanks Bo, but I'm not into any programming even with Tasker. Honestly, I can't use it because you can't troubleshoot which you don't understand at all, at least I can't. Your approach may be able to give me the list, even if has only the current notifications, but the essence wouldn't be much different from the output of dumpsys notification. Ultimately, I asked for a file because I can set file modification event so the task would execute immediately. Your function or notification service's output has to be periodically checked for differences. – Firelord Sep 23 '15 at 2:45
  • I understand and unsure you are correct but I was just thinking that with a shell service call. You could then back trace through the log the actions taken. It was just a passing thought that I should mention just in case. I will keep my eye out though for a solution. – Bo Lawson Sep 23 '15 at 2:57
  • Can you able to find the Intent/Activity that is being called when the Notification Log widget is called?You have mentioned the interface INotificationManager while this interface will be implemented in a class and it's the NotificationManager class. – Lucky Sep 23 '15 at 10:35
  • Please check if this Notification Saver app can be of useful to you. It seems that you can export it to .csv and someone said it persists logs even after restart. – Lucky Sep 23 '15 at 10:45
5

The historical record is stored in memory, and is not directly available in the service API (as far as I'm aware). The Settings activity accesses it through the NotificationService.getHistoricalNotifications() method, but this method is not exposed in the NotificationManager API (only getActiveNotifications() is). You might be able to do it through reflection (not tested) but you definitely will not be able to find a file with this information. My understanding of most apps that display these records is that they actually keep their own list somewhere, and add new items as they are posted. Hence, they would not be able to access your historical record from before the time of installation.

All of the logic for managing the queue is in the NotificationManagerService$Archive inner class. The gist of it is that when a new notification comes in, the system sends it to the the service which then calls Archive.record(notification). By default, AOSP has the configuration set so that the Archive will hold a maximum of 100 records, then it will start popping the front item from the queue each time a new one is added.

Your only real option here is likely going to be polling the output of either adb dumpsys or the NotificationManager.

  • +1 Thank you. This gives a good insight. Just as I suspected, it's all in the memory. As for the third party apps, I tested two such apps and they recorded the notification entries in a database, that's why they can always show the entries after a reboot or so. – Firelord Sep 23 '15 at 15:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.