Repository navigation
Update what's kept on the phone in the background - #408
Merged
Merged
Conversation
hatstand
force-pushed
the
claude/project-thread-wugi27-background-sync
branch
from
November 6, 2026 21:24
3a7437b to
602b430
Compare
Store screenshotsFrom run 42298232038, against clementine-it. Left: the store listing of the latest release, v13.12, which shows the dark theme. Right: this pull request, dark and light. |
Base automatically changed from
claude/project-thread-wugi27-sync-updated
to
master
November 6, 2026 21:36
A periodic WorkManager job, SyncWorker, syncs the rules for the last Clementine that synced, at its last address, about every 6 hours. It runs only when Android sees fit for work that can wait: charging, idle, battery and storage not low, and on a network Download over allows. It opens a connection of its own, checks that the Clementine answering is the one the rules are for, syncs through Syncer, and disconnects. When the app is already connected, its connection syncs instead. When Android stops the job, SyncEngine downloads nothing more and keeps what it has, so the next run carries on. A setting under Download over, on by default, turns it off. App sets WorkManager up on first use, as its Configuration.Provider, so it's there in Robolectric tests too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01R2bAq6kZW6eyymkA3zsd4p
hatstand
force-pushed
the
claude/project-thread-wugi27-background-sync
branch
from
November 6, 2026 21:37
602b430 to
62ce939
Compare
hatstand
enabled auto-merge (rebase)
November 6, 2026 21:39
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.

































The second of two PRs for background sync, after #407. Until now, what's kept on the phone only synced while the app was connected to Clementine. Now it's updated in the background too, so music set to Every time I connect stays up to date without opening the app.
When it runs
BackgroundSyncschedulesSyncWorkeras unique periodic work, every 6 hours. It's scheduled at startup and again whenever the setting or Download over changes, withExistingPeriodicWorkPolicy.UPDATEso jobs don't stack. Android runs it only when the phone is in a fit state for work that can wait:UNMETEREDfor Wi‑Fi only,NOT_ROAMINGfor Wi‑Fi and mobile data, andCONNECTEDfor any network. Data Saver keeps background work off the network as well.In practice that's mostly overnight on home Wi‑Fi.
Appis WorkManager'sConfiguration.Provider, and the manifest removes WorkManager's startup initializer, so WorkManager is set up on first use. That also works in Robolectric tests, which don't run startup initializers.What a run does
Syncer.syncNow()).BackgroundConnectionof its own to the last address. This is a plainClementineSimpleConnectionwith no media session, renderer or notification, and it doesn't startClementineService. It waits for Clementine's INFO and checks that it's the Clementine the rules are for and that it syncs. Another Clementine at the same address is left alone.Syncer.syncInBackground, which shares the app's sync slot. So the progress notification and the Kept on this phone rows work as before. A sync asked for while it runs, such as when the app connects, runs after it.success()whatever happened. Clementine not being on is the usual case, so WorkManager waits for the next period rather than retrying.WorkManager stops a worker after 10 minutes.
SyncEnginetakes a newstoppedcheck: once it's true, it downloads nothing more, the rule being synced fails and the rest aren't tried. Everything downloaded so far stays, and the next run carries on.This doesn't run as a
dataSyncforeground service, which the plan suggested for long syncs. That would need a Play Console declaration before the dev builds could be uploaded, and each 10-minute run carries on where the last one stopped anyway. It can come later if long syncs turn out to need it.The setting
"Update kept music in the background", under Download over, on by default. It shows only with the testing features, like the rest of media sync, so there's no release note. The strings have the same English and translator notes as the iOS client's (iOS-Remote#82).
Tests
BackgroundSyncTestcovers:BackgroundConnectionagainst a fake Clementine: it connects and gets a manifest, a wrong code is refused, and nothing is there.SyncEngineTest.aStoppedSyncDownloadsNothingMoreAndKeepsWhatItHas🤖 Generated with Claude Code
https://claude.ai/code/session_01R2bAq6kZW6eyymkA3zsd4p