mirror of
https://codeberg.org/fynngodau/usageDirect.git
synced 2026-04-21 07:20:39 +00:00
The usageDirect event log wrapper receives data from UsageStatsManager's event log API. The data format is a "list" of events which are worked through in order. The process is tricky and requires assumptions and workarounds, which are documented here.
- Query time is the time interval that the event log wrapper is queried for.
- It is currently at most spanning across one day (not across midnight) in the user's timezone (see #25).
- Now is the point in time at which the query is happening. Now may be inside query time. Ago is relative to now.
- A dashed out scenario should not happen, but has to be expected anyway (faulty data).
- Current behavior normally describes how the event log wrapper interprets data. A behavior in italics is not implemented in the event log wrapper, but performed by the usageDirect process that copies the data to database.
- Rules apply top to bottom.
| Scenario | Technical name | Handled | Current behavior |
|---|---|---|---|
| App opens and closes within query time | Open and close events in order | Yes | Count from open event until close event |
| ––– | Duplicate close event | Yes | Drop second close event |
| ––– | Duplicate open event | Yes | Drop first open event |
| Device is powered off | Shutdown event | Yes | Treat shutdown event as close event for all previous unmatched open events (per Android docs) |
| Device is booted | Startup event | Yes | Drop all previous unmatched open events (per Android docs) |
| App opens before query time | True unmatched close event | Yes | If open event is contained in logs of the preceeding 24 hours, count from start of query time until close event, drop otherwise (UnmatchedCloseEventGuardian) |
| ––– | Faulty unmatched close event | Yes | Drop event |
| App closes after query time | True unmatched open event | Partially | If query time ends in the future and if app contained in ActivityManager.getRunningAppProcesses()¹, count from open event until now, drop otherwise (can cause #25) |
| ––– | Faulty unmatched open event | Yes | Drop event |
| App open for whole query time | No event | Partially | If query time ends in the future and if app contained in ActivityManager.getRunningAppProcesses()¹, count from start of query time until now, undetected otherwise |
| Event log is emptied | Data gone | Yes | Don't overwrite existing data, add new data incrementally |
| Switch timezone | Midnight moves in time | Yes | Add time that was not counted yet to the day it belongs assuming the timezone at query time |
¹Documented as not inteded for this purpose and does not work with the app set as launcher app.