Skip to content

🧪 Regression Guard: Fix cascading crashes on service stop#694

Open
yuga-hashimoto wants to merge 1 commit into
mainfrom
fix/service-cleanup-cascading-crashes-16455628158932526732
Open

🧪 Regression Guard: Fix cascading crashes on service stop#694
yuga-hashimoto wants to merge 1 commit into
mainfrom
fix/service-cleanup-cascading-crashes-16455628158932526732

Conversation

@yuga-hashimoto
Copy link
Copy Markdown
Owner

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 IllegalStateException or SecurityException), the app's current error-handling logic catches the exception and attempts a fallback cleanup by calling context.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., another SecurityException or IllegalArgumentException). When this happens inside the catch block 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 nested try-catch (e: Exception) blocks in HotwordService, NodeForegroundService, and SessionForegroundService. 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:

  • Verified the nested try-catch blocks are syntactically correct and use the standard android.util.Log.e for logging.
  • Ran local builds and unit tests via ./gradlew build and ./gradlew testStandardDebugUnitTest, confirming no compilation regressions.

PR created automatically by Jules for task 16455628158932526732 started by @yuga-hashimoto

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>
@google-labs-jules
Copy link
Copy Markdown
Contributor

👋 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 @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

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