2

The file under consideration is any file under /data/system/usagestats/0/daily/. The entries it has are like:

<package lastTimeActive="77497976" package="com.android.settings" timeActive="471657" lastEvent="2" /> 
<package lastTimeActive="50486897" package="com.android.dialer" timeActive="180327" lastEvent="2" />
<package lastTimeActive="83158956" package="com.cyanogenmod.trebuchet" timeActive="461860" lastEvent="2" />
<package lastTimeActive="59444603" package="com.slovoed.oald" timeActive="405608" lastEvent="2" />

Here is the complete text for the file 1438905600000.

The value 77497976 doesn't seem to be Unix Time, and 471657 seems to be milliseconds.

I added that value into the value mentioned in file name i.e. 1438905600000 + 77497976, and the converted resultant of 1438983097976 here doesn't reflect the actual result shown in GUI here:

(Click image to enlarge; screenshot was taken on Aug 8, 2015 at 05:08 AM)

IMG: Screenshot of Usage Statistics

Package name of apps shown in screenshot whose raw time-stamps you can see in the file:

  • Settings → com.android.settings
  • Dialer → com.android.dialer
  • Launcher3 → com.cyanogenmod.trebuchet
  • SQLite Editor → com.speedsoftware.sqleditor
  • Titanium Backup → com.keramidas.titaniumbackup
  • OALD → com.slovoed.oald
  • ES File Explorer → com.estrongs.android.pop
  • Clock → com.android.deskclock

adb shell su -c 'dumpsys usagestats' is of no help since it gives no output to me.

In Android 4.x, it is easy to understand the time-stamp (mainly the "last time used") because Unix Time is written in the logs, and you can convert it into human readable time easily.

I looked at UsageStats, UsageStatsManager, UsageStatsActivity but couldn't understand how the time gets converted.


Alternatively, is there a schema which Lollipop follows to write entries in those usage-stats file? Perhaps, that can help to figure out in conversion?

I'm using a rooted OnePlus One running CM12.

  • timeActive seems to be corresponding to "Usage Time" (i.e. how long the app was active) in ms, as you assumed. The others don't seem to make a match, even considering time-zone differences (Aug 7 23:31:37 from what I've calculated using date -d @<unixtime>; times again in ms). Maybe you could edit your question and include numbers for the other apps so we might see a pattern? "Last time used" somehow suggest user action (direct invocation); maybe the settings app was triggered "indirectly"? – Izzy Aug 8 '15 at 19:40
  • I actually posted the full file here as mentioned. Also, I made sure that entries in the screenshot and the time I copied those remains the same. Are you asking something else? – Firelord Aug 8 '15 at 19:46
  • Ooops – I revoke that part of my previous comment, missed that link, sorry. But that makes it even more strange, as the entries don't match: from the file, DeskClock was LRU; I don't see it in the screenshot. From the screenshot, TiBu was used shortly; I can't find that in the file. I'm confused. // Btw: does the usage-history.xml still exist with Lollipop, and in the same place as with 4.x? This blogpost suggests as much. – Izzy Aug 8 '15 at 19:52
  • 1
    What I'm playing at: You might have picked the wrong file to compare with. Your screenshot is newer (Aug 8, 5 am) than the file (Aug 7, 2 am); on Aug 8, 2 am Android could have started a new file (if it does so all 24h that is). As that's just argued by the file name: what does ls -l give for its last "touch"? – Izzy Aug 8 '15 at 19:57
  • Fresh piece: This is the recent screenshot I took after using ES File Explorer: i.stack.imgur.com/wdMbY.png. Here is the stats file I immediately captured after closing Explorer: pastebin.com/X4A5Knha – Firelord Aug 8 '15 at 20:00

Your Answer

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

Browse other questions tagged or ask your own question.