Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Android 10 support. Testers needed #47

Closed
ThanosFisherman opened this issue Jan 18, 2020 · 53 comments
Closed

Android 10 support. Testers needed #47

ThanosFisherman opened this issue Jan 18, 2020 · 53 comments

Comments

@ThanosFisherman
Copy link
Owner

Please report any connectivity issues related to Android 10 here.

WiFiUtils now has a basic support for Android 10 thanks to the contribution #46 of @eliaslecomte

Hopefully owners of Android 10 devices will help us fix potential bugs.

@AndroidDeveloperLB
Copy link

Does it have a way to connect to Wifi network as I've written here:
#31 (comment)
?
At least via root?

@ThanosFisherman
Copy link
Owner Author

@AndroidDeveloperLB I haven't tried the root way because that's another story that involves some command line arguments plus I'm not even sure if it's gonna work.

The new contribution aims to make this library connect to WiFi networks on Android 10 devices without requiring root but it's not thoroughly tested yet.

@AndroidDeveloperLB
Copy link

@ThanosFisherman Wait you have an idea of what should be done using root?
As for without root, I only know of a "suggestion" API that Google presented. It has various disadvantages:

  1. Not staying forever. If the app is removed, the networks too.
  2. Has some limit of number of networks, though it's a very high limit.
  3. Last time I checked, the API causes a notification to appear, instead of just adding the networks or even show a confirmation dialog to the user to add them. Not only that, but it didn't appear right away. It might have changed since I checked it though.

@eliaslecomte
Copy link
Contributor

That is correct, with the new api (starting Android 10), the wifi internet is only for the app that requested it. I assume the use case is more like connecting to configure IoT devices.

@AndroidDeveloperLB
Copy link

@eliaslecomte Well it's not such a nice alternative to what we had before...

@RussNelson
Copy link

I believe that they're trying to prevent MITM attacks by not allowing an app to connect to a subverted access point. They don't explicitly say that because you never want to give attackers suggestions.

@AndroidDeveloperLB
Copy link

" subverted access point" ?
So it's not about privacy of getting location by knowing the surrounding Wifi networks?

@RussNelson
Copy link

No, that's why an application can't connect without recommending the connection to the user.
The added permissions needed to scan are about getting location by knowing the surrounding WiFi networks. By insisting on both COARSE_LOCATION and FINE_LOCATION, it becomes a moot point that you can look up the location via WiFi. The user has to trust your app with your location because .... you can figure it out on your own.

@AndroidDeveloperLB
Copy link

What I say is that without COARSE_LOCATION and FINE_LOCATION permissions, it's still possible to get a good guess of where you are, so that's why I think they added those into the mix.

@RussNelson
Copy link

Yes, you are quite correct. So rather than leave the user in the dark, they require scanning for WiFi access point to have location permissions. The user gets explicitly asked for that.

@singhal2
Copy link

singhal2 commented Feb 3, 2020

I tried implementing the same in a new project. The phone connects and instantly disconnects to the network, as the OnAvailable method of the NetworkCallback seems to be in a loop. Demo video

@AndroidDeveloperLB
Copy link

@singhal2 Can you please share the source code of this?
Maybe it's a bug on the OS

@eliaslecomte
Copy link
Contributor

I tried implementing the same in a new project. The phone connects and instantly disconnects to the network, as the OnAvailable method of the NetworkCallback seems to be in a loop. Demo video

What network security is used (wpa2?)?
Is it a network with or without internet?

@singhal2
Copy link

singhal2 commented Feb 4, 2020 via email

@AndroidDeveloperLB
Copy link

@singhal2 If you can make it happen even without this library, you should report it to Google:
https://issuetracker.google.com/issues

@singhal2
Copy link

singhal2 commented Feb 10, 2020

Here is the source code I implemented. It contains both the library and standard code to connect to wifi.

https://github.com/singhal2/WifiDemo_AndroidQ

@AndroidDeveloperLB
Copy link

@singhal2 Probably wrong link. Doesn't include Android app project...

@eliaslecomte
Copy link
Contributor

There is a first problem:
/** * Enable or disable Wi-Fi. * <p> * Applications must have the {@link android.Manifest.permission#CHANGE_WIFI_STATE} * permission to toggle wifi. * * @param enabled {@code true} to enable, {@code false} to disable. * @return {@code false} if the request cannot be satisfied; {@code true} indicates that wifi is * either already in the requested state, or in progress toward the requested state. * @throws {@link java.lang.SecurityException} if the caller is missing required permissions. * * @deprecated Starting with Build.VERSION_CODES#Q, applications are not allowed to * enable/disable Wi-Fi. * <b>Compatibility Note:</b> For applications targeting * {@link android.os.Build.VERSION_CODES#Q} or above, this API will always return {@code false} * and will have no effect. If apps are targeting an older SDK ( * {@link android.os.Build.VERSION_CODES#P} or below), they can continue to use this API. */ @Deprecated public boolean setWifiEnabled(boolean enabled) { try { return mService.setWifiEnabled(mContext.getOpPackageName(), enabled); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } }

setWifiEnabled always returns false. I didn't have this at first, not sure if this is due to an sdk patch update?

@AndroidDeveloperLB
Copy link

@eliaslecomte You mean this:

https://developer.android.com/reference/android/net/wifi/WifiManager.html#setWifiEnabled(boolean)

This method was deprecated in API level 29.
Starting with Build.VERSION_CODES#Q, applications are not allowed to enable/disable Wi-Fi. Compatibility Note: For applications targeting Build.VERSION_CODES.Q or above, this API will always return false and will have no effect. If apps are targeting an older SDK ( Build.VERSION_CODES.P or below), they can continue to use this API.

You can't normally toggle Wifi using this permission anymore. Maybe via other workarounds (root, being system app, etc...).

@eliaslecomte
Copy link
Contributor

eliaslecomte commented Feb 13, 2020

Yes, but also, startScan returns false starting Android 10 if you request ACCESS_COARSE_LOCATION. Will have to add a description for that.

As documented here: https://developer.android.com/guide/topics/connectivity/wifi-scan

@AndroidDeveloperLB
Copy link

@eliaslecomte I hope you figure it out. Such a mess has become of Android API. Too many restrictions, that sometimes even the docs don't help.

@ljbatwh
Copy link

ljbatwh commented Apr 22, 2020

Based on Wifitutils 1.5.1, I have tested on XiaoMi Mix2 (android 10). It can connect to a WIFI of IoT(can not access the internet). but the IP looks wired. after I add connctionManager.bindProcessToNetwork, it works.

But to support disconnect from that WIFI, I need to pass out the networkCallback used in connectivityManager.requestNetwork(request, networkCallback) when connecting to wifi.

I did not see there is any interface can do that. so I create a Pull Request on react-native-wifi-reborn
Is anyone familiar with WifiUtils could give a review to see how to do those changes on WifiUtils? @ThanosFisherman

@ThanosFisherman
Copy link
Owner Author

@ljbatwh The latest version (1.6.0) of WifiUtils includes support for disconnecting of wifi networks. Please take a look at MainActivity to see how disconnection works and do some testing on your Xiaomi because I do not own an android 10 device yet.

@ljbatwh
Copy link

ljbatwh commented Apr 23, 2020

@ThanosFisherman thanks. the 1.6.0 can connect and disconnect wifi on my android 10 (XiaoMi Mix2)
but there two issues.

  1. I need to add connectivityManager.bindProcessToNetwork(network) after the connected.
    Else, it can not access another device on the network.
    networkCallback = new ConnectivityManager.NetworkCallback() {
          @Override
          public void onAvailable(@NonNull Network network) {
              super.onAvailable(network);
              **connectivityManager.bindProcessToNetwork(network);**
              wifiLog("AndroidQ+ connected to wifi ");
          }

          @Override
          public void onUnavailable() {
              super.onUnavailable();

              wifiLog("AndroidQ+ could not connect to wifi");
          }
      };
  1. the multicast package can not be received. But if I connect the Wifi by manual, the multicast worked.

@eliaslecomte
Copy link
Contributor

eliaslecomte commented May 1, 2020

@ljbatwh I've added the bindProcessToNetwork() again(it was also in 1.5.0 but I wrongly assumed it wasn't needed because my IoT device does not have internet) in this pr: #66.

I would assume multicast works. I am also using https://github.com/tradle/react-native-udp and this works after connecting with bindProcessToNetwork().

@NizarETH
Copy link

NizarETH commented Aug 2, 2020

@ThanosFisherman I tried multiple time, I debug my a lot of code too, so the scope of internet access is limited inside the app, If you leave the app which you trigger the connection to a hotspot, then, you will not have internet access.
thank's

@eliaslecomte
Copy link
Contributor

@ThanosFisherman I tried multiple time, I debug my a lot of code too, so the scope of internet access is limited inside the app, If you leave the app which you trigger the connection to a hotspot, then, you will not have internet access.
thank's

Yes this is actually normal behavior. Since Android 10, Android has blocked the previous api's to manipulate wifi configuration entries. There are 2 new api's. The first (which is currently used by WifiUtils) is used for IoT commissioning. The app that uses it can execute api calls to the wireless access point. Only that app, and the wifi network is not persisted for the smartphone to use. There is also a wifi suggestion api in Android. You might have need to have a look at that.

@mas1515
Copy link

mas1515 commented Aug 7, 2020

@eliaslecomte
I test library with android 10
my device is
samsung a50s

and sample
doesnt work at all .

what is solution ??? how use library with android 10 ???

@super0610
Copy link

Hi @ThanosFisherman
Thanks for providing great library.
I was trying to use this library to connect with iOT devices.
Below Android 9, it works well, but with android 10 it doesn't work.

If i provide correct password, then it connected and I save this password.
After I change wifi password manually, and retry to connect (at this moment, the saved password is different with current password), it is failed (Didn't connect to wifi authentication_error_occurred)

After that, even the correct password doesn't works, always showing above Log.

what can i do?

remove(SSID, callback) function is forgetting previous configuration in Android 10?, if not how???

Hope any one can give me answer asap.

@eliaslecomte
Copy link
Contributor

@eliaslecomte
I test library with android 10
my device is
samsung a50s

and sample
doesnt work at all .

what is solution ??? how use library with android 10 ???

Did you maybe edit the MainActivity? This file is no longer used, you should edit the MainKotlinActivity for testing purposes.

@eliaslecomte
Copy link
Contributor

Hi @ThanosFisherman
Thanks for providing great library.
I was trying to use this library to connect with iOT devices.
Below Android 9, it works well, but with android 10 it doesn't work.

If i provide correct password, then it connected and I save this password.
After I change wifi password manually, and retry to connect (at this moment, the saved password is different with current password), it is failed (Didn't connect to wifi authentication_error_occurred)

After that, even the correct password doesn't works, always showing above Log.

what can i do?

remove(SSID, callback) function is forgetting previous configuration in Android 10?, if not how???

Hope any one can give me answer asap.

If changing password / reconnecting doesn't work you will have to debug. I think it will be a phone firmware issue rather than something WifiUtils can fix.

@super0610
Copy link

Thanks @eliaslecomte
Let me try to explain again. (lets think any credential is not saved in wifi settings)

  • if i use correct password, then app connect to wifi.
  • if i use wrong password, we get "Didn't connect to wifi authentication_error_occurred", i think it is correct.
  • after this, i can't connect to wifi even with correct password, always show above log message.

it will work again if i go to wifi settings and forgot that wifi.
Please let me know if this is still firmware issue? or when try to connect to wifi in android 10, some credential info is saved in wifi configuration?
as i asked above, remove function will not remove previous configuration in android 10? since am going to call this function before trying connect.

Hope your kind reply, Thanks.

@super0610
Copy link

PS; the password is changed correctly in Firmware, if i fresh wifi and try changed password, it works.
if i use wrong password again, then it will stop working even i use correct password.

@eliaslecomte
Copy link
Contributor

Is your app targetting Android 10? If that's the case it's not actually saving the wifi configuration. You can only Disconnect in wifi settings but it's never saved in the first place. I would call the remote method first.

@super0610
Copy link

super0610 commented Sep 10, 2020

min sdk version is 23, targetSDK version is 29

@ThanosFisherman
Copy link
Owner Author

ThanosFisherman commented Sep 10, 2020

Regarding the sample I did some cleanups, migrated to .kts gradle scripts, renamed the MainKotlinActivity into MainActivity and removed the old Java MainActivity. The sample should work as is. Just make sure you are using the latest Android Studio Version (CC @mas1515 )

@super0610 Seems like another restriction (or probably a bug on Android OS itself). You say that if you manually forget the network then WifiUtils are able to reconnect with the new password. Please Try the following:

  • Make sure the hotspot you are trying to connect to is not previously saved in the device. If it is then manually forget it from the Settings
  • Open the sample and try to connect with the current password (This step should work fine)
  • Now change the HotSpot password via your router firmware
  • Launch the sample again and choose REMOVE - Let me know at this point if the network is actually removed from the Settings
  • Modify the Wifi password in sample code to the new one and rerun the sample
  • Turn off and back on your device's wifi (just in case there is a glitch or something)
  • Try to connect again with the new password - Let me know what happens at this point

@super0610
Copy link

super0610 commented Sep 10, 2020

Thanks for your reply @ThanosFisherman
Yes, I am using latest Android Studio, and latest WifiUtils library (1.6.3)
I will check this in few hours and share here.
Best Regards.,

@super0610
Copy link

hi @ThanosFisherman
I tested with the Sample, but the sample doesn't work.
I tried same credential for the wifi, forget wifl from settings.
Tested several times, but sample didn't work, and our app works with same credential.

@super0610
Copy link

in Android 7, sample works.
in Android 10 (mine is Samsung SM-T290 tablet), it doesn't (Timeout)

@ThanosFisherman
Copy link
Owner Author

Thanks for the update @super0610 I'm not sure yet what might be wrong or if this is an intended behavior. I'll try to investigate it and post back.

@super0610
Copy link

Thanks @ThanosFisherman
I will wait good news, and i can test in my side if needed.

@eliaslecomte
Copy link
Contributor

I'm not having a Samsung SM-T290, so I can't help on this one. If you could do any more debugging @super0610 that would be awesome.

@heetparkhiya
Copy link

Getting Error COULD_NOT_SCAN in android 10 when connecting to local hotspot created with specific ssid and password

@taddcrockett
Copy link

taddcrockett commented Oct 28, 2020

Getting Error COULD_NOT_SCAN in android 10 when connecting to local hotspot created with specific ssid and password

Same here. Galaxy S20 connecting to a device that doesn't have an internet connection with a specific ssid and password.

edit: could be an S20 specific issue. I am able to connect to the same WiFi network using Google Pixel 4a on AN10

edit 2: location was turned off on the S20. Turned it on and was able to connect

@OneupLee
Copy link

I have found an application and it can easily connect to wifi on android 10 device.But I don't know how it work.
my device: realme x2 android 10 & teclast p20hd android 10
google play: https://play.google.com/store/apps/details?id=com.halo.wifikey.wifilocating&hl=en
web site: https://en.wifi.com/

@hayuki
Copy link

hayuki commented Nov 16, 2020

About enabling/disabling Wifi through the library on Android 10 (and up) - I think because of the OS restrictions that have been put in place the best option would be to invoke a Settings panel:

val panelIntent = Intent(Settings.Panel.ACTION_WIFI)
startActivityForResult(panelIntent, WIFI_REQUEST)

What do you think?

@eliaslecomte
Copy link
Contributor

About enabling/disabling Wifi through the library on Android 10 (and up) - I think because of the OS restrictions that have been put in place the best option would be to invoke a Settings panel:

val panelIntent = Intent(Settings.Panel.ACTION_WIFI)
startActivityForResult(panelIntent, WIFI_REQUEST)

What do you think?

This is logic you want to add in your app :-). The library indicates wifi is off. You show this 'error state' and the user has to take action. You can add a button that then opens the Settings screen.

Repository owner deleted a comment from AndroidDeveloperLB May 3, 2021
@ansuman87
Copy link

I tried it on my Android 10 device and I get zero scanResults.

@ThanosFisherman ThanosFisherman unpinned this issue Jun 10, 2022
Repository owner locked and limited conversation to collaborators Jun 10, 2022
@ThanosFisherman ThanosFisherman converted this issue into discussion #128 Jun 10, 2022

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Projects
None yet
Development

No branches or pull requests