Skip to content

fix(android): check manifest declaration instead of grant state for FGS permission (fixes #731) - #733

Open
ened wants to merge 1 commit into
mainfrom
fix/issue-731
Open

fix(android): check manifest declaration instead of grant state for FGS permission (fixes #731)#733
ened wants to merge 1 commit into
mainfrom
fix/issue-731

Conversation

@ened

@ened ened commented Aug 17, 2026

Copy link
Copy Markdown
Collaborator

Summary

requireForegroundServicePermission() in ForegroundServiceUtils.kt used PackageManager.checkPermission(), which reports the runtime grant state — not the manifest declaration. On Android 16+, foreground-service permissions can be revoked/denied at runtime even when declared, so the guard false-positived and threw:

expedited work (setExpedited) requires the 'android.permission.FOREGROUND_SERVICE_SHORT_SERVICE' permission in the merged manifest, but it is missing

…even though the merged manifest clearly declares it (see #731).

The guard now checks the merged manifest declaration instead: packageManager.getPackageInfo(packageName, PackageManager.GET_PERMISSIONS).requestedPermissions (the set of declared permissions). The loud IllegalStateException with the same fix hint is kept for genuinely missing declarations.

Behavior matrix after the fix:

Path Manifest state Result
Expedited / shortService FOREGROUND_SERVICE_SHORT_SERVICE declared (plugin default) passes — even if the runtime grant state is DENIED (Android 16+)
dataSync workmanager.enableDataSyncForegroundService=true set (permission declared) passes
dataSync flag not set (permission absent) still throws with the #725 fix hint

Verification

  • ./gradlew :workmanager_android:testDebugUnitTest (via example app, JDK 17): 56 tests, 0 failures — including new tests covering both the declared case (shortService and dataSync) and the missing-declaration case, plus a null-requestedPermissions edge case.
  • -Pworkmanager.enableDataSyncForegroundService=true build: confirmed the plugin swaps in the opt-in manifest and processDebugManifest output then contains FOREGROUND_SERVICE_DATA_SYNC.
  • flutter build apk --debug (example app): builds clean.
  • ktlint 1.7.1 (CI version) on the repo: clean. dart analyze: no issues.

Fixes #731

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.

🐞Exception: expedited work (setExpedited) requires the 'android.permission.FOREGROUND_SERVICE_SHORT_SERVICE'

1 participant