ashar-7 / ScreenTrack-Android

Android App for monitoring app usage. Using MVVM architecture and Dagger Hilt.
21 stars 0 forks source link

Getting wrong sessions/stats for some applications #3

Open shadygoneinsane opened 2 years ago

shadygoneinsane commented 2 years ago

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,

Issue_session_1_1 Issue_session_1_2 Issue_session_1_3

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.

shadygoneinsane commented 2 years ago

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..

ashar-7 commented 2 years ago

Hey, thanks for looking into it! I'm pretty busy these days but will look into it when I have some free time.

mrstark-coder commented 1 year ago

Of Course Me Too @ashar-7