Repository navigation
feat: usage collection into a local buffer - #15
Merged
Merged
Conversation
A session ends on pause, another app, screen off or shutdown; activity switches inside one app stay one session. Events are Unix seconds, at most a day each, with an event_id derived from app and start time so re-reading a window never duplicates anything. No label, no domain.
Collection starts at pairing, so nothing from before is read. Each run stores its events and the new cursor in one transaction; a session still running at the end of a run is finished in a later one.
Reads UsageEvents with the usage access the user grants, skips this app and the launcher, and runs through WorkManager without a network constraint because Android keeps raw events only for a few days.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #12
What
Reads foreground app sessions from
UsageStatsManagerand keeps them in a local Room buffer, independent of the network. Nothing is uploaded yet; that is #13.UsageEventssince the last run, builds sessions and stores the events together with the new starting point in one Room transaction.start_ts,duration_secsup to 86400 (longer sessions are split, under 1 s dropped), package name asapp_id. Nolabel, nodomain, never a category. Theevent_idis a hash of app and start time, so re-reading a window never duplicates anything locally or on the server.Security / privacy relevant
PACKAGE_USAGE_STATS(a special access the user grants in the settings) and a<queries>entry for the HOME intent, used only to find the launcher.Dependencies
Room 2.8.5, WorkManager 2.12.0 and KSP 2.3.12, each more than two weeks old. Most of the new verification-metadata entries are compile-time tooling for the Room compiler (Guava, kotlinpoet, sqlite-jdbc). The release runtime classpath gains only androidx modules (Room, SQLite, WorkManager, Lifecycle parts), and contains nothing from Play Services or Firebase. All CI tasks pass one at a time with a cold
GRADLE_USER_HOME. The Room schema is committed underapp/schemas/.Tests
UsageSessionsTest,SessionEventsTestandUsageCollectorTest(against a fake DAO). The Room DAO itself and the Android side have not been exercised on a device yet:UsageEventstypes, launcher detection and the WorkManager schedule are all untested.