Fix connection status provider exceptions and api inconsistencies #4590
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-catch
blocks around all childNetworkCallback
invocations (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:
AndroidConnectionStatusProvider
by ensuring that a misbehavingNetworkCallback
does 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
sendDefaultPII
is enabled.🔮 Next steps</pr_request_template>
Learn more about Cursor Agents