WifiStateMachine: ignore disconnect

WifiStateMachine allows tests to inject a disconnect by using the
CMD_DISCONNECT message.  This message is now ignored in the
disconnecting and disconnected states.  This would previously cause a
variety of failures depending on the timing due to the tests calling
disconnect before calling connect.  This caused scans to be cancelled
and tests to fail.

BUG: 30313886
TEST: Created new sl4a tests (still in development) that stress test wifi
startup and connections.  The specific failure is not seen with the
included changes. WiFi framework unit tests also pass.

Change-Id: I143a762f38fe3e4ecaf1be71b21553def3cfb239
diff --git a/service/java/com/android/server/wifi/WifiStateMachine.java b/service/java/com/android/server/wifi/WifiStateMachine.java
index e3ab3bc..200ce67 100644
--- a/service/java/com/android/server/wifi/WifiStateMachine.java
+++ b/service/java/com/android/server/wifi/WifiStateMachine.java
@@ -5667,12 +5667,6 @@
                     replyToMessage(message, message.what,
                             mWifiConfigManager.getMatchingConfig((ScanResult)message.obj));
                     break;
-                /* Do a redundant disconnect without transition */
-                case CMD_DISCONNECT:
-                    mWifiConfigManager.setAndEnableLastSelectedConfiguration
-                            (WifiConfiguration.INVALID_NETWORK_ID);
-                    mWifiNative.disconnect();
-                    break;
                 case CMD_RECONNECT:
                     if (mWifiConnectivityManager != null) {
                         mWifiConnectivityManager.forceConnectivityScan();
@@ -7354,6 +7348,9 @@
                 case CMD_START_SCAN:
                     deferMessage(message);
                     return HANDLED;
+                case CMD_DISCONNECT:
+                    if (DBG) log("Ignore CMD_DISCONNECT when already disconnecting.");
+                    break;
                 case CMD_DISCONNECTING_WATCHDOG_TIMER:
                     if (disconnectingWatchdogCount == message.arg1) {
                         if (DBG) log("disconnecting watchdog! -> disconnect");
@@ -7454,7 +7451,10 @@
                             setAndEnableLastSelectedConfiguration(
                                     WifiConfiguration.INVALID_NETWORK_ID);
                     break;
-                    /* Ignore network disconnect */
+                case CMD_DISCONNECT:
+                    if (DBG) log("Ignore CMD_DISCONNECT when already disconnected.");
+                    break;
+                /* Ignore network disconnect */
                 case WifiMonitor.NETWORK_DISCONNECTION_EVENT:
                     // Interpret this as an L2 connection failure
                     break;