summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNingyuan Wang <nywang@google.com>2017-09-18 13:33:36 -0700
committerNingyuan Wang <nywang@google.com>2017-10-04 18:07:05 -0700
commit98842059a66adb61a1f27fd56d92c80a77066e83 (patch)
treecf1f68e03b1288c42334d857a7f7be41610bfb07
parent470817b13e56d915805729ab4f51075f3fa2ec15 (diff)
Do not trigger scan for reconnect() when wifi is connected
According to the document of WifiManager.reconnect(), we only try to connect when wifi is disconnected. This CL adds the handling of CMD_RECONNECT in WifiStateMachine for L2ConnectedState to avoid unnecessary scans and connection attempts. This also adds the handling of CMD_RECONNECT for WpsRunningState, which just logs and ignores this command because in WpsRunningSate we are attempting to connect and when we leave and head to disconnected state, we will trigger a scan anyway. Bug: 65839442 Test: compile, unit tests Test: 1. Write a simple cts test case WifiManagerTest#testWifiReconnect only calling WifiManager.reconnect() 2. Make sure wifi is connected 3. Run cts test using: cts-tradefed run cts -m CtsNetTestCases -t android.net.wifi.cts.WifiManagerTest#testWifiReconnect 4. Grab bugreport 5. Verify the following log appears: "Ignore CMD_RECONNECT request because wifi is already connected" Change-Id: I7aa7842653aa4eaf8d70946dc8e120d3814ffc09
-rw-r--r--service/java/com/android/server/wifi/WifiStateMachine.java5
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java29
2 files changed, 34 insertions, 0 deletions
diff --git a/service/java/com/android/server/wifi/WifiStateMachine.java b/service/java/com/android/server/wifi/WifiStateMachine.java
index d6723cac3..1f6cada74 100644
--- a/service/java/com/android/server/wifi/WifiStateMachine.java
+++ b/service/java/com/android/server/wifi/WifiStateMachine.java
@@ -5995,6 +5995,9 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss
case CMD_STOP_RSSI_MONITORING_OFFLOAD:
stopRssiMonitoringOffload();
break;
+ case CMD_RECONNECT:
+ log(" Ignore CMD_RECONNECT request because wifi is already connected");
+ break;
case CMD_RESET_SIM_NETWORKS:
if (message.arg1 == 0 // sim was removed
&& mLastNetworkId != WifiConfiguration.INVALID_NETWORK_ID) {
@@ -6847,6 +6850,8 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss
case WifiManager.CONNECT_NETWORK:
case CMD_ENABLE_NETWORK:
case CMD_RECONNECT:
+ log(" Ignore CMD_RECONNECT request because wps is running");
+ return HANDLED;
case CMD_REASSOCIATE:
deferMessage(message);
break;
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java
index ecb4c959c..29590afec 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java
@@ -2354,6 +2354,35 @@ public class WifiStateMachineTest {
}
/**
+ * Test that reconnectCommand() triggers connectivity scan when WifiStateMachine
+ * is in DisconnectedMode.
+ */
+ @Test
+ public void testReconnectCommandWhenDisconnected() throws Exception {
+ // Connect to network with |sBSSID|, |sFreq|, and then disconnect.
+ disconnect();
+
+ mWsm.reconnectCommand(WifiStateMachine.WIFI_WORK_SOURCE);
+ mLooper.dispatchAll();
+ verify(mWifiConnectivityManager).forceConnectivityScan(WifiStateMachine.WIFI_WORK_SOURCE);
+ }
+
+ /**
+ * Test that reconnectCommand() doesn't trigger connectivity scan when WifiStateMachine
+ * is in ConnectedMode.
+ */
+ @Test
+ public void testReconnectCommandWhenConnected() throws Exception {
+ // Connect to network with |sBSSID|, |sFreq|.
+ connect();
+
+ mWsm.reconnectCommand(WifiStateMachine.WIFI_WORK_SOURCE);
+ mLooper.dispatchAll();
+ verify(mWifiConnectivityManager, never())
+ .forceConnectivityScan(WifiStateMachine.WIFI_WORK_SOURCE);
+ }
+
+ /**
* Adds the network without putting WifiStateMachine into ConnectMode.
*/
@Test