Skip to content

Fix connection status provider exceptions and api inconsistencies #4590

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

Conversation

romtsn
Copy link
Member

@romtsn romtsn commented Aug 1, 2025

<pr_request_template>## 📜 Description
This PR addresses two issues in AndroidConnectionStatusProvider:

  1. Exception Handling: Added try-catch blocks around all child NetworkCallback invocations (onAvailable, onLost, onCapabilitiesChanged, onUnavailable) to prevent uncaught exceptions from halting the event dispatch loop. Exceptions are now logged as warnings.
  2. API Compatibility: Implemented an API level check within onUnavailable() to ensure child callbacks are only invoked on API 26 (Oreo) and above, aligning with its @RequiresApi(Build.VERSION_CODES.O) annotation and preventing inconsistent behavior on API 24-25 devices.

💡 Motivation and Context

This change is required to:

  • Improve the robustness of the AndroidConnectionStatusProvider by ensuring that a misbehaving NetworkCallback does not prevent other callbacks from receiving network status updates.
  • Resolve an inconsistency where NetworkCallback.onUnavailable() was registered on API 24+ but only invoked by the system on API 26+, leading to unexpected behavior on lower API levels.

💚 How did you test it?

Comprehensive unit tests were added to verify:

  • That exceptions thrown by individual child callbacks do not halt the dispatch loop for onAvailable, onLost, onCapabilitiesChanged, and onUnavailable.
  • That onUnavailable() correctly invokes child callbacks on API 26+ devices.
  • That onUnavailable() does not invoke child callbacks on API 24-25 devices.
  • That exception handling still functions correctly for onUnavailable() on API 26+.

📝 Checklist

  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs if needed.
  • I updated the wizard if needed.
  • Review from the native team if needed.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.

🔮 Next steps</pr_request_template>


Open in Cursor Open in Web

Learn more about Cursor Agents

Copy link
Contributor

github-actions bot commented Aug 1, 2025

Fails
🚫 Please consider adding a changelog entry for the next release.

Instructions and example for changelog

Please add an entry to CHANGELOG.md to the "Unreleased" section. Make sure the entry includes this PR's number.

Example:

## Unreleased

- Fix connection status provider exceptions and api inconsistencies ([#4590](https://github.com/getsentry/sentry-java/pull/4590))

If none of the above apply, you can opt out of this check by adding #skip-changelog to the PR description.

Generated by 🚫 dangerJS against 9e65025

@romtsn romtsn closed this Aug 1, 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

Successfully merging this pull request may close these issues.

3 participants