Skip to content

fix(monitor): Prevent crash when OS denies foreground service start#397

Merged
d4rken merged 1 commit intomainfrom
fix/handle-foreground-service-denied
Feb 22, 2026
Merged

fix(monitor): Prevent crash when OS denies foreground service start#397
d4rken merged 1 commit intomainfrom
fix/handle-foreground-service-denied

Conversation

@d4rken
Copy link
Copy Markdown
Member

@d4rken d4rken commented Feb 21, 2026

Summary

  • Add promoteToForeground() helper in MonitorService that catches
    ForegroundServiceStartNotAllowedException (Android 12+) and
    SecurityException from startForeground(), allowing the service
    to exit gracefully instead of crashing
  • Guard onStartCommand() with a foregroundStartFailed flag so
    the service stops with START_NOT_STICKY when promotion was denied
  • Both startForeground() calls (pre-DI and post-DI) now go through
    the same helper to cover OEM edge cases on the second call too
  • Minor: convert createEarlyNotification() builder to apply syntax
    for consistency with the rest of the file

Closes #313

Add promoteToForeground() helper that catches ForegroundServiceStartNotAllowedException
(Android 12+) and SecurityException, allowing graceful service exit instead of crashing.
@d4rken d4rken added the bug Something isn't working label Feb 21, 2026
@d4rken d4rken merged commit 5b59dda into main Feb 22, 2026
9 checks passed
@d4rken d4rken deleted the fix/handle-foreground-service-denied branch February 22, 2026 05:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"Only when connected" mode not working

1 participant