Skip to content

feat(android): migrate unknown hostname#577

Open
0xbrayo wants to merge 2 commits intoActivityWatch:masterfrom
0xbrayo:migrate-hostname-android
Open

feat(android): migrate unknown hostname#577
0xbrayo wants to merge 2 commits intoActivityWatch:masterfrom
0xbrayo:migrate-hostname-android

Conversation

@0xbrayo
Copy link
Copy Markdown
Member

@0xbrayo 0xbrayo commented Mar 26, 2026

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 26, 2026

Codecov Report

❌ Patch coverage is 0% with 50 lines in your changes missing coverage. Please review.
✅ Project coverage is 66.91%. Comparing base (656f3c9) to head (4309887).
⚠️ Report is 39 commits behind head on master.

Files with missing lines Patch % Lines
aw-datastore/src/datastore.rs 0.00% 26 Missing ⚠️
aw-datastore/src/worker.rs 0.00% 24 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #577      +/-   ##
==========================================
- Coverage   70.81%   66.91%   -3.90%     
==========================================
  Files          51       54       +3     
  Lines        2916     3195     +279     
==========================================
+ Hits         2065     2138      +73     
- Misses        851     1057     +206     

☔ 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.

@0xbrayo
Copy link
Copy Markdown
Member Author

0xbrayo commented Mar 28, 2026

@greptile-apps review

@greptile-apps
Copy link
Copy Markdown

greptile-apps bot commented Mar 28, 2026

Greptile Summary

This PR adds a hostname migration feature for Android, allowing buckets previously created with "unknown" or "Unknown" as their hostname to be updated to the device's real hostname. The change threads a new MigrateHostname command from the SQLite layer (DatastoreInstance) up through the worker dispatch loop (DatastoreWorker) to a JNI-exposed entry point callable from the Android/Kotlin side.

Key findings:

  • P1 — JNI symbol name is invalid: Java_net_activitywatch_android_RustInterface_migrate_hostname contains a bare _ in the method-name portion of the mangled symbol. Per the JNI specification, underscores in method names must be encoded as _1; a plain _ is interpreted as the separator between the class name and the method. This will cause a runtime UnsatisfiedLinkError. The name must align with whatever the Kotlin/Java declaration uses — either migrateHostname (→ ...RustInterface_migrateHostname) or migrate_hostname (→ ...RustInterface_migrate_1hostname).
  • P2 — panic! in worker dispatch: An unexpected Response variant produces a thread panic rather than a propagated DatastoreError.
  • P2 — No empty-string guard on the incoming hostname: An empty hostname from the Android side would silently blank-out all previously-unknown buckets.

Confidence Score: 4/5

Not safe to merge until the JNI symbol name is corrected — the entry point will silently fail to link at runtime.

The datastore and worker layers are correctly implemented. The sole blocking issue is in the JNI symbol name, which will prevent the Android side from ever calling the function. Once that is fixed (a one-line rename), the remaining findings are minor P2 quality improvements.

aw-server/src/android/mod.rs — the JNI function symbol name must be corrected before this can be used from Android.

Important Files Changed

Filename Overview
aw-server/src/android/mod.rs Adds JNI entry point for hostname migration; the symbol name uses a plain _ mid-method which violates JNI naming conventions and will cause a runtime link failure.
aw-datastore/src/datastore.rs Adds migrate_hostname SQL UPDATE + in-memory cache refresh; logic is sound — get_stored_buckets overwrites the same bucket keys so the cache stays consistent.
aw-datastore/src/worker.rs Wires MigrateHostname command through the worker dispatch loop and public Datastore API; minor issue: panics on unexpected response variant instead of returning an error.

Sequence Diagram

sequenceDiagram
    participant Android as Android/Kotlin
    participant JNI as JNI (mod.rs)
    participant DS as Datastore (worker.rs)
    participant DSI as DatastoreInstance (datastore.rs)
    participant SQLite as SQLite DB

    Android->>JNI: migrate_hostname(hostname)
    JNI->>DS: migrate_hostname(&hostname)
    DS->>DS: send Command::MigrateHostname(hostname)
    DS->>DSI: migrate_hostname(conn, new_hostname)
    DSI->>SQLite: UPDATE buckets SET hostname=?1 WHERE hostname='unknown' OR hostname='Unknown'
    SQLite-->>DSI: rows_updated (n)
    alt n > 0
        DSI->>SQLite: SELECT * FROM buckets (get_stored_buckets)
        SQLite-->>DSI: fresh bucket rows
        DSI->>DSI: refresh buckets_cache
        DSI-->>DS: Ok(n)
        DS->>DS: self.commit = true
    else n == 0
        DSI-->>DS: Ok(0)
    end
    DS-->>JNI: Response::Count(n)
    JNI-->>Android: "Migrated hostname for N bucket(s)"
Loading

Reviews (1): Last reviewed commit: "feat(android): migrate unknown hostname" | Re-trigger Greptile

@0xbrayo 0xbrayo force-pushed the migrate-hostname-android branch from cf2b78d to 6a16914 Compare March 28, 2026 20:41
@0xbrayo 0xbrayo force-pushed the migrate-hostname-android branch from 6a16914 to 89b8cec Compare March 28, 2026 20:48
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.

Migration of existing databases

1 participant