🧪 Regression Guard: Fix cascading crashes on service stop#694
🧪 Regression Guard: Fix cascading crashes on service stop#694yuga-hashimoto wants to merge 1 commit into
Conversation
Wrap fallback `context.stopService(intent)` calls in try-catch blocks to prevent secondary crashes when cleaning up failed service starts. Co-authored-by: yuga-hashimoto <74749461+yuga-hashimoto@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
Description:
This PR introduces a defensive fix to prevent cascading service cleanup crashes.
Context:
Android imposes strict background execution limits. When a foreground service or standard service fails to start due to these limits (throwing an
IllegalStateExceptionorSecurityException), the app's current error-handling logic catches the exception and attempts a fallback cleanup by callingcontext.stopService(intent).The Bug:
Depending on the Android version and the exact state of the app/intent,
context.stopService(intent)itself can throw an exception (e.g., anotherSecurityExceptionorIllegalArgumentException). When this happens inside thecatchblock of the original startup exception, the unhandled secondary exception causes the entire app to crash, turning a graceful failure into a hard crash.The Fix:
Wrapped the
context.stopService(intent)fallback calls inside nestedtry-catch (e: Exception)blocks inHotwordService,NodeForegroundService, andSessionForegroundService. This ensures that if the cleanup call fails, the exception is safely caught and logged, preventing a fatal crash and allowing the app to degrade gracefully.Verification:
try-catchblocks are syntactically correct and use the standardandroid.util.Log.efor logging../gradlew buildand./gradlew testStandardDebugUnitTest, confirming no compilation regressions.PR created automatically by Jules for task 16455628158932526732 started by @yuga-hashimoto