Skip to content

Commit

Permalink
fixed zero duration issue by removing move_to_foreground/background e…
Browse files Browse the repository at this point in the history
…vents
  • Loading branch information
nicolae-stroncea committed Jun 27, 2020
1 parent de17c29 commit de9fe91
Showing 1 changed file with 5 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ class UsageStatsWatcher constructor(val context: Context) {
nextEvent@ while(usageEvents.hasNextEvent()) {
val event = UsageEvents.Event()
usageEvents.getNextEvent(event)
if(event.eventType !in arrayListOf(UsageEvents.Event.ACTIVITY_RESUMED, UsageEvents.Event.ACTIVITY_PAUSED, UsageEvents.Event.SCREEN_INTERACTIVE, UsageEvents.Event.SCREEN_NON_INTERACTIVE)) {
if(event.eventType !in arrayListOf(UsageEvents.Event.ACTIVITY_RESUMED, UsageEvents.Event.ACTIVITY_PAUSED)) {
// Not sure which events are triggered here, so we use a (probably safe) fallback
//Log.d(TAG, "Rare eventType: ${event.eventType}, skipping")
continue@nextEvent
Expand All @@ -164,14 +164,12 @@ class UsageStatsWatcher constructor(val context: Context) {
val awEvent = Event.fromUsageEvent(event, context, includeClassname = true)
val pulsetime: Double
when(event.eventType) {
UsageEvents.Event.ACTIVITY_RESUMED, UsageEvents.Event.SCREEN_INTERACTIVE -> {
// MOVE_TO_FOREGROUND: New Activity was opened
// SCREEN_INTERACTIVE: Screen just became interactive, user was previously therefore not active on the device
UsageEvents.Event.ACTIVITY_RESUMED -> {
// ACTIVITY_RESUMED: Activity was opened/reopened
pulsetime = 1.0
}
UsageEvents.Event.ACTIVITY_PAUSED, UsageEvents.Event.SCREEN_NON_INTERACTIVE -> {
// MOVE_TO_BACKGROUND: Activity was moved to background
// SCREEN_NOT_INTERACTIVE: Screen locked/turned off, user is therefore now AFK, and this is the last event
UsageEvents.Event.ACTIVITY_PAUSED -> {
// ACTIVITY_PAUSED: Activity was moved to background
pulsetime = 24 * 60 * 60.0 // 24h, we will assume events should never grow longer than that
}
else -> {
Expand Down

0 comments on commit de9fe91

Please sign in to comment.