Wednesday, 25 September 2019

Android WiFi manager network switch when connecting to a configured network

I am seeing some interesting behaviour when dealing with Wifi Manager on latest versions of Android(on Pixel especially). I am trying to make the WIFI manager connect to a known hotspot(IOT appliance).

Google lists the steps clearly in a blog post, if you are on lollipop and above you need to bind to a particular network to make sure your network requests pass through a given network. Can find the steps here https://android-developers.googleblog.com/2016/07/connecting-your-app-to-wifi-device.html

The listed steps work fine in a normal scenario( you search for the access points through a scan and do an add network because this wasn't configured earlier). But if the access point is connected manually from the Wifi list the add network would fail( from Android M and above you are not allowed to change wifi configuration done by another app or the system) and I have to connect to the already configured network. This case always causes a network switch after about 20-30 seconds.

I think this is caused by https://android.googlesource.com/platform/frameworks/base/+/master/services/core/java/com/android/server/connectivity/NetworkAgentInfo.java because Google calls home and checks if the network has internet.

But I could not figure out why this only happens when the network is previously connected from Settings -> Wifi

Sorry for the long-winded post if anyone has any clue why this is happening and if there is any way to prevent it, would really appreciate it. Note that it is not possible to update the wifi configuration on M and above. Also, disable network doesn't help either. Also interestingly this only happens on a pixel but not on a Samsung device(No network agent ?).



from Android WiFi manager network switch when connecting to a configured network

No comments:

Post a Comment