Skip to content

Commit 6bfc888

Browse files
committed
Fix DHCP handling at disconnect/reconnect
Wifi can have a quick disconnection followed by a reconnection. We used to create a new DHCP state machine thread for every new connection and never really waited until it quit after disconnect. This may have lead to situations where repeated disconnect/reconnects resulted in multiple dhcp start calls. We now keep the statemachine after a disconnect and only shut it at supplicant stop. Bug: 6417686 Change-Id: Icf66efdc654be886e3eb46c81f09f8cce536f2f6
1 parent 4bbb139 commit 6bfc888

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

core/java/android/net/DhcpStateMachine.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,12 @@ private enum DhcpAction {
9292
/* Notification from DHCP state machine post DHCP discovery/renewal. Indicates
9393
* success/failure */
9494
public static final int CMD_POST_DHCP_ACTION = BASE + 5;
95+
/* Notification from DHCP state machine before quitting */
96+
public static final int CMD_ON_QUIT = BASE + 6;
9597

9698
/* Command from controller to indicate DHCP discovery/renewal can continue
9799
* after pre DHCP action is complete */
98-
public static final int CMD_PRE_DHCP_ACTION_COMPLETE = BASE + 6;
100+
public static final int CMD_PRE_DHCP_ACTION_COMPLETE = BASE + 7;
99101

100102
/* Message.arg1 arguments to CMD_POST_DHCP notification */
101103
public static final int DHCP_SUCCESS = 1;
@@ -172,6 +174,10 @@ public void doQuit() {
172174
quit();
173175
}
174176

177+
protected void onQuitting() {
178+
mController.sendMessage(CMD_ON_QUIT);
179+
}
180+
175181
class DefaultState extends State {
176182
@Override
177183
public void exit() {

services/java/com/android/server/WifiService.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ public void handleMessage(Message msg) {
240240
switch (msg.what) {
241241
case AsyncChannel.CMD_CHANNEL_HALF_CONNECTED: {
242242
if (msg.arg1 == AsyncChannel.STATUS_SUCCESSFUL) {
243-
Slog.d(TAG, "New client listening to asynchronous messages");
243+
if (DBG) Slog.d(TAG, "New client listening to asynchronous messages");
244244
mClients.add((AsyncChannel) msg.obj);
245245
} else {
246246
Slog.e(TAG, "Client connection failure, error=" + msg.arg1);
@@ -249,9 +249,9 @@ public void handleMessage(Message msg) {
249249
}
250250
case AsyncChannel.CMD_CHANNEL_DISCONNECTED: {
251251
if (msg.arg1 == AsyncChannel.STATUS_SEND_UNSUCCESSFUL) {
252-
Slog.d(TAG, "Send failed, client connection lost");
252+
if (DBG) Slog.d(TAG, "Send failed, client connection lost");
253253
} else {
254-
Slog.d(TAG, "Client connection lost with reason: " + msg.arg1);
254+
if (DBG) Slog.d(TAG, "Client connection lost with reason: " + msg.arg1);
255255
}
256256
mClients.remove((AsyncChannel) msg.obj);
257257
break;

wifi/java/android/net/wifi/WifiStateMachine.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1672,10 +1672,7 @@ private void handleNetworkDisconnect() {
16721672
/* In case we were in middle of DHCP operation
16731673
restore back powermode */
16741674
handlePostDhcpSetup();
1675-
16761675
mDhcpStateMachine.sendMessage(DhcpStateMachine.CMD_STOP_DHCP);
1677-
mDhcpStateMachine.doQuit();
1678-
mDhcpStateMachine = null;
16791676
}
16801677

16811678
try {
@@ -1928,6 +1925,9 @@ public boolean processMessage(Message message) {
19281925
case CMD_CLEAR_SUSPEND_OPTIMIZATIONS:
19291926
case CMD_NO_NETWORKS_PERIODIC_SCAN:
19301927
break;
1928+
case DhcpStateMachine.CMD_ON_QUIT:
1929+
mDhcpStateMachine = null;
1930+
break;
19311931
case CMD_SET_SUSPEND_OPTIMIZATIONS:
19321932
mSuspendWakeLock.release();
19331933
break;
@@ -2498,6 +2498,9 @@ public void enter() {
24982498

24992499
/* Send any reset commands to supplicant before shutting it down */
25002500
handleNetworkDisconnect();
2501+
if (mDhcpStateMachine != null) {
2502+
mDhcpStateMachine.doQuit();
2503+
}
25012504

25022505
if (DBG) log("stopping supplicant");
25032506
if (!mWifiNative.stopSupplicant()) {
@@ -3197,8 +3200,11 @@ public void enter() {
31973200

31983201
if (!mWifiConfigStore.isUsingStaticIp(mLastNetworkId)) {
31993202
//start DHCP
3200-
mDhcpStateMachine = DhcpStateMachine.makeDhcpStateMachine(
3201-
mContext, WifiStateMachine.this, mInterfaceName);
3203+
if (mDhcpStateMachine == null) {
3204+
mDhcpStateMachine = DhcpStateMachine.makeDhcpStateMachine(
3205+
mContext, WifiStateMachine.this, mInterfaceName);
3206+
3207+
}
32023208
mDhcpStateMachine.registerForPreDhcpNotification();
32033209
mDhcpStateMachine.sendMessage(DhcpStateMachine.CMD_START_DHCP);
32043210
} else {

0 commit comments

Comments
 (0)