particle-iot / particle-android

Particle Open Source for Android
Apache License 2.0
37 stars 38 forks source link

Device setup: Phone - device Wi-Fi connection failure. #96

Open IgnacioBasallote opened 4 years ago

IgnacioBasallote commented 4 years ago

Hi,

I have an issue in the "Choose your XX device" screen during the device setup. When I select the device network to connect my phone into it, the app pops up the progress dialog, but it will never leave this screen. I have been going through your code to see what is causing this problem and finally, I figured out that the phone is connecting/disconnecting until the variable discoverProcessAttempts reaches "MAX_NUM_DISCOVER_PROCESS_ATTEMPTS". Then, the phone gets blocked on this screen.

This effect is caused by the phone itself. In this case, the phone detects that the device network does not have an internet connection and then, the phone decides to connect to any other registered existing network that really does. If one explicitly disables all the registered existing Wi-Fi networks, this problem vanishes.

So, having a look in your code from the version (io.particle:devicesetup:0.6.3), I found that you are using the WifiConfiguration class and the priority field, which is set to 999999 giving maximum priority to device's network (ApConnector.java). However, I have seen that this field is deprecated (https://developer.android.com/reference/android/net/wifi/WifiConfiguration.html#priority).

Could the problem be here perhaps? Maybe the phone does not really prioritize the device's network after all and that's why it is connecting/disconnecting all the time.

This issue happens on a Xiaomi Mi 9T.

I am looking forward to your response.

Thanks in advance! Nacho

jensck commented 4 years ago

This effect is caused by the phone itself. In this case, the phone detects that the device network does not have an internet connection and then, the phone decides to connect to any other registered existing network that really does. If one explicitly disables all the registered existing Wi-Fi networks, this problem vanishes.

We already disable the network we're currently connected to. Disabling all networks is an option I suppose (I'm guessing one would actually have to disable just the registered networks currently in range), but that seems like it runs a high risk of side effects and would require a good amount of testing. As such, I can't give any kind of timeline for fixing this right now.

antoniovazquezblanco commented 4 years ago

Disabling all the networks is not a very efficient solution. The problem resides in the fact that android API for network preference has changed. The priority field is no longer used and deprecated (in fact, the whole WifiConfiguration class is). We have found the issue above in various phones from various manufacturers due to changes in Android and not due to changes made by manufacturers. From Android 8 onwards, wpa_supplicant is responsible for setting WiFi network priorities and unless the new network API is used, the device setup library will be facing this bug.

Independently of the issue of wpa_supplicant changing the selected network, I think it is important to be able to show an error to the user when this situation takes place, otherwise, the user will be forever waiting in a screen with a infinite progressbar that cannot cancel.

Thank you @jensck for the support!

StemyEnergy commented 4 years ago

Hi,

Having the same issue with a Samsung Galaxy S9 with Android 10. The app is not able to connect to the device's WiFi. The phone remains connected to the WiFi network it was connected before starting the configuration process.

After a couple of minutes, the app prompts an error dialog which lets you retry the process.

Thanks in advance for your help!

Desdaemon commented 2 years ago

Chiming in, this is a blocker on my Oppo Reno running Android 11 and Google Pixel 3 running Android 12 as well.