Skip to content

fix(android): load embedded server config#608

Merged
ErikBjare merged 2 commits into
ActivityWatch:masterfrom
TimeToBuildBob:bob/android-auth-config
May 21, 2026
Merged

fix(android): load embedded server config#608
ErikBjare merged 2 commits into
ActivityWatch:masterfrom
TimeToBuildBob:bob/android-auth-config

Conversation

@TimeToBuildBob
Copy link
Copy Markdown
Contributor

Summary

  • load the embedded Android server config with create_config(false) instead of starting from AWConfig::default()
  • make Android get_config_dir() return the app data dir so config-backed auth state can actually exist on-device
  • keep device IDs in app data with a corrected comment explaining why

Why

Android auth is still blocked before the aw-android WebView handoff step: the embedded aw-server-rust path currently bypasses config.toml, so [auth].api_key cannot be loaded or persisted on Android at all. This patch fixes that prerequisite and unblocks ActivityWatch/aw-android#145.

Testing

  • cargo test -p aw-server

Notes

I could not run an Android-target build in this environment because only the Linux host target is installed here, so the Android-specific validation still needs device/SDK coverage on the aw-android side.

@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented May 21, 2026

Greptile Summary

This PR fixes Android config loading so that aw-server-rust actually reads config.toml from the on-device app data directory, enabling [auth].api_key to be persisted and loaded on Android. Previously the Android path used AWConfig::default(), bypassing the config file entirely, and get_config_dir() simply panicked.

  • android/mod.rs: switches from AWConfig::default() to create_config(false, None), which reads (and creates if absent) config.toml under ANDROID_DATA_DIR.
  • dirs.rs: get_config_dir() on Android now returns ANDROID_DATA_DIR (the app files dir) instead of panicking, making config and data share the same on-device directory — consistent with how get_data_dir() already behaved.
  • device_id.rs: comment-only update reflecting that get_config_dir() is now available on Android.

Confidence Score: 4/5

Changes are logically correct and narrowly scoped to Android; the Linux/desktop path is entirely unaffected.

All three changes are small and well-reasoned. get_config_dir() on Android no longer panics and create_config correctly creates and reads config.toml in the app data dir. The port override intentionally discards the port value from the config, which is correct for Android but could surprise future maintainers. No logic regressions on the Linux build path, and the Android-specific code compiles with correct argument count and types.

aw-server/src/android/mod.rs is the only file worth a second look since it cannot be exercised by the Linux host build.

Important Files Changed

Filename Overview
aw-server/src/android/mod.rs Replaces AWConfig::default() with create_config(false, None) so Android reads config.toml from the app data dir, enabling auth config (api_key) to be loaded at runtime.
aw-server/src/dirs.rs Android get_config_dir() changed from panic! to returning ANDROID_DATA_DIR, making config/data share the same directory on-device; directory creation is delegated to callers.
aw-server/src/device_id.rs Comment-only change: updates the rationale for using get_data_dir() to reflect that get_config_dir() is now supported on Android.

Sequence Diagram

sequenceDiagram
    participant Android as aw-android JVM
    participant JNI as RustInterface (JNI)
    participant Dirs as dirs.rs
    participant Config as config.rs

    Android->>JNI: initialize()
    Android->>JNI: setDataDir(appFilesDir)
    JNI->>Dirs: set_android_data_dir(path)
    Note over Dirs: ANDROID_DATA_DIR = appFilesDir

    Android->>JNI: startServer()
    JNI->>Config: create_config(false, None)
    Config->>Dirs: get_config_dir()
    Dirs-->>Config: Ok(ANDROID_DATA_DIR)
    Note over Config: resolves to ANDROID_DATA_DIR/config.toml
    Config->>Config: create_dir_all(ANDROID_DATA_DIR)
    Config->>Config: read/write config.toml (incl. [auth].api_key)
    Config-->>JNI: "AWConfig { port, auth, ... }"
    JNI->>JNI: "server_config.port = 5600"
    JNI->>JNI: build_rocket(server_state, server_config)
Loading

Reviews (2): Last reviewed commit: "fix(android): pass missing config_overri..." | Re-trigger Greptile

Comment thread aw-server/src/android/mod.rs Outdated
info!("Using server_state:: device_id: {}", server_state.device_id);

let mut server_config: AWConfig = AWConfig::default();
let mut server_config = crate::config::create_config(false);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P0 create_config has two parameters (testing: bool, config_override: Option<&Path>); the missing None argument for config_override will cause a compile error on any Android-target build, even though Linux cargo test silently skips this #[cfg(target_os = "android")] block.

Suggested change
let mut server_config = crate::config::create_config(false);
let mut server_config = crate::config::create_config(false, None);

@codecov
Copy link
Copy Markdown

codecov Bot commented May 21, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 76.95%. Comparing base (656f3c9) to head (441bd6d).
⚠️ Report is 54 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #608      +/-   ##
==========================================
+ Coverage   70.81%   76.95%   +6.14%     
==========================================
  Files          51       62      +11     
  Lines        2916     4926    +2010     
==========================================
+ Hits         2065     3791    +1726     
- Misses        851     1135     +284     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@TimeToBuildBob
Copy link
Copy Markdown
Contributor Author

fix(android): added missing None to create_config(false, None) — the Android build should now compile.

Thanks @greptile-apps for catching this. The Linux build never exercises the android cfg block so it was invisible in local testing.

@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented May 21, 2026

Makes sense — glad that's sorted. The fix is correct: create_config(false, None) properly threads through the config loading path instead of short-circuiting to defaults, and since the #[cfg(target_os = "android")] block is never compiled on Linux, that kind of signature mismatch is easy to miss locally.

The overall shape of the patch looks good now — get_config_dir() returning ANDROID_DATA_DIR unblocks config persistence, and the corrected comment in device_id.rs is a cleaner explanation of intent. Worth making sure the Android CI (or a manual aw-android device build) covers this path end-to-end to confirm auth key round-trips through config.toml as expected.

Tip: You can customize Greptile's behavior for this repo with .greptile/rules.md and .greptile/config.json.

@TimeToBuildBob
Copy link
Copy Markdown
Contributor Author

Good catch @greptile-apps — the missing None argument was the Android build failure. Fixed in the latest push and Android CI now passes.

@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented May 21, 2026

Thanks for the update! Glad Android CI is green now. The fix sounds straightforward — nothing else to flag on that front.

@TimeToBuildBob
Copy link
Copy Markdown
Contributor Author

Android CI is green and the Greptile compile fix is already in the latest push. This PR is ready to merge, but the TimeToBuildBob account does not have upstream merge permissions on ActivityWatch/aw-server-rust, so it needs a maintainer-side merge.

@ErikBjare ErikBjare merged commit 0c8b2ad into ActivityWatch:master May 21, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants