Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6bfc8887 authored by Irfan Sheriff's avatar Irfan Sheriff
Browse files

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
parent 4bbb1397
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -92,10 +92,12 @@ public class DhcpStateMachine extends StateMachine {
    /* Notification from DHCP state machine post DHCP discovery/renewal. Indicates
     * success/failure */
    public static final int CMD_POST_DHCP_ACTION            = BASE + 5;
    /* Notification from DHCP state machine before quitting */
    public static final int CMD_ON_QUIT                     = BASE + 6;

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

    /* Message.arg1 arguments to CMD_POST_DHCP notification */
    public static final int DHCP_SUCCESS = 1;
@@ -172,6 +174,10 @@ public class DhcpStateMachine extends StateMachine {
        quit();
    }

    protected void onQuitting() {
        mController.sendMessage(CMD_ON_QUIT);
    }

    class DefaultState extends State {
        @Override
        public void exit() {
+3 −3
Original line number Diff line number Diff line
@@ -240,7 +240,7 @@ public class WifiService extends IWifiManager.Stub {
            switch (msg.what) {
                case AsyncChannel.CMD_CHANNEL_HALF_CONNECTED: {
                    if (msg.arg1 == AsyncChannel.STATUS_SUCCESSFUL) {
                        Slog.d(TAG, "New client listening to asynchronous messages");
                        if (DBG) Slog.d(TAG, "New client listening to asynchronous messages");
                        mClients.add((AsyncChannel) msg.obj);
                    } else {
                        Slog.e(TAG, "Client connection failure, error=" + msg.arg1);
@@ -249,9 +249,9 @@ public class WifiService extends IWifiManager.Stub {
                }
                case AsyncChannel.CMD_CHANNEL_DISCONNECTED: {
                    if (msg.arg1 == AsyncChannel.STATUS_SEND_UNSUCCESSFUL) {
                        Slog.d(TAG, "Send failed, client connection lost");
                        if (DBG) Slog.d(TAG, "Send failed, client connection lost");
                    } else {
                        Slog.d(TAG, "Client connection lost with reason: " + msg.arg1);
                        if (DBG) Slog.d(TAG, "Client connection lost with reason: " + msg.arg1);
                    }
                    mClients.remove((AsyncChannel) msg.obj);
                    break;
+11 −5
Original line number Diff line number Diff line
@@ -1672,10 +1672,7 @@ public class WifiStateMachine extends StateMachine {
            /* In case we were in middle of DHCP operation
               restore back powermode */
            handlePostDhcpSetup();

            mDhcpStateMachine.sendMessage(DhcpStateMachine.CMD_STOP_DHCP);
            mDhcpStateMachine.doQuit();
            mDhcpStateMachine = null;
        }

        try {
@@ -1928,6 +1925,9 @@ public class WifiStateMachine extends StateMachine {
                case CMD_CLEAR_SUSPEND_OPTIMIZATIONS:
                case CMD_NO_NETWORKS_PERIODIC_SCAN:
                    break;
                case DhcpStateMachine.CMD_ON_QUIT:
                    mDhcpStateMachine = null;
                    break;
                case CMD_SET_SUSPEND_OPTIMIZATIONS:
                    mSuspendWakeLock.release();
                    break;
@@ -2498,6 +2498,9 @@ public class WifiStateMachine extends StateMachine {

            /* Send any reset commands to supplicant before shutting it down */
            handleNetworkDisconnect();
            if (mDhcpStateMachine != null) {
                mDhcpStateMachine.doQuit();
            }

            if (DBG) log("stopping supplicant");
            if (!mWifiNative.stopSupplicant()) {
@@ -3197,8 +3200,11 @@ public class WifiStateMachine extends StateMachine {

            if (!mWifiConfigStore.isUsingStaticIp(mLastNetworkId)) {
                //start DHCP
                if (mDhcpStateMachine == null) {
                    mDhcpStateMachine = DhcpStateMachine.makeDhcpStateMachine(
                            mContext, WifiStateMachine.this, mInterfaceName);

                }
                mDhcpStateMachine.registerForPreDhcpNotification();
                mDhcpStateMachine.sendMessage(DhcpStateMachine.CMD_START_DHCP);
            } else {