-
Notifications
You must be signed in to change notification settings - Fork 207
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
Use NetworkCallback to monitor connectivity changes on newer API levels #501
Conversation
🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉
…ing for mocking in unit tests
…lowing for mocking in unit test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Verified that reports are cached then automatically flushed when a device is put into airplane mode, on API 27 + API 22 physical devices, and that device.networkStatus is populated correctly.
I did this same manual check on API 29 and API 26.
Read through the code and mostly understood it. Looks sensible. Yay for Kotlin!
Pass tests by cleaning up `Client` instantiations
Goal
We rely on the
ConnectivityManager
to detect whether or not we have a network connection. This allows us to save battery by avoiding unnecessary radio use when there is no available connection.Several APIs in
NetworkInfo
(returned byConnectivityManager
) have been deprecated when targeting API 28 - namelyisConnectedOrConnecting()
, andgetType()
which sets thedevice.networkStatus
field.This changeset refactors the notifier to use modern APIs where possible, and otherwise falls back to the legacy behaviour on API < N.
This PR also adds Kotlin as a dependency to the bugsnag-android artefact.
Changeset
allWarningsAsErrors
for Kotlin compilation, which fails the build when using deprecated codeConnectivity
interface that encapsulates all methods related to network stateConnectivityCompat
shim that forwards method calls onto the modern or legacy implementation, dependent on API levelWithin the
Connectivity
implementations:BroadcastReceiver
to listen to network changes on API < N, and aNetworkCallback
otherwisenetworkInfo.type
to get network state on API < N, andactiveNetwork
otherwiseTests
Verified that reports are cached then automatically flushed when a device is put into airplane mode, on API 27 + API 22 physical devices, and that
device.networkStatus
is populated correctly.Note: the unit tests currently fail locally due to many client objects being created. The fix for this is implemented in #503.