Stop the dataSync foreground service on Android 15 timeout - #50
Merged
Merged
Conversation
dhruv-dangi-openspace
marked this pull request as ready for review
September 29, 2026 15:24
Android 15 gives an app's dataSync foreground services six hours per day in the background. At the limit the system calls onTimeout and expects stopSelf within a few seconds, or it kills the process with ForegroundServiceDidNotStopInTimeException. WorkManager 2.9 never implemented onTimeout, so every long upload that outlived the budget took the app down. WorkManager 2.10 added the handler: it stops each worker of the timed-out type with STOP_REASON_FOREGROUND_SERVICE_TIMEOUT and stops the service. The stopped workers re-run, setForeground is refused because the budget is spent, and the existing isForegroundStartDenied path carries the upload on without foreground priority until the user opens the app and the budget resets. Bumps androidx.work to 2.12.0, which raises the library's floor to minSdk 24. Ours is 29. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
dhruv-dangi-openspace
force-pushed
the
dhruv/workmanager-2.12
branch
from
September 29, 2026 15:36
b162c83 to
461fe2e
Compare
dmurphy5
approved these changes
Sep 29, 2026
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.
Fixes the top Android crash on Diana 110.3:
ForegroundServiceDidNotStopInTimeException. Sentry DIANA-FT0, 280 users.What breaks
Android 15 gives
dataSyncforeground services six hours per day while the app is in the background. When the budget runs out the system calls the service'sonTimeoutand waits a few seconds forstopSelf. If that never comes, it kills the process. WorkManager 2.9 does not implementonTimeout, so a capture upload that outlives the budget takes the app down. Every event is on Android 15 or newer with the app in the background.What changes
androidx.workgoes from 2.9.1 to 2.12.0. Since 2.10, WorkManager answers the timeout: it stops each worker of the timed-out type withSTOP_REASON_FOREGROUND_SERVICE_TIMEOUTand stops the service. The stopped workers re-run,setForegroundis refused because the budget is spent, andisForegroundStartDeniedalready handles that by continuing the upload without foreground priority. The budget resets when the user opens the app.The library's minSdk floor becomes 24 with this version. Ours is 29.
Not changed
The raw upload worker still retries transport failures with no network constraint, so an offline worker spends the same six hours a real upload would. The worker carries a comment that WorkManager constraints were unreliable, so that stays a separate decision.
Verification
:react-native-background-upload:compileDebugKotlinandtestDebugUnitTestpass locally on the example app, 84 tests. Not run on a device: reproducing needs an upload that sits in the background for six hours on an Android 15 phone.🤖 Generated with Claude Code