Fix connection status provider exceptions and api inconsistencies#4590
Closed
romtsn wants to merge 2 commits intorz/perf/single-network-callbackfrom
Closed
Conversation
… 26+ Co-authored-by: roman.zavarnitsyn <roman.zavarnitsyn@sentry.io>
Contributor
Instructions and example for changelogPlease add an entry to 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
<pr_request_template>## 📜 Description
This PR addresses two issues in
AndroidConnectionStatusProvider:try-catchblocks around all childNetworkCallbackinvocations (onAvailable,onLost,onCapabilitiesChanged,onUnavailable) to prevent uncaught exceptions from halting the event dispatch loop. Exceptions are now logged as warnings.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:
AndroidConnectionStatusProviderby ensuring that a misbehavingNetworkCallbackdoes not prevent other callbacks from receiving network status updates.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:
onAvailable,onLost,onCapabilitiesChanged, andonUnavailable.onUnavailable()correctly invokes child callbacks on API 26+ devices.onUnavailable()does not invoke child callbacks on API 24-25 devices.onUnavailable()on API 26+.📝 Checklist
sendDefaultPIIis enabled.🔮 Next steps</pr_request_template>
Learn more about Cursor Agents