summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRebecca Silberstein <silberst@google.com>2018-03-19 23:51:54 -0700
committerRebecca Silberstein <silberst@google.com>2018-03-30 16:22:06 -0700
commit4e1c7af3e5b47bc8f53e92aa25047c5ca03238ce (patch)
tree774446c0bebb1651f6076c42d3ffa860a5fc17ed /tests
parentc4002658545b95d0f7f1686e925072518416a78e (diff)
WifiStateMachine: onDown triggers wifi off
When the underlying sta interface in Client Mode gets an onDown callback, notify SelfRecovery if MacRandomization isn't enabled. We do expect onDown to happen with MacRandomization, so we don't want to restart/disable client mode... because we would disable wifi and never connect. This CL additionally adds a check to get the interface state after creation. This fixes the issue where WSM does not know the interface is up before a connection. This CL triggers SelfRecovery with a new reason code. Also added unit tests. Due to b/72459123, supplicant reports of iface down are still handled. Bug: 75989180 Bug: 75991970 Test: frameworks/opt/net/wifi/tests/wifitests/runtests.sh Test: 'adb shell ifconfig wlan0 down' when connected, confirm wifi disables Test: 'adb shell ifconfig wlan0 down' when disconnected, confirm wifi disables Test: removed config while connected to the network does not disable wifi Test: removed config while disconnected does not disable wifi Change-Id: Ifb7fc5289ed7f029ed02f6ce21d7b71710992501
Diffstat (limited to 'tests')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/SelfRecoveryTest.java58
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiControllerTest.java43
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java119
3 files changed, 196 insertions, 24 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/SelfRecoveryTest.java b/tests/wifitests/src/com/android/server/wifi/SelfRecoveryTest.java
index c8dafdd69..0d9137ac3 100644
--- a/tests/wifitests/src/com/android/server/wifi/SelfRecoveryTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/SelfRecoveryTest.java
@@ -47,13 +47,13 @@ public class SelfRecoveryTest {
@Test
public void testValidTriggerReasonsSendMessageToWifiController() {
mSelfRecovery.trigger(SelfRecovery.REASON_LAST_RESORT_WATCHDOG);
- verify(mWifiController).sendMessage(eq(WifiController.CMD_RESTART_WIFI), anyInt());
+ verify(mWifiController).sendMessage(eq(WifiController.CMD_RECOVERY_RESTART_WIFI), anyInt());
reset(mWifiController);
when(mClock.getElapsedSinceBootMillis())
.thenReturn(SelfRecovery.MAX_RESTARTS_TIME_WINDOW_MILLIS + 1);
mSelfRecovery.trigger(SelfRecovery.REASON_WIFINATIVE_FAILURE);
- verify(mWifiController).sendMessage(eq(WifiController.CMD_RESTART_WIFI), anyInt());
+ verify(mWifiController).sendMessage(eq(WifiController.CMD_RECOVERY_RESTART_WIFI), anyInt());
reset(mWifiController);
}
@@ -71,6 +71,15 @@ public class SelfRecoveryTest {
}
/**
+ * Verifies that a STA interface down event will trigger WifiController to disable wifi.
+ */
+ @Test
+ public void testStaIfaceDownDisablesWifi() {
+ mSelfRecovery.trigger(SelfRecovery.REASON_STA_IFACE_DOWN);
+ verify(mWifiController).sendMessage(eq(WifiController.CMD_RECOVERY_DISABLE_WIFI));
+ }
+
+ /**
* Verifies that invocations of {@link SelfRecovery#trigger(int)} for REASON_HAL_CRASH &
* REASON_WIFICOND_CRASH are limited to {@link SelfRecovery#MAX_RESTARTS_IN_TIME_WINDOW} in a
* {@link SelfRecovery#MAX_RESTARTS_TIME_WINDOW_MILLIS} millisecond time window.
@@ -82,46 +91,55 @@ public class SelfRecoveryTest {
// aren't ignored
for (int i = 0; i < SelfRecovery.MAX_RESTARTS_IN_TIME_WINDOW / 2; i++) {
mSelfRecovery.trigger(SelfRecovery.REASON_WIFINATIVE_FAILURE);
- verify(mWifiController).sendMessage(eq(WifiController.CMD_RESTART_WIFI), anyInt());
+ verify(mWifiController).sendMessage(eq(WifiController.CMD_RECOVERY_RESTART_WIFI),
+ anyInt());
reset(mWifiController);
mSelfRecovery.trigger(SelfRecovery.REASON_WIFINATIVE_FAILURE);
- verify(mWifiController).sendMessage(eq(WifiController.CMD_RESTART_WIFI), anyInt());
+ verify(mWifiController).sendMessage(eq(WifiController.CMD_RECOVERY_RESTART_WIFI),
+ anyInt());
reset(mWifiController);
}
if ((SelfRecovery.MAX_RESTARTS_IN_TIME_WINDOW % 2) == 1) {
mSelfRecovery.trigger(SelfRecovery.REASON_WIFINATIVE_FAILURE);
- verify(mWifiController).sendMessage(eq(WifiController.CMD_RESTART_WIFI), anyInt());
+ verify(mWifiController).sendMessage(eq(WifiController.CMD_RECOVERY_RESTART_WIFI),
+ anyInt());
reset(mWifiController);
}
// Verify that further attempts to trigger restarts for are ignored
mSelfRecovery.trigger(SelfRecovery.REASON_WIFINATIVE_FAILURE);
- verify(mWifiController, never()).sendMessage(eq(WifiController.CMD_RESTART_WIFI),
+ verify(mWifiController, never()).sendMessage(eq(WifiController.CMD_RECOVERY_RESTART_WIFI),
anyString());
reset(mWifiController);
mSelfRecovery.trigger(SelfRecovery.REASON_WIFINATIVE_FAILURE);
- verify(mWifiController, never()).sendMessage(eq(WifiController.CMD_RESTART_WIFI),
+ verify(mWifiController, never()).sendMessage(eq(WifiController.CMD_RECOVERY_RESTART_WIFI),
anyString());
reset(mWifiController);
// Verify L.R.Watchdog can still restart things (It has its own complex limiter)
mSelfRecovery.trigger(SelfRecovery.REASON_LAST_RESORT_WATCHDOG);
- verify(mWifiController).sendMessage(eq(WifiController.CMD_RESTART_WIFI), anyInt());
+ verify(mWifiController).sendMessage(eq(WifiController.CMD_RECOVERY_RESTART_WIFI),
+ anyInt());
+ reset(mWifiController);
+
+ // Verify Sta Interface Down will still disable wifi
+ mSelfRecovery.trigger(SelfRecovery.REASON_STA_IFACE_DOWN);
+ verify(mWifiController).sendMessage(eq(WifiController.CMD_RECOVERY_DISABLE_WIFI));
reset(mWifiController);
// now TRAVEL FORWARDS IN TIME and ensure that more restarts can occur
when(mClock.getElapsedSinceBootMillis())
.thenReturn(SelfRecovery.MAX_RESTARTS_TIME_WINDOW_MILLIS + 1);
mSelfRecovery.trigger(SelfRecovery.REASON_LAST_RESORT_WATCHDOG);
- verify(mWifiController).sendMessage(eq(WifiController.CMD_RESTART_WIFI), anyInt());
+ verify(mWifiController).sendMessage(eq(WifiController.CMD_RECOVERY_RESTART_WIFI), anyInt());
reset(mWifiController);
when(mClock.getElapsedSinceBootMillis())
.thenReturn(SelfRecovery.MAX_RESTARTS_TIME_WINDOW_MILLIS + 1);
mSelfRecovery.trigger(SelfRecovery.REASON_WIFINATIVE_FAILURE);
- verify(mWifiController).sendMessage(eq(WifiController.CMD_RESTART_WIFI), anyInt());
+ verify(mWifiController).sendMessage(eq(WifiController.CMD_RECOVERY_RESTART_WIFI), anyInt());
reset(mWifiController);
}
@@ -136,7 +154,25 @@ public class SelfRecoveryTest {
for (int i = 0; i < SelfRecovery.MAX_RESTARTS_IN_TIME_WINDOW * 2; i++) {
// Verify L.R.Watchdog can still restart things (It has it's own complex limiter)
mSelfRecovery.trigger(SelfRecovery.REASON_LAST_RESORT_WATCHDOG);
- verify(mWifiController).sendMessage(eq(WifiController.CMD_RESTART_WIFI), anyInt());
+ verify(mWifiController).sendMessage(eq(WifiController.CMD_RECOVERY_RESTART_WIFI),
+ anyInt());
+ reset(mWifiController);
+ }
+ }
+
+ /**
+ * Verifies that invocations of {@link SelfRecovery#trigger(int)} for
+ * REASON_STA_IFACE_DOWN are NOT limited to
+ * {@link SelfRecovery#MAX_RESTARTS_IN_TIME_WINDOW} in a
+ * {@link SelfRecovery#MAX_RESTARTS_TIME_WINDOW_MILLIS} millisecond time window.
+ */
+ @Test
+ public void testTimeWindowLimiting_staIfaceDown_noEffect() {
+ for (int i = 0; i < SelfRecovery.MAX_RESTARTS_IN_TIME_WINDOW * 2; i++) {
+ mSelfRecovery.trigger(SelfRecovery.REASON_STA_IFACE_DOWN);
+ verify(mWifiController).sendMessage(eq(WifiController.CMD_RECOVERY_DISABLE_WIFI));
+ verify(mWifiController, never())
+ .sendMessage(eq(WifiController.CMD_RECOVERY_RESTART_WIFI), anyInt());
reset(mWifiController);
}
}
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiControllerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiControllerTest.java
index 50be8e44b..279fb670b 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiControllerTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiControllerTest.java
@@ -19,7 +19,8 @@ package com.android.server.wifi;
import static com.android.server.wifi.WifiController.CMD_AP_STOPPED;
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_RECOVERY_DISABLE_WIFI;
+import static com.android.server.wifi.WifiController.CMD_RECOVERY_RESTART_WIFI;
import static com.android.server.wifi.WifiController.CMD_SCAN_ALWAYS_MODE_CHANGED;
import static com.android.server.wifi.WifiController.CMD_SET_AP;
import static com.android.server.wifi.WifiController.CMD_WIFI_TOGGLED;
@@ -402,7 +403,8 @@ public class WifiControllerTest {
@Test
public void testRestartWifiStackInStaEnabledStateTriggersBugReport() throws Exception {
enableWifi();
- mWifiController.sendMessage(CMD_RESTART_WIFI, SelfRecovery.REASON_WIFINATIVE_FAILURE);
+ mWifiController.sendMessage(CMD_RECOVERY_RESTART_WIFI,
+ SelfRecovery.REASON_WIFINATIVE_FAILURE);
mLooper.dispatchAll();
verify(mWifiStateMachine).takeBugReport(anyString(), anyString());
}
@@ -410,12 +412,37 @@ public class WifiControllerTest {
@Test
public void testRestartWifiWatchdogDoesNotTriggerBugReport() throws Exception {
enableWifi();
- mWifiController.sendMessage(CMD_RESTART_WIFI, SelfRecovery.REASON_LAST_RESORT_WATCHDOG);
+ mWifiController.sendMessage(CMD_RECOVERY_RESTART_WIFI,
+ SelfRecovery.REASON_LAST_RESORT_WATCHDOG);
mLooper.dispatchAll();
verify(mWifiStateMachine, never()).takeBugReport(anyString(), anyString());
}
/**
+ * When in sta mode, CMD_RECOVERY_DISABLE_WIFI messages should trigger wifi to disable.
+ */
+ @Test
+ public void testRecoveryDisabledTurnsWifiOff() throws Exception {
+ enableWifi();
+ reset(mWifiStateMachine);
+ mWifiController.sendMessage(CMD_RECOVERY_DISABLE_WIFI);
+ mLooper.dispatchAll();
+ verify(mWifiStateMachine).setOperationalMode(WifiStateMachine.DISABLED_MODE);
+ }
+
+ /**
+ * When wifi is disabled, CMD_RECOVERY_DISABLE_WIFI should not trigger a state change.
+ */
+ @Test
+ public void testRecoveryDisabledWhenWifiAlreadyOff() throws Exception {
+ reset(mWifiStateMachine, mWifiStateMachinePrime);
+ assertEquals("StaDisabledWithScanState", getCurrentState().getName());
+ mWifiController.sendMessage(CMD_RECOVERY_DISABLE_WIFI);
+ mLooper.dispatchAll();
+ verifyZeroInteractions(mWifiStateMachine, mWifiStateMachinePrime);
+ }
+
+ /**
* 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
@@ -439,7 +466,7 @@ public class WifiControllerTest {
reset(mWifiStateMachine);
assertEquals("ApStaDisabledState", getCurrentState().getName());
- mWifiController.sendMessage(CMD_RESTART_WIFI);
+ mWifiController.sendMessage(CMD_RECOVERY_RESTART_WIFI);
mLooper.dispatchAll();
verifyZeroInteractions(mWifiStateMachine);
}
@@ -457,7 +484,7 @@ public class WifiControllerTest {
public void testRestartWifiStackInStaDisabledWithScanState() throws Exception {
reset(mWifiStateMachine);
assertEquals("StaDisabledWithScanState", getCurrentState().getName());
- mWifiController.sendMessage(CMD_RESTART_WIFI);
+ mWifiController.sendMessage(CMD_RECOVERY_RESTART_WIFI);
mLooper.dispatchAll();
verifyZeroInteractions(mWifiStateMachine);
}
@@ -478,7 +505,7 @@ public class WifiControllerTest {
reset(mWifiStateMachine);
assertEquals("DeviceActiveState", getCurrentState().getName());
- mWifiController.sendMessage(CMD_RESTART_WIFI);
+ mWifiController.sendMessage(CMD_RECOVERY_RESTART_WIFI);
mLooper.dispatchAll();
InOrder inOrder = inOrder(mWifiStateMachine);
inOrder.verify(mWifiStateMachine).setOperationalMode(WifiStateMachine.CONNECT_MODE);
@@ -503,7 +530,7 @@ public class WifiControllerTest {
assertInEcm(true);
reset(mWifiStateMachine);
- mWifiController.sendMessage(CMD_RESTART_WIFI);
+ mWifiController.sendMessage(CMD_RECOVERY_RESTART_WIFI);
mLooper.dispatchAll();
assertInEcm(true);
verifyZeroInteractions(mWifiStateMachine);
@@ -524,7 +551,7 @@ public class WifiControllerTest {
assertEquals("ApEnabledState", getCurrentState().getName());
reset(mWifiStateMachine);
- mWifiController.sendMessage(CMD_RESTART_WIFI);
+ mWifiController.sendMessage(CMD_RECOVERY_RESTART_WIFI);
mLooper.dispatchAll();
verifyZeroInteractions(mWifiStateMachine);
verify(mWifiStateMachinePrime, never()).disableWifi();
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java
index cf6ff8e53..0889f677c 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java
@@ -1776,18 +1776,127 @@ public class WifiStateMachineTest {
}
/**
- * Test verifying that interface onDown callbacks are not currently hooked up.
+ * Test verifying that interface onDown callback triggers SelfRecovery when Supplicant has
+ * already reported the driver is not active.
*/
@Test
- public void testInterfaceOnDownDoesNotTriggerClientModeShutdown() throws Exception {
- connect();
+ public void testInterfaceOnDownInClientModeTriggersSelfRecovery() throws Exception {
+ // Trigger initialize to capture the death handler registration.
+ loadComponentsInStaMode();
+
+ // make sure we mark the iface up
+ mInterfaceCallbackCaptor.getValue().onUp(WIFI_IFACE_NAME);
+
+ // make sure supplicant has been reported as inactive
+ when(mWifiNative.isInterfaceUp(eq(WIFI_IFACE_NAME))).thenReturn(true);
+ mWsm.sendMessage(WifiMonitor.SUPPLICANT_STATE_CHANGE_EVENT, 0, 0,
+ new StateChangeResult(0, WifiSsid.createFromAsciiEncoded(""), null,
+ SupplicantState.INTERFACE_DISABLED));
+ mLooper.dispatchAll();
// trigger onDown for the client interface
mInterfaceCallbackCaptor.getValue().onDown(WIFI_IFACE_NAME);
mLooper.dispatchAll();
- // since this is not handled yet, should not trigger a disconnect
- assertEquals("ConnectedState", getCurrentState().getName());
+ // WSM should trigger self recovery, but not disconnect until externally triggered
+ verify(mSelfRecovery).trigger(eq(SelfRecovery.REASON_STA_IFACE_DOWN));
+ }
+
+ /**
+ * Test verifying that interface onDown callback does not trigger SelfRecovery when
+ * Supplicant reports that the driver is active.
+ */
+ @Test
+ public void testInterfaceOnDownInClientModeDoesNotTriggerSelfRecoveryIfDriverActive()
+ throws Exception {
+ // Trigger initialize to capture the death handler registration.
+ loadComponentsInStaMode();
+
+ // make sure we mark the iface up
+ mInterfaceCallbackCaptor.getValue().onUp(WIFI_IFACE_NAME);
+ mLooper.dispatchAll();
+
+ // make sure supplicant has been reported as active
+ mWsm.sendMessage(WifiMonitor.SUPPLICANT_STATE_CHANGE_EVENT, 0, 0,
+ new StateChangeResult(0, WifiSsid.createFromAsciiEncoded(""), null,
+ SupplicantState.DISCONNECTED));
+ mLooper.dispatchAll();
+
+ // trigger onDown for the client interface
+ mInterfaceCallbackCaptor.getValue().onDown(WIFI_IFACE_NAME);
+ mLooper.dispatchAll();
+
+ // WSM should trigger self recovery, but not disconnect until externally triggered
+ verify(mSelfRecovery, never()).trigger(eq(SelfRecovery.REASON_STA_IFACE_DOWN));
+ }
+
+ /**
+ * Test verifying that Supplicant update for inactive driver does not trigger SelfRecovery
+ * when the interface is reported down.
+ */
+ @Test
+ public void testSupplicantUpdateDriverInactiveInClientModeTriggersSelfRecovery()
+ throws Exception {
+ // Trigger initialize to capture the death handler registration.
+ loadComponentsInStaMode();
+
+ when(mWifiNative.isInterfaceUp(eq(WIFI_IFACE_NAME))).thenReturn(false);
+
+ mWsm.sendMessage(WifiMonitor.SUPPLICANT_STATE_CHANGE_EVENT, 0, 0,
+ new StateChangeResult(0, WifiSsid.createFromAsciiEncoded(""), null,
+ SupplicantState.INTERFACE_DISABLED));
+ mLooper.dispatchAll();
+
+ // WSM should trigger self recovery, but not disconnect until externally triggered
+ verify(mSelfRecovery, never()).trigger(eq(SelfRecovery.REASON_STA_IFACE_DOWN));
+ }
+
+ /**
+ * Test verifying that interface Supplicant update for inactive driver does not trigger
+ * SelfRecovery when WifiNative reports the interface is up.
+ */
+ @Test
+ public void testSupplicantUpdateDriverInactiveIfaceUpClientModeDoesNotTriggerSelfRecovery()
+ throws Exception {
+ // Trigger initialize to capture the death handler registration.
+ loadComponentsInStaMode();
+
+ when(mWifiNative.isInterfaceUp(eq(WIFI_IFACE_NAME))).thenReturn(true);
+
+ // make sure supplicant has been reported as inactive
+ mWsm.sendMessage(WifiMonitor.SUPPLICANT_STATE_CHANGE_EVENT, 0, 0,
+ new StateChangeResult(0, WifiSsid.createFromAsciiEncoded(""), null,
+ SupplicantState.INTERFACE_DISABLED));
+ mLooper.dispatchAll();
+
+ // WSM should trigger self recovery, but not disconnect until externally triggered
+ verify(mSelfRecovery, never()).trigger(eq(SelfRecovery.REASON_STA_IFACE_DOWN));
+ }
+
+ /**
+ * Test verifying that interface onDown callback does not trigger SelfRecovery when
+ * MacRandomization is enabled.
+ */
+ @Test
+ public void testInterfaceOnDownInClientModeDoesNotTriggerSelfRecoveryWithMacRand()
+ throws Exception {
+ when(mFrameworkFacade.getIntegerSetting(mContext,
+ Settings.Global.WIFI_CONNECTED_MAC_RANDOMIZATION_ENABLED, 0)).thenReturn(1);
+ mContentObserver.onChange(false);
+
+ // Trigger initialize to capture the death handler registration.
+ loadComponentsInStaMode();
+
+ // make sure we mark the iface up
+ mInterfaceCallbackCaptor.getValue().onUp(WIFI_IFACE_NAME);
+ mLooper.dispatchAll();
+
+ // trigger onDown for the client interface
+ mInterfaceCallbackCaptor.getValue().onDown(WIFI_IFACE_NAME);
+ mLooper.dispatchAll();
+
+ // WSM should trigger self recovery, but not disconnect until externally triggered
+ verify(mSelfRecovery, never()).trigger(eq(SelfRecovery.REASON_STA_IFACE_DOWN));
}
/**