We are developing software on a custom Android platform and we begin to receive complaints from customers about the state of the Wifi connection. It seems that once in a while, they loose their Wifi connection for 1-2 seconds and then it comes back automatically. They can notice this from a small GUI feedback or from a disconnect/reconnect event issued from an XMPP client.
After investigation, we found from the log in adb logcat
that the Wifi is changing its state from CONNECTED
to CONNECTING
every time there is a DHCP renewal. As we currently have a DHCP lease time of 1 hour, our platform tries to renew its address every 29 minutes. Here is a log excerpt from a DHCP renewal :
[ 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 could I prevent the connection state to change from CONNECTED
to CONNECTING
while using DHCP ? Can I change a setting somewhere to change this behaviour ?
I don't think the
DISCONNECTING
can be really avoided. The only way to deal with this issue is ignoring theDISCONNECTING
state on a Wifi change state and to use theisConnectedOrConnecting
method fromNetwork
instead ofisConnected
to verify if we are connected or not.