summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorxshu <xshu@google.com>2019-11-20 17:24:53 -0800
committerxshu <xshu@google.com>2019-11-21 16:36:37 -0800
commit42b506b4a331c28d8ab5a477a50088e13a1bbdfd (patch)
tree23e417fe400293d7f33f08b8ac6b1f74325213d4 /tests
parent6f4ff4c473aabac4312925e6ea7634a363f7f164 (diff)
Add frequent disconnects to BssidBlocklistMonitor
Addresses cases where the AP disconnects the device shortly after connection. Bug: 139287182 Test: atest FrameworksWifiTests Change-Id: I2805b5625a6c1dcac0a02dab20167a46c41575a0
Diffstat (limited to 'tests')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/BssidBlocklistMonitorTest.java50
-rw-r--r--tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java13
2 files changed, 61 insertions, 2 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/BssidBlocklistMonitorTest.java b/tests/wifitests/src/com/android/server/wifi/BssidBlocklistMonitorTest.java
index 1f42d45b6..3d397a241 100644
--- a/tests/wifitests/src/com/android/server/wifi/BssidBlocklistMonitorTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/BssidBlocklistMonitorTest.java
@@ -48,6 +48,8 @@ public class BssidBlocklistMonitorTest {
private static final int TEST_DHCP_FAILURE = BssidBlocklistMonitor.REASON_DHCP_FAILURE;
private static final long BASE_BLOCKLIST_DURATION = TimeUnit.MINUTES.toMillis(5); // 5 minutes
private static final long MAX_BLOCKLIST_DURATION = TimeUnit.HOURS.toMillis(18); // 18 hours
+ private static final long ABNORMAL_DISCONNECT_TIME_WINDOW_MS = TimeUnit.SECONDS.toMillis(30);
+ private static final long ABNORMAL_DISCONNECT_RESET_TIME_MS = TimeUnit.HOURS.toMillis(3);
private static final int FAILURE_STREAK_CAP = 7;
private static final int NUM_FAILURES_TO_BLOCKLIST = 3;
@@ -192,6 +194,34 @@ public class BssidBlocklistMonitorTest {
}
/**
+ * Verify that only abnormal disconnects that happened in a window of time right after
+ * connection gets counted in the BssidBlocklistMonitor.
+ */
+ @Test
+ public void testAbnormalDisconnectRecencyCheck() {
+ // does some setup so that 1 failure is enough to add the BSSID to blocklist.
+ when(mWifiScoreCard.getBssidBlocklistStreak(TEST_SSID_1, TEST_BSSID_1,
+ BssidBlocklistMonitor.REASON_ABNORMAL_DISCONNECT)).thenReturn(1);
+
+ // simulate an abnormal disconnect coming in after the allowed window of time
+ when(mWifiScoreCard.getBssidConnectionTimestampMs(TEST_SSID_1, TEST_BSSID_1))
+ .thenReturn(0L);
+ when(mClock.getWallClockMillis()).thenReturn(ABNORMAL_DISCONNECT_TIME_WINDOW_MS + 1);
+ assertFalse(mBssidBlocklistMonitor.handleBssidConnectionFailure(TEST_BSSID_1, TEST_SSID_1,
+ BssidBlocklistMonitor.REASON_ABNORMAL_DISCONNECT));
+ verify(mWifiScoreCard, never()).incrementBssidBlocklistStreak(TEST_SSID_1, TEST_BSSID_1,
+ BssidBlocklistMonitor.REASON_ABNORMAL_DISCONNECT);
+
+ // simulate another abnormal disconnect within the time window and verify the BSSID is
+ // added to blocklist.
+ when(mClock.getWallClockMillis()).thenReturn(ABNORMAL_DISCONNECT_TIME_WINDOW_MS);
+ assertTrue(mBssidBlocklistMonitor.handleBssidConnectionFailure(TEST_BSSID_1, TEST_SSID_1,
+ BssidBlocklistMonitor.REASON_ABNORMAL_DISCONNECT));
+ verify(mWifiScoreCard).incrementBssidBlocklistStreak(TEST_SSID_1, TEST_BSSID_1,
+ BssidBlocklistMonitor.REASON_ABNORMAL_DISCONNECT);
+ }
+
+ /**
* Verify that when the BSSID blocklist streak is greater or equal to 1, then we block a
* BSSID on a single failure regardless of failure type.
*/
@@ -254,7 +284,7 @@ public class BssidBlocklistMonitorTest {
*/
@Test
public void testNetworkConnectionResetsBlocklistStreak() {
- when(mClock.getWallClockMillis()).thenReturn(100L);
+ when(mClock.getWallClockMillis()).thenReturn(ABNORMAL_DISCONNECT_RESET_TIME_MS + 1);
mBssidBlocklistMonitor.handleBssidConnectionSuccess(TEST_BSSID_1, TEST_SSID_1);
verify(mWifiScoreCard).resetBssidBlocklistStreak(TEST_SSID_1, TEST_BSSID_1,
BssidBlocklistMonitor.REASON_AP_UNABLE_TO_HANDLE_NEW_STA);
@@ -268,7 +298,23 @@ public class BssidBlocklistMonitorTest {
BssidBlocklistMonitor.REASON_ASSOCIATION_TIMEOUT);
verify(mWifiScoreCard).resetBssidBlocklistStreak(TEST_SSID_1, TEST_BSSID_1,
BssidBlocklistMonitor.REASON_AUTHENTICATION_FAILURE);
- verify(mWifiScoreCard).setBssidConnectionTimeMs(TEST_SSID_1, TEST_BSSID_1, 100L);
+ verify(mWifiScoreCard).setBssidConnectionTimestampMs(TEST_SSID_1, TEST_BSSID_1,
+ ABNORMAL_DISCONNECT_RESET_TIME_MS + 1);
+ verify(mWifiScoreCard).resetBssidBlocklistStreak(TEST_SSID_1, TEST_BSSID_1,
+ BssidBlocklistMonitor.REASON_ABNORMAL_DISCONNECT);
+ }
+
+ /**
+ * Verify that the abnormal disconnect streak is not reset if insufficient time has passed.
+ */
+ @Test
+ public void testNetworkConnectionNotResetAbnormalDisconnectStreak() {
+ when(mClock.getWallClockMillis()).thenReturn(ABNORMAL_DISCONNECT_RESET_TIME_MS);
+ mBssidBlocklistMonitor.handleBssidConnectionSuccess(TEST_BSSID_1, TEST_SSID_1);
+ verify(mWifiScoreCard).setBssidConnectionTimestampMs(TEST_SSID_1, TEST_BSSID_1,
+ ABNORMAL_DISCONNECT_RESET_TIME_MS);
+ verify(mWifiScoreCard, never()).resetBssidBlocklistStreak(TEST_SSID_1, TEST_BSSID_1,
+ BssidBlocklistMonitor.REASON_ABNORMAL_DISCONNECT);
}
/**
diff --git a/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java b/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java
index 51300190a..7d68dc94c 100644
--- a/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java
@@ -2972,6 +2972,19 @@ public class ClientModeImplTest extends WifiBaseTest {
}
/**
+ * Verify that if a NETWORK_DISCONNECTION_EVENT is received in ConnectedState, then an
+ * abnormal disconnect is reported to BssidBlocklistMonitor.
+ */
+ @Test
+ public void testAbnormalDisconnectNotifiesBssidBlocklistMonitor() throws Exception {
+ connect();
+ mCmi.sendMessage(WifiMonitor.NETWORK_DISCONNECTION_EVENT, 0, 0, sBSSID);
+ mLooper.dispatchAll();
+ verify(mBssidBlocklistMonitor).handleBssidConnectionFailure(sBSSID, sSSID,
+ BssidBlocklistMonitor.REASON_ABNORMAL_DISCONNECT);
+ }
+
+ /**
* Verifies that WifiLastResortWatchdog and BssidBlocklistMonitor is notified of
* association rejection of type REASON_CODE_AP_UNABLE_TO_HANDLE_NEW_STA.
* @throws Exception