-
Notifications
You must be signed in to change notification settings - Fork 392
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
fix(android): isConnected is wrong incorrect for wifi networks only the app has access to #443
fix(android): isConnected is wrong incorrect for wifi networks only the app has access to #443
Conversation
…networks that are available to the app but not the system. Using registerNetworkCallback fixes this.
I'm no expert on the matter. I've read this post https://proandroiddev.com/connectivity-network-internet-state-change-on-android-10-and-above-311fb761925 before experimenting with the registerDefaultNetworkCallback / registerNetworkCallback to find out that fixes this issue. |
## [6.0.1](v6.0.0...v6.0.1) (2021-08-24) ### Bug Fixes * Ensure warnings are not shown on React Native 0.65 ([#487](#487) by [@lubomyr](https://github.com/lubomyr)) ([ac0ed65](ac0ed65)) * **android:** isConnected is incorrect for wifi networks only the app has access to ([#443](#443) by [@eliaslecomte](https://github.com/eliaslecomte)) ([7084771](7084771))
🎉 This PR is included in version 6.0.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This may have a regression as noted in #496 but that issue report has no details (yet), just cross-linking them via this comment. |
… the app has access to (react-native-netinfo#443 by @eliaslecomte)" This reverts commit 7084771.
… the app has access to (react-native-netinfo#443 by @eliaslecomte)" This reverts commit 7084771.
… the app has access to (react-native-netinfo#443 by @eliaslecomte)" This reverts commit 7084771.
It is with deep sadness that I must say we merged #571 which means the underlying issue here will be reopened. This was painful but the regressions from this could not be ignored, and reverting this seemed like it would cause less trouble than leaving it in, though I/we recognize this is still a problem. Please see #571 for discussion |
6.0.1版本,修改NetworkCallbackConnectivityReceiver文件: |
Overview
Use registerNetworkCallback instead of registerDefaultNetworkCallback as the default method isn't notified of wifi network changes that are available to the app but not the system / other apps.
Issue
When I use react-native-wifi-reborn to connect with an IoT wifi network (for commissioning), and I use
fetch
, netinfo returns the correct network information. However theisConnected
isfalse
and the eventListener isn't notified of the change.After debugging the code I noticed that the ConnectivityNetworkCallback was never invoked for the new wifi network.
To me it looks like the registerDefaultNetworkCallback only notifies for wifi networks that are available system-wide, while the registerNetworkCallback also for wifi networks that are only available to the app.
Looking at the Android sdk this is what is executed for registerDefaultNetworkCallback:
While registerNetworkCallback:
The default networkcapabilities are:
Looking at the code the issue is that when fetching wifi data, the WifiManager is used to fetch fields like ssid, bssid, frequency, ... . The isConnected indicates false because the variable mConnectionType is actually
NONE
. Also, important to notice is, that if you have a mobile connection, it's actually true if that connection is active.Related issues
none
for no internet wifi connections. #411Test Plan
Running a simple test; connect via react-native-wifi-reborn to a wifi network, call
Netinfo.fetch()
and see if wifi details + isConnected are correct.Also checking if NetInfo.addEventListener is updated of the change.
Currently tested on: