summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorRebecca Silberstein <silberst@google.com>2016-05-26 09:08:03 -0700
committerRebecca Silberstein <silberst@google.com>2016-06-28 15:51:42 -0700
commit5f0238c0d7b4b037dcb1c397217eb65dcfbf53ce (patch)
treee4c8080f7f1883698d0ac13a740ce93a2ea32f26 /tests
parent9563500603c158373e2ee512c4d451783c104660 (diff)
downloadandroid_frameworks_opt_net_wifi-5f0238c0d7b4b037dcb1c397217eb65dcfbf53ce.tar.gz
android_frameworks_opt_net_wifi-5f0238c0d7b4b037dcb1c397217eb65dcfbf53ce.tar.bz2
android_frameworks_opt_net_wifi-5f0238c0d7b4b037dcb1c397217eb65dcfbf53ce.zip
DO NOT MERGE WifiController: Add CMD_RESET_WIFI command
(cherry-pick from master) Allow WifiController to safely restart the WiFi stack. This will initially be used by the WifiLastResortWatchdog. The CMD_RESET_WIFI message is only handled in the StaEnabledState where it would have been attempting to connect. The process of bringing the wifi back up is handled through the use of the new CMD_RESET_WIFI_CONTINUE command. Tests are also added to verify that the new CMD_RESET_WIFI command is ignored in other states (explicitly tests Emergency mode and AP enabled). BUG: 27856267 Change-Id: I778ccd6f7d555f6ee6abb195c1c16c106c2e66b7
Diffstat (limited to 'tests')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiControllerTest.java119
1 files changed, 119 insertions, 0 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiControllerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiControllerTest.java
index 70f1b5f66..8f1b23e2a 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiControllerTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiControllerTest.java
@@ -22,6 +22,7 @@ import static com.android.server.wifi.WifiController.CMD_AP_STOPPED;
import static com.android.server.wifi.WifiController.CMD_DEVICE_IDLE;
import static com.android.server.wifi.WifiController.CMD_EMERGENCY_CALL_STATE_CHANGED;
import static com.android.server.wifi.WifiController.CMD_EMERGENCY_MODE_CHANGED;
+import static com.android.server.wifi.WifiController.CMD_RESTART_WIFI;
import static com.android.server.wifi.WifiController.CMD_SET_AP;
import static com.android.server.wifi.WifiController.CMD_WIFI_TOGGLED;
@@ -303,4 +304,122 @@ public class WifiControllerTest {
inOrder.verify(mWifiStateMachine).setDriverStart(true);
assertEquals("FullLockHeldState", getCurrentState().getName());
}
+
+ /**
+ * The command to trigger a WiFi reset should not trigger any action by WifiController if we
+ * are not in STA mode.
+ * WiFi is not in connect mode, so any calls to reset the wifi stack due to connection failures
+ * should be ignored.
+ * Create and start WifiController in ApStaDisabledState, send command to restart WiFi
+ * <p>
+ * Expected: WiFiController should not call WifiStateMachine.setSupplicantRunning(false)
+ */
+ @Test
+ public void testRestartWifiStackInApStaDisabledState() throws Exception {
+ // Start a new WifiController with wifi disabled
+ when(mSettingsStore.isAirplaneModeOn()).thenReturn(false);
+ when(mSettingsStore.isWifiToggleEnabled()).thenReturn(false);
+ when(mSettingsStore.isScanAlwaysAvailable()).thenReturn(false);
+
+ when(mContext.getContentResolver()).thenReturn(mock(ContentResolver.class));
+
+ mWifiController = new WifiController(mContext, mWifiStateMachine,
+ mSettingsStore, mWifiLockManager, mLooper.getLooper(), mFacade);
+
+ mWifiController.start();
+ mLooper.dispatchAll();
+
+ reset(mWifiStateMachine);
+ assertEquals("ApStaDisabledState", getCurrentState().getName());
+ mWifiController.sendMessage(CMD_RESTART_WIFI);
+ mLooper.dispatchAll();
+ verifyZeroInteractions(mWifiStateMachine);
+ }
+
+ /**
+ * The command to trigger a WiFi reset should not trigger any action by WifiController if we
+ * are not in STA mode, even if scans are allowed.
+ * WiFi is not in connect mode, so any calls to reset the wifi stack due to connection failures
+ * should be ignored.
+ * Create and start WifiController in StaDisablediWithScanState, send command to restart WiFi
+ * <p>
+ * Expected: WiFiController should not call WifiStateMachine.setSupplicantRunning(false)
+ */
+ @Test
+ public void testRestartWifiStackInStaDisabledWithScanState() throws Exception {
+ reset(mWifiStateMachine);
+ assertEquals("StaDisabledWithScanState", getCurrentState().getName());
+ mWifiController.sendMessage(CMD_RESTART_WIFI);
+ mLooper.dispatchAll();
+ verifyZeroInteractions(mWifiStateMachine);
+ }
+
+ /**
+ * The command to trigger a WiFi reset should trigger a wifi reset in WifiStateMachine through
+ * the WifiStateMachine.setSupplicantRunning(false) call when in STA mode.
+ * WiFi is in connect mode, calls to reset the wifi stack due to connection failures
+ * should trigger a supplicant stop, and subsequently, a driver reload.
+ * Create and start WifiController in DeviceActiveState, send command to restart WiFi
+ * <p>
+ * Expected: WiFiController should call WifiStateMachine.setSupplicantRunning(false),
+ * WifiStateMachine should enter CONNECT_MODE and the wifi driver should be started.
+ */
+ @Test
+ public void testRestartWifiStackInStaEnabledState() throws Exception {
+ enableWifi();
+
+ reset(mWifiStateMachine);
+ assertEquals("DeviceActiveState", getCurrentState().getName());
+ mWifiController.sendMessage(CMD_RESTART_WIFI);
+ mLooper.dispatchAll();
+ InOrder inOrder = inOrder(mWifiStateMachine);
+ inOrder.verify(mWifiStateMachine).setSupplicantRunning(false);
+ inOrder.verify(mWifiStateMachine).setSupplicantRunning(true);
+ inOrder.verify(mWifiStateMachine).setOperationalMode(WifiStateMachine.CONNECT_MODE);
+ inOrder.verify(mWifiStateMachine).setDriverStart(true);
+ assertEquals("DeviceActiveState", getCurrentState().getName());
+ }
+
+ /**
+ * The command to trigger a WiFi reset should not trigger a reset when in ECM mode.
+ * Enable wifi and enter ECM state, send command to restart wifi.
+ * <p>
+ * Expected: The command to trigger a wifi reset should be ignored and we should remain in ECM
+ * mode.
+ */
+ @Test
+ public void testRestartWifiStackDoesNotExitECMMode() throws Exception {
+ enableWifi();
+ assertEquals("DeviceActiveState", getCurrentState().getName());
+ when(mFacade.getConfigWiFiDisableInECBM(mContext)).thenReturn(true);
+
+ mWifiController.sendMessage(CMD_EMERGENCY_CALL_STATE_CHANGED, 1);
+ mLooper.dispatchAll();
+ assertInEcm(true);
+
+ reset(mWifiStateMachine);
+ mWifiController.sendMessage(CMD_RESTART_WIFI);
+ mLooper.dispatchAll();
+ assertInEcm(true);
+ verifyZeroInteractions(mWifiStateMachine);
+ }
+
+ /**
+ * The command to trigger a WiFi reset should not trigger a reset when in AP mode.
+ * Enter AP mode, send command to restart wifi.
+ * <p>
+ * Expected: The command to trigger a wifi reset should be ignored and we should remain in AP
+ * mode.
+ */
+ @Test
+ public void testRestartWifiStackDoesNotExitAPMode() throws Exception {
+ mWifiController.obtainMessage(CMD_SET_AP, 1).sendToTarget();
+ mLooper.dispatchAll();
+ assertEquals("ApEnabledState", getCurrentState().getName());
+
+ reset(mWifiStateMachine);
+ mWifiController.sendMessage(CMD_RESTART_WIFI);
+ mLooper.dispatchAll();
+ verifyZeroInteractions(mWifiStateMachine);
+ }
}