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.

Firelord
  • 25,084
  • 20
  • 124
  • 286
  • 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 08 '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 08 '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 08 '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 08 '15 at 19:57
  • Fresh piece: This is the recent screenshot I took after using ES File Explorer: http://i.stack.imgur.com/wdMbY.png. Here is the stats file I immediately captured after closing Explorer: http://pastebin.com/X4A5Knha – Firelord Aug 08 '15 at 20:00
  • ls -l 1438992000000 gives me 2015-08-08 22:39 which is weird because it's not correct as per screenshot. Even if it's GMT, it's incorrect since it should be -05:30 from the screenshot in its output as Android outputs GMT in shell. – Firelord Aug 08 '15 at 20:05
  • Agreed. And again, the file doesn't reflect the screenshot: the top 3 from the file (if ordered by lastTimeActive) are not included with the screenshot at the position I'd expect them – but a lot closer to the bottom. And vice-versa. Note: EndTime matches lastTimeActive of Trebuchet (Launcher), making that the last-used app (and ruling out "RTL" writing of numbers, which I almost started to suspect). Again: Is the /data/system/usagestats/usage-history.xml available to check against? – Izzy Aug 08 '15 at 20:21
  • The concept of having a single usage-history.xml in only applicable until Kitkat. Since Lollipop, all the usage-stats are in folders viz. daily, weekly, monthly and yearly. The files their are plain XML but extension is missing, Their name is the UNIX TIME when they were created. Usually created at 00:00 GMT. – Firelord Aug 08 '15 at 20:28
  • Also, in the recent screenshot, the entries of Settings, Dialer, and Launcher3 is correct before ES File Explorer, since I entered the code in dialer to launch Testing settings, and I visited the dialer using launcher. All of this happened after using Explorer app, so the screenshot is absolutely correct. The issue is with the file! – Firelord Aug 08 '15 at 20:32
  • Have you been able to solve the mystery meanwhile? – Izzy Jul 23 '16 at 23:40
  • Nope. Primarily because I abandoned this issue, and time, unfortunately and as of now, doesn't permit me to do research at all. – Firelord Jul 24 '16 at 00:13

0 Answers0