Getting wrong sessions/stats for some applications
I could find some applications for which the getSessions() in AppUsageManager.kt gives Session object starting from midnight i.e from 00:00:00 to a time from where the actual first session started which is the subsequent session in the sessions list.
This causes the overall usage time to be much more than what it actually is and gives the wrong session info as well..
For reference, I am attaching some screenshots,

I believe this is due to the fact that we consider 'startTime' for events that are not initialized as 'timeStart' - I will test some more and put my observations here, meanwhile please check if you are getting the same issue as well.
UsageEvents.Event.ACTIVITY_PAUSED -> { // same as MOVE_TO_BACKGROUND
// end time
if(startTime == 0L) {
if(!isInitialized) {
startTime = timeStart
endTime = event.timeStamp
}
} else {
endTime = event.timeStamp
}
}
I appreciate your time and effort put in this project, Thanks for this project.
I tried debugging and the first event was going in this condition UsageEvents.Event.ACTIVITY_PAUSED which afterward I replaced by simply
endTime = event.timeStamp
seems to work fine, I will test some more and put my findings here..
Between I am using Google's Wellbeing tools and one more third-party app StayFree app to compare the stats I am getting from your code... I hope you will find time to check and compare for yourselves as well..
Hey, thanks for looking into it! I'm pretty busy these days but will look into it when I have some free time.
Of Course Me Too @ashar-7