devstepbcn / react-native-android-wifi

A react-native module for viewing and connecting to Wifi networks on Android devices.
ISC License
212 stars 121 forks source link

Don't request special permissions on SDK 24+ when calling forceWifiUsage #72

Closed bondparkerbond closed 5 years ago

bondparkerbond commented 5 years ago

The advanced permission Modify System Settings is only needed to force wifi usage on Android version 6.0.0. On SDK 24+, normal permissions that we already use in this app that don't require user approval are sufficient for forcing wifi usage. Taking a user to an advanced permission page and forcing an unneeded permission to perform something already allowed is a bad user experience. For more information, please see:

https://stackoverflow.com/questions/32185628/connectivitymanager-requestnetwork-in-android-6-0#answer-33509180 "...no longer needed in Android 6.0.1. WRITE_SETTING and CHANGE_NETWORK_STATE are no longer the same thing" "This was an Android 6.0 bug. It's fixed in Android 6.0.1, requestNetwork() can be called if you request CHANGE_NETWORK_STATE in the manifest. No need to call requestPermissions(), it's a normal permission." "UPDATE: as of Android 6.0.1, CHANGE_NETWORK_STATE is auto granted when requested in your manifest file. The above WRITE_SETTINGS checks are only required for 6.0"

Note: We could also specify Build.VERSION.RELEASE to get the bug fix version number and only request this permission in 6.0.0, as 6.0.1 should follow 7+ behavior, but I only have Android devices with Android 7-9 to test and figured a simpler fix now would solve the problem for most users.

bondparkerbond commented 5 years ago

I have tested this fix with an Essential Phone on 7.1.1, Pixel XL on 8.0.0, and a Pixel 3 on Android 9.

bondparkerbond commented 5 years ago

This fixes Issue #73 .

devstepbcn commented 5 years ago

Thank you @bondparkerbond !