Android: How to prevent Wi-Fi tearing on DHCP renewal?

We are developing software on a custom Android platform and we are starting to receive complaints from customers about the state of the Wi-Fi connection. It seems that from time to time they lose the Wifi connection for 1-2 seconds and then come back automatically. They can notice this from a little GUI feedback or from the disconnect / reconnect event issued by the XMPP client.

After researching, we found from the log adb logcat

that Wifi changes its state from CONNECTED

to CONNECTING

every time a DHCP update occurs. Since we currently have a DHCP lease of 1 hour, our platform tries to renew its address every 29 minutes. Here is an excerpt from the DHCP update log:

[ 11-24 10:10:11.751  2629: 3350 D/DhcpStateMachine ]
DHCP renewal on wlan0

[ 11-24 10:10:12.351  2629: 3350 D/DhcpStateMachine ]
DHCP succeeded on wlan0

[ 11-24 10:10:12.361  2877: 2877 D/DCT      ]
onReceive: action=android.net.wifi.STATE_CHANGE

[ 11-24 10:10:12.361  2877: 2877 D/DCT      ]
NETWORK_STATE_CHANGED_ACTION: mIsWifiConnected=false

[ 11-24 10:10:12.361  2877: 2877 D/DCT      ]
NETWORK_STATE_CHANGED_ACTION: networkInfo=NetworkInfo: type: WIFI[], state: CONNECTING/VERIFYING_POOR_LINK, reason: (unspecified), extra: "XXX", roaming: false, failover: false, isAvailable: true

[ 11-24 10:10:12.371  2877: 2877 D/DCT      ]
onReceive: action=android.net.wifi.STATE_CHANGE

[ 11-24 10:10:12.371  2877: 2877 D/DCT      ]
NETWORK_STATE_CHANGED_ACTION: mIsWifiConnected=false

[ 11-24 10:10:12.371  2877: 2877 D/DCT      ]
NETWORK_STATE_CHANGED_ACTION: networkInfo=NetworkInfo: type: WIFI[], state: CONNECTING/CAPTIVE_PORTAL_CHECK, reason: (unspecified), extra: "XXX", roaming: false, failover: false, isAvailable: true

[ 11-24 10:10:12.381  2877: 2877 D/DCT      ]
onReceive: action=android.net.wifi.STATE_CHANGE

[ 11-24 10:10:12.381  2877: 2877 D/DCT      ]
NETWORK_STATE_CHANGED_ACTION: mIsWifiConnected=true

[ 11-24 10:10:12.381  2877: 2877 D/DCT      ]
NETWORK_STATE_CHANGED_ACTION: networkInfo=NetworkInfo: type: WIFI[], state: CONNECTED/CONNECTED, reason: (unspecified), extra: "XXX", roaming: false, failover: false, isAvailable: true

      

How can I prevent the connection state from changing from CONNECTED

to CONNECTING

when using DHCP? Can I change the setting somewhere to change this behavior?

+3


source to share


1 answer


I don’t think it DISCONNECTING

can really be avoided. The only way to solve this problem is to ignore the state DISCONNECTING

in the Wifi change state and use the isConnectedOrConnecting

from method Network

instead isConnected

to check if we are connected or not.



0


source







All Articles