fix(android): load widget classes from datastore, not unauthenticated HTTP - #653
Conversation
… HTTP androidQuery fetched settings.classes via AwClient to localhost:5600 without an API key. Android enables dashboard auth by default, so that GET 401'd (or failed when the HTTP server wasn't running) and silently fell back to default_classes(). The Activity view uses the user's custom classes, so per-category widget times diverged while totals still matched. Read settings.classes from the datastore the JNI query already has, parse them through a shared helper (optional id, double-encoded JSON), and add getSetting() so widget/worker code can do the same for startOfDay. ActivityWatch/aw-android#142
Greptile SummaryThe PR makes Android widget queries load category classes directly from the datastore and adds a JNI settings reader for native widget and worker code.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains. Important Files Changed
Sequence DiagramsequenceDiagram
participant Widget as Android widget
participant JNI as Rust JNI bridge
participant Store as Datastore
participant Query as Android query
Widget->>JNI: androidQuery(...)
JNI->>Store: get settings.classes
Store-->>JNI: Raw JSON value
JNI->>JNI: Parse class rules or use defaults
JNI->>Query: Run canonical query with classes
Query-->>Widget: Categorized activity results
Widget->>JNI: getSetting(key)
JNI->>JNI: settings_datastore_key(key)
JNI->>Store: get settings.key
Store-->>Widget: Raw JSON value or null
Reviews (2): Last reviewed commit: "fix(android): allow dotted keys in getSe..." | Re-trigger Greptile |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #653 +/- ##
==========================================
+ Coverage 70.81% 78.32% +7.51%
==========================================
Files 51 65 +14
Lines 2916 5408 +2492
==========================================
+ Hits 2065 4236 +2171
- Misses 851 1172 +321 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Greptile 4/5: getSetting rejected keys containing '.' while GET /api/0/settings/<key> accepts them, so JNI returned null for values the HTTP API could retrieve. Share settings_datastore_key between the HTTP handler and JNI.
|
@greptileai review |
|
CI-green and mergeable (Greptile 5/5) — waiting only on a maintainer click. This PR is ready to merge, but the bot has pull-only access to this repo and can't self-merge — surfacing it here so it isn't lost. The monitoring loop will stop re-flagging it now that this note is posted. |
Problem
The Android homescreen widget's
androidQuerycategorized events with default category rules even when the user had custom classes. Totals matched the Activity view (same events) but per-category rows did not. That's ActivityWatch/aw-android#142.0xbrayo already called it: "the categorization might be falling back to the default categories when creating a AW client fails." Confirmed.
Cause
androidQueryfetchedsettings.classesover HTTP viaAwClient::new("127.0.0.1", 5600, ...)without an API key. Android enables dashboard API-key auth by default (ensureDashboardApiKey). That GET either:Authorization: Bearer …, orBoth paths logged a warning and silently used
default_classes(). The Activity view (WebView) has the token, so it used the user's custom classes.A third failure mode: parsing used
Vec<aw_models::Class>which requiresid: i32. The webui payload treatsidas optional, so a successful HTTP response could still fail to parse and fall back to defaults.Fix
settings.classesfrom the datastoreandroidQueryalready has. No HTTP, no API key, works when the HTTP server is down.classes_from_settings_str(optionalid, double-encoded JSON from TypeError: e.slice().map is not a function error after updating to version 0.13 activitywatch#1067, empty/null → defaults).getSettingJNI so widget/worker Kotlin can stop hitting unauthenticated HTTP forstartOfDay/aw-notify(follow-up in aw-android).Tests
cargo test -p aw-client-rust --lib classes— 8 passed, including:idare used (not defaults)id+dataparsesFollow-up (aw-android)
This does not ship in the Play build until ActivityWatch/aw-android bumps
aw-server-rust. After merge I'll open that bump plus KotlingetSettingforstartOfDay. Users whose custom classes only live in WebViewlocalStorage(older bundled webui) still need one Settings save — or a localStorage →settings.classesmigration — so the datastore has something to read.Does not close ActivityWatch/aw-android#142 on its own.
Not overlapping with #652
#652 only changes
dirs::db_path/create_configcall sites in this file. This PR is theandroidQueryclass-loading path.