Skip to content

Handle foreground service start failures#102

Open
xiwangly2 wants to merge 1 commit into
JulianAssmann:masterfrom
xiwangly2:fix/android-fgs-start-failure
Open

Handle foreground service start failures#102
xiwangly2 wants to merge 1 commit into
JulianAssmann:masterfrom
xiwangly2:fix/android-fgs-start-failure

Conversation

@xiwangly2

Copy link
Copy Markdown

#96

Improve Android foreground service lifecycle and error handling

  • Add state tracking to prevent concurrent foreground service start requests and handle start timeouts.
  • Wrap startForeground and startForegroundService in try-catch blocks to prevent unhandled crashes (e.g., SecurityException or RuntimeException) when starting the service fails.
  • Propagate service start failures and timeouts back to Dart via the method channel result.
  • Refactor disableBackgroundExecution to directly call stopService() instead of sending a shutdown intent.
  • Ensure wake and Wi-Fi locks are safely released and nulled out during service cleanup.
  • Update the Dart enableBackgroundExecution method to accurately reflect the native operation's success state rather than assuming it always succeeds.

Verified on Xiaomi 25060RK16C, Android 16 / targetSdk 36: mediaProjection FGS rejection is surfaced as PlatformException(ForegroundServiceStartError) instead of crashing with AndroidRuntime FATAL.

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.

1 participant