Skip to content

How to Prevent Foreground Service Crash After Permission Removal on Android #320

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
GiantChipmunk opened this issue Feb 16, 2025 · 0 comments

Comments

@GiantChipmunk
Copy link

GiantChipmunk commented Feb 16, 2025

Issue:
If the user revokes the necessary permissions (e.g., FOREGROUND_SERVICE_HEALTH, ACTIVITY_RECOGNITION) via device settings and then returns to the app, the app crashes with the following error:

java.lang.SecurityException: Starting FGS with type health callerApp=ProcessRecord{...} targetSDK=35 requires permissions: all of the permissions allOf=true [android.permission.FOREGROUND_SERVICE_HEALTH] any of the permissions allOf=false [android.permission.ACTIVITY_RECOGNITION, android.permission.BODY_SENSORS, android.permission.HIGH_SAMPLING_RATE_SENSORS]

Steps to Reproduce:

  1. Start the foreground service in the app.
  2. Go to Settings > Apps > MyApp > Permissions and revoke necessary permissions (ACTIVITY_RECOGNITION, FOREGROUND_SERVICE_HEALTH).
  3. Return to the app.
  4. The app crashes immediately with the error mentioned above.

Is there any way to prevent the app from crashing when the user revokes these permissions while the foreground service is running? Ideally, I would like to catch this scenario and gracefully stop the service before Android forces the crash.

Thank you for your help!

@Dev-hwang Dev-hwang added resolved-pending-release The issue has been resolved, but it hasn't been released yet. and removed resolved-pending-release The issue has been resolved, but it hasn't been released yet. labels Apr 13, 2025
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

No branches or pull requests

2 participants