Skip to content

fix(android): migrate aw-watcher-android-test buckets on startup - #244

Open
TimeToBuildBob wants to merge 1 commit into
ActivityWatch:masterfrom
TimeToBuildBob:fix/merge-legacy-android-bucket
Open

fix(android): migrate aw-watcher-android-test buckets on startup#244
TimeToBuildBob wants to merge 1 commit into
ActivityWatch:masterfrom
TimeToBuildBob:fix/merge-legacy-android-bucket

Conversation

@TimeToBuildBob

Copy link
Copy Markdown
Contributor

Summary

aw-server-rust#628 added migrateWatcherAndroidBucketNames(), but BackgroundService never called it. Upgrades from pre-rename builds keep writing/reading aw-watcher-android-test_* history that the Activity view no longer queries (#243).

This PR:

  1. Declares the JNI and calls it during startup, after hostname migration so bucket IDs are stable first.
  2. Guards with hasMigratedWatcherAndroidBucketNames. Completes the preference only when no aw-watcher-android-test* buckets remain. Collision leftovers retry on the next start instead of being marked done forever.
  3. Extracts naming/completion rules into WatcherAndroidBucketMigration with JVM unit tests.

What this does not do

The current aw-server-rust submodule pin still uses UPDATE OR IGNORE. If both the legacy and canonical buckets exist, the rename is skipped. The SQL merge for that collision case is ActivityWatch/aw-server-rust#661. After that merges, bump this submodule — the Kotlin leftover check already matches the new merge (including partial overlap leftovers).

I did not bump the submodule in this PR: the merge commit is not yet on ActivityWatch/aw-server-rust, so a SHA bump would break CI checkout.

Tests

  • WatcherAndroidBucketMigrationTest (canonical ID, leftover detection, success-prefix parsing)
  • Datastore merge tests live on the rust PR

Refs

The server-side rename from aw-server-rust#628 never ran because
BackgroundService only called migrateHostname(). Wire the JNI and
mark the preference complete only when no aw-watcher-android-test*
buckets remain, so a collision leftover retries on the next start.

Collision merge itself is ActivityWatch/aw-server-rust#661; this PR
does not bump the submodule, so the current pin still rename-only
skips the both-buckets-exist case.

Refs: ActivityWatch#149, ActivityWatch#150,
ActivityWatch#243
@greptile-apps

greptile-apps Bot commented Aug 27, 2026

Copy link
Copy Markdown

Greptile Summary

The PR invokes the existing native Android watcher-bucket migration during background-service startup and records completion only after confirming that no legacy bucket IDs remain.

  • Adds a durable preference flag for successful migration completion.
  • Runs hostname and watcher-bucket migrations on an I/O coroutine during service startup.
  • Declares the native migration method and extracts bucket naming and completion rules.
  • Adds JVM tests for canonical naming, legacy detection, completion, and native success parsing.

Confidence Score: 5/5

The PR appears safe to merge, with no concrete blocking or independently actionable non-blocking defects identified.

The startup path invokes the migration off the main thread, preserves retries after native failures or collision leftovers, and marks completion only after the legacy bucket prefix is absent.

Important Files Changed

Filename Overview
mobile/src/main/java/net/activitywatch/android/BackgroundService.kt Adds asynchronous startup orchestration for the native watcher-bucket migration, retrying failures and collision leftovers.
mobile/src/main/java/net/activitywatch/android/AWPreferences.kt Adds the durable completion marker that prevents rerunning a successfully completed watcher-bucket migration.
mobile/src/main/java/net/activitywatch/android/RustInterface.kt Declares the Kotlin JNI entry point for the existing native watcher-bucket migration.
mobile/src/main/java/net/activitywatch/android/WatcherAndroidBucketMigration.kt Encapsulates legacy ID recognition, canonicalization, native success parsing, and completion criteria.
mobile/src/test/java/net/activitywatch/android/WatcherAndroidBucketMigrationTest.kt Covers the extracted migration naming, filtering, completion, and success-response rules.

Sequence Diagram

sequenceDiagram
    participant OS as Android
    participant Service as BackgroundService
    participant Prefs as AWPreferences
    participant Native as RustInterface
    OS->>Service: Start or recreate service
    Service->>Native: startServerTask()
    Service->>Prefs: Read migration flags
    opt Hostname migration pending
        Service->>Native: migrateHostname(deviceName)
        Native-->>Service: Migration result
        Service->>Prefs: Mark hostname migrated on success
    end
    opt Watcher bucket migration pending
        Service->>Native: migrateWatcherAndroidBucketNames()
        Native-->>Service: Migration result
        Service->>Native: getBucketsJSON()
        alt No legacy bucket IDs remain
            Service->>Prefs: Mark watcher migration complete
        else Legacy bucket IDs remain
            Service->>Service: Log and retry next startup
        end
    end
Loading

Reviews (1): Last reviewed commit: "fix(android): call migrateWatcherAndroid..." | Re-trigger Greptile

@TimeToBuildBob

Copy link
Copy Markdown
Contributor Author

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.

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.

1 participant