@@ -32,6 +32,7 @@ import java.text.ParseException
32
32
class UsageStatsWatcher constructor(val context : Context ) {
33
33
private val TAG = " UsageStatsWatcher"
34
34
private val bucket_id = " aw-watcher-android-test"
35
+ private val unlock_bucket_id = " aw-watcher-android-unlock"
35
36
36
37
private val ri = RustInterface (context)
37
38
private val isoFormatter = SimpleDateFormat (" yyyy-MM-dd'T'HH:mm:ss.SSSXXX" )
@@ -145,6 +146,7 @@ class UsageStatsWatcher constructor(val context: Context) {
145
146
146
147
// TODO: Use other bucket type when support for such a type has been implemented in aw-webui
147
148
ri.createBucketHelper(bucket_id, " currentwindow" )
149
+ ri.createBucketHelper(unlock_bucket_id, " os.lockscreen.unlocks" )
148
150
lastUpdated = getLastEventTime()
149
151
Log .w(TAG , " lastUpdated: ${lastUpdated?.toString() ? : " never" } " )
150
152
@@ -156,11 +158,17 @@ class UsageStatsWatcher constructor(val context: Context) {
156
158
val event = UsageEvents .Event ()
157
159
usageEvents.getNextEvent(event)
158
160
if (event.eventType !in arrayListOf (UsageEvents .Event .ACTIVITY_RESUMED , UsageEvents .Event .ACTIVITY_PAUSED )) {
161
+ if (event.eventType == UsageEvents .Event .KEYGUARD_HIDDEN ){
162
+ val timestamp = DateTimeUtils .toInstant(java.util.Date (event.timeStamp))
163
+ // NOTE: getLastEventTime() returns the last time of an event from the activity bucket(bucket_id)
164
+ // Therefore, if an unlock happens after last event from main bucket, unlock event will get sent twice.
165
+ // Fortunately not an issue because identical events will get merged together (see heartbeats)
166
+ ri.heartbeatHelper(unlock_bucket_id, timestamp, 0.0 , JSONObject (), 0.0 )
167
+ }
159
168
// Not sure which events are triggered here, so we use a (probably safe) fallback
160
169
// Log.d(TAG, "Rare eventType: ${event.eventType}, skipping")
161
170
continue @nextEvent
162
171
}
163
-
164
172
val awEvent = Event .fromUsageEvent(event, context, includeClassname = true )
165
173
val pulsetime: Double
166
174
when (event.eventType) {
0 commit comments