fix(connectivity_plus): Fix connectivity state update on Android when network is lost #2673
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.
Description
Looks like we had an issue with catching connectivity state change on Android device when some network type gets disconnected (by either turning it off or losing signal) for quite some time. I believe that the issue happened due to a race condition after getting
onLost()called.In fact, the note about possible race condition is mentioned in the documentation in a few places:
Cautionsection)This PR contains a fix, which is not really nice, but does its job. The fix itself is adding a 100ms delay to runnable
sendEventin broadcase receiver file.For the usage of Android connectivity APIs in the plugin we don't have much options to create a
NetworkRequestobject, like it is suggested in https://developer.android.com/training/monitoring-device-state/connectivity-status-typeThus, I think we can live with this delay for now. But feel free to correct me if I missed some better option.
Additionally fixed #2671 and removed the method which sends just
Stringas a result, so also reverted my yesterday change from #2668Here is a video on how the example app works now with same test as in #2672 where mobile network switches on and off on the same device with Android 14:
connectivity_fix.mp4
Also tested this fix with other connection types and worked good.
Related Issues
Closes #2672
Closes #2671
Breaking Change
Does your PR require plugin users to manually update their apps to accommodate your change?
!in the title as explained in Conventional Commits).