fix(android): make FOREGROUND_SERVICE_DATA_SYNC opt-in (fixes #725) - #726
Merged
Conversation
The plugin always declared FOREGROUND_SERVICE_DATA_SYNC and merged the dataSync type onto SystemForegroundService, forcing Play Console to ask every app for a dataSync foreground-service declaration + demonstration video — even apps that only run plain periodic background tasks. dataSync is now opt-in: the default manifest declares only FOREGROUND_SERVICE + FOREGROUND_SERVICE_SHORT_SERVICE (expedited work, not a Play special type). Apps running long-running workers with the dataSync type enable it via the workmanager.enableDataSyncForegroundService Gradle property, which swaps in AndroidManifest.dataSync.xml (permission + dataSync|shortService type). Verified with aapt2 dump on the final APK: default has no DATA_SYNC permission, opt-in has permission + type 0x801 (dataSync|shortService). 50 unit tests pass.
Runtime guard in resolveForegroundServiceType: when a worker requests the dataSync foreground service type but FOREGROUND_SERVICE_DATA_SYNC is not in the merged manifest (the app did not set workmanager.enableDataSyncForegroundService=true), throw a descriptive IllegalStateException instead of a cryptic SecurityException on Android 14+ when the service starts. shortService (always declared) is unaffected. Adds ForegroundServicePermissionTest (Robolectric): dataSync without the permission throws; shortService builds with the shortService type.
Collaborator
Author
|
Added a runtime guard per your idea: if a worker requests |
Expedited work runs as a shortService FGS on Android 14+, which needs FOREGROUND_SERVICE_SHORT_SERVICE in the merged manifest. The plugin declares it by default, but if an app strips it, fail at registration with a descriptive error instead of a SecurityException at task time. Shared requireForegroundServicePermission helper (also used by the dataSync guard). Note: the SDK stubs expose no Manifest.permission constant for SHORT_SERVICE — the manifest literal string is used.
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 #725 — the plugin always declared
FOREGROUND_SERVICE_DATA_SYNCand merged thedataSynctype ontoSystemForegroundService, so Play Console demanded a dataSync foreground-service declaration + demonstration video from every app — even those that only run plain periodic background tasks.Change
FOREGROUND_SERVICE+FOREGROUND_SERVICE_SHORT_SERVICE(expedited work needs shortService; it is not a Play special type).dataSyncis opt-in: setworkmanager.enableDataSyncForegroundService=truein gradle.properties (or-Pon the CLI) and the build swaps inAndroidManifest.dataSync.xml(adds the permission +dataSync|shortServiceservice type).ForegroundServiceConfig/ long-running workers).Verification (aapt2 dump permissions on the built APK)
-Pworkmanager.enableDataSyncForegroundService=trueUnit tests: 50/50 pass.