feat(sync): add SyncSettingsActivity — enable/disable toggle + SAF directory picker - #204
Open
TimeToBuildBob wants to merge 6 commits into
Open
feat(sync): add SyncSettingsActivity — enable/disable toggle + SAF directory picker#204TimeToBuildBob wants to merge 6 commits into
TimeToBuildBob wants to merge 6 commits into
Conversation
…tory picker - Add SAF URI storage to AWPreferences (getSyncDirUri/setSyncDirUri) so the chosen directory persists across reboots with granted content:// permissions - Add SyncSettingsActivity: enable/disable toggle backed by AWPreferences.setSyncEnabled(), plus ACTION_OPEN_DOCUMENT_TREE directory picker that takes persistable URI permission and displays the chosen directory name via DocumentsContract - Add activity_sync_settings.xml layout following the AuthSettingsActivity pattern - Register SyncSettingsActivity in AndroidManifest.xml - Add "Sync Settings" item to the options menu, wired in MainActivity Phase 1: UI infrastructure only. The native aw-sync library still writes to the internal scoped directory via AW_SYNC_DIR. Phase 2 will add file-copy bridging from the internal dir to the SAF-granted location (or a DocumentFile-based I/O rewrite) once the permissions and preference plumbing is confirmed working. Closes ActivityWatch#203
Greptile SummaryAdds a native sync-settings screen and supporting preference/service wiring.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains. Important Files Changed
Sequence DiagramsequenceDiagram
actor User
participant Settings as SyncSettingsActivity
participant Prefs as AWPreferences
participant Service as BackgroundService
participant Scheduler as SyncScheduler
participant SAF as Android SAF
User->>Settings: Toggle sync
Settings->>Prefs: Persist enabled state
Settings->>Service: ACTION_SYNC_ENABLED_CHANGED
Service->>Scheduler: Start or stop
User->>Settings: Choose directory
Settings->>SAF: ACTION_OPEN_DOCUMENT_TREE
SAF-->>Settings: Tree URI and granted modes
Settings->>SAF: Persist new URI permission
Settings->>SAF: Release different old URI permission
Settings->>Prefs: Store selected URI
Reviews (5): Last reviewed commit: "fix(sync): preserve grant when reselecti..." | Re-trigger Greptile |
P1: Toggle leaves scheduler state stale - Add ACTION_SYNC_ENABLED_CHANGED to BackgroundService; handle in onStartCommand to start/stop the running SyncScheduler immediately, without a service restart. - SyncSettingsActivity sends this Intent when the toggle changes. P1: Persisting ungranted URI modes crashes - Only pass flag bits the provider actually granted (from result.data?.flags) to takePersistableUriPermission(); wrap in try-catch for providers that still decline. P2: Replaced directories retain stale grants - Release the old URI's persistable permission before granting the new one, so stale grants don't accumulate against Android's bounded allowance.
Contributor
Author
|
@greptileai review |
…nit guard Two P1 findings from re-review: 1. BackgroundService: ACTION_SYNC_ENABLED_CHANGED skips full initialization when Android kills and recreates the service while SyncSettingsActivity is open. Guard with `isFullyStarted` flag (set at end of normal onStartCommand) so the toggle only short-circuits on an already-running service instance. 2. SyncSettingsActivity: old URI grant released before new one confirmed, and URI saved as success even when takePersistableUriPermission fails. Fix: take the new grant first; abort early with error toast on failure; only then release the old grant and commit the new URI.
Contributor
Author
|
@greptileai review |
… flags When ACTION_OPEN_DOCUMENT_TREE returns a URI with no READ or WRITE flags in persistable mode, the previous commit's zero-flag branch skipped the permission take but still fell through to release the old grant and save the new URI as success. After the transient access expires, the directory is inaccessible. Fix: explicit early-return + error toast when persistableFlags == 0, leaving the old grant and URI intact. Also simplify the flow so takePersistableUriPermission is now unconditional (persistableFlags is always nonzero at that point), with its SecurityException still aborting before the old grant is released.
Contributor
Author
|
@greptileai review |
Contributor
Author
|
@greptileai review |
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. |
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.
Summary
Follow-up to #203 (filed in ActivityWatch/activitywatch#1357) and the sync-disabled-by-default PR (#184). Adds the user-facing sync settings screen.
What this adds:
SyncSettingsActivity: enable/disable toggle +ACTION_OPEN_DOCUMENT_TREEdirectory pickerAWPreferences:getSyncDirUri/setSyncDirUrito persist the user-chosen SAF URI with persistable permissions across rebootsactivity_sync_settings.xmllayoutHow it works:
AWPreferences.isSyncEnabled())ACTION_OPEN_DOCUMENT_TREE— the user picks any folder their sync tool (Syncthing, Dropbox, etc.) can seecontentResolver.takePersistableUriPermission()so it survives rebootsPhase 1 scope: This PR wires up the UI and preference plumbing. The native
aw-synclibrary continues writing to the internal scoped directory viaAW_SYNC_DIR. Phase 2 will bridge the internal sync dir to the SAF-granted location (file-copy orDocumentFile-based I/O rewrite) once the permissions infrastructure is confirmed working on real devices.APIs used: All API 26+ (minSdkVersion 26 confirmed), including
DocumentsContract.EXTRA_INITIAL_URIfor suggesting a sensible starting location.Test plan
takePersistableUriPermission)Relates to ActivityWatch/activitywatch#1357 (@ErikBjare approved: "approved, go")