From 8da501dd29ae22e722de2c372570a08b27e10c98 Mon Sep 17 00:00:00 2001 From: Kai Shi Date: Mon, 10 Feb 2020 18:49:15 -0800 Subject: Trigger bugreport at high auth failure rate Trigger bugreport when high auth failure rate (>=80%) happens in an enterprise network at high RSSI with enough connection attempts (>=5). This is done in debug build only. The minimum interval between two captures is 60 mins. Test: unit test with atest com.android.server.wifi Test: manual Bug: 149256555 Change-Id: I57f99a404400d8b4b77f1199646c6917bd090627 --- .../src/com/android/server/wifi/ClientModeImplTest.java | 7 +++++++ .../com/android/server/wifi/WifiDiagnosticsTest.java | 13 +++++++++++++ .../src/com/android/server/wifi/WifiScoreCardTest.java | 17 ++++++++++++++++- 3 files changed, 36 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java b/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java index c5548dba7..4456d087c 100644 --- a/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java +++ b/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java @@ -56,6 +56,7 @@ import android.net.wifi.IActionListener; import android.net.wifi.ScanResult; import android.net.wifi.SupplicantState; import android.net.wifi.WifiConfiguration; +import android.net.wifi.WifiConfiguration.KeyMgmt; import android.net.wifi.WifiEnterpriseConfig; import android.net.wifi.WifiInfo; import android.net.wifi.WifiManager; @@ -1687,6 +1688,7 @@ public class ClientModeImplTest extends WifiBaseTest { verify(mWifiConfigManager).updateNetworkSelectionStatus(anyInt(), eq(WifiConfiguration.NetworkSelectionStatus.DISABLED_BY_WRONG_PASSWORD)); + verify(mWifiScoreCard, never()).detectAbnormalAuthFailure(any()); assertEquals("DisconnectedState", getCurrentState().getName()); } @@ -1711,6 +1713,7 @@ public class ClientModeImplTest extends WifiBaseTest { WifiConfiguration config = new WifiConfiguration(); config.SSID = sSSID; config.getNetworkSelectionStatus().setHasEverConnected(true); + config.allowedKeyManagement.set(KeyMgmt.IEEE8021X); config.enterpriseConfig.setEapMethod(WifiEnterpriseConfig.Eap.SIM); when(mWifiConfigManager.getConfiguredNetwork(anyInt())).thenReturn(config); MockitoSession mockSession = ExtendedMockito.mockitoSession() @@ -1728,6 +1731,7 @@ public class ClientModeImplTest extends WifiBaseTest { WifiNative.EAP_SIM_VENDOR_SPECIFIC_CERT_EXPIRED, config); verify(mDataTelephonyManager).resetCarrierKeysForImsiEncryption(); mockSession.finishMocking(); + verify(mWifiScoreCard).detectAbnormalAuthFailure(anyString()); } /** @@ -1749,6 +1753,7 @@ public class ClientModeImplTest extends WifiBaseTest { WifiConfiguration config = new WifiConfiguration(); config.getNetworkSelectionStatus().setHasEverConnected(true); config.enterpriseConfig.setEapMethod(WifiEnterpriseConfig.Eap.TLS); + config.allowedKeyManagement.set(KeyMgmt.IEEE8021X); when(mWifiConfigManager.getConfiguredNetwork(anyInt())).thenReturn(config); mCmi.sendMessage(WifiMonitor.AUTHENTICATION_FAILURE_EVENT, @@ -1757,6 +1762,7 @@ public class ClientModeImplTest extends WifiBaseTest { mLooper.dispatchAll(); verify(mDataTelephonyManager, never()).resetCarrierKeysForImsiEncryption(); + verify(mWifiScoreCard).detectAbnormalAuthFailure(null); } /** @@ -1784,6 +1790,7 @@ public class ClientModeImplTest extends WifiBaseTest { verify(mWifiConfigManager).updateNetworkSelectionStatus(anyInt(), eq(WifiConfiguration.NetworkSelectionStatus .DISABLED_AUTHENTICATION_NO_SUBSCRIPTION)); + verify(mWifiScoreCard, never()).detectAbnormalAuthFailure(null); } @Test diff --git a/tests/wifitests/src/com/android/server/wifi/WifiDiagnosticsTest.java b/tests/wifitests/src/com/android/server/wifi/WifiDiagnosticsTest.java index a20bb9872..acfc78d7e 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiDiagnosticsTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiDiagnosticsTest.java @@ -880,6 +880,19 @@ public class WifiDiagnosticsTest extends WifiBaseTest { verify(mBugreportManager, never()).requestBugreport(any(), any(), any()); } + @Test + public void tryTakeBugReportTwiceWithInsufficientTimeGap() { + when(mBuildProperties.isUserBuild()).thenReturn(false); + // 1st attempt should succeed + when(mClock.getWallClockMillis()).thenReturn(10L); + mWifiDiagnostics.takeBugReport("", ""); + verify(mBugreportManager, times(1)).requestBugreport(any(), any(), any()); + // 2nd attempt should fail + when(mClock.getWallClockMillis()).thenReturn(1000_000L); + mWifiDiagnostics.takeBugReport("", ""); + verify(mBugreportManager, times(1)).requestBugreport(any(), any(), any()); + } + @Test public void takeBugReportDoesNothingWhenConfigOverlayDisabled() { when(mBuildProperties.isUserBuild()).thenReturn(false); diff --git a/tests/wifitests/src/com/android/server/wifi/WifiScoreCardTest.java b/tests/wifitests/src/com/android/server/wifi/WifiScoreCardTest.java index ae71794e4..107511b4f 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiScoreCardTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiScoreCardTest.java @@ -149,6 +149,7 @@ public class WifiScoreCardTest extends WifiBaseTest { DeviceConfigFacade.DEFAULT_DISCONNECTION_NONLOCAL_LOW_THR_PERCENT); when(mDeviceConfigFacade.getHealthMonitorMinRssiThrDbm()).thenReturn( DeviceConfigFacade.DEFAULT_HEALTH_MONITOR_MIN_RSSI_THR_DBM); + mWifiScoreCard.enableVerboseLogging(true); } /** @@ -757,6 +758,13 @@ public class WifiScoreCardTest extends WifiBaseTest { BssidBlocklistMonitor.REASON_WRONG_PASSWORD); } + private void makeAuthFailureExample() { + mWifiScoreCard.noteConnectionAttempt(mWifiInfo, -53, mWifiInfo.getSSID()); + millisecondsPass(500); + mWifiScoreCard.noteConnectionFailure(mWifiInfo, -53, mWifiInfo.getSSID(), + BssidBlocklistMonitor.REASON_AUTHENTICATION_FAILURE); + } + /** * Check network stats after authentication failure and wrong password. */ @@ -1051,7 +1059,7 @@ public class WifiScoreCardTest extends WifiBaseTest { private void makeRecentStatsWithAuthFailure() { for (int i = 0; i < MIN_NUM_CONNECTION_ATTEMPT; i++) { - makeAuthFailureAndWrongPassword(); + makeAuthFailureExample(); } } @@ -1159,5 +1167,12 @@ public class WifiScoreCardTest extends WifiBaseTest { checkStatsDeltaExample(statsDec, 0); checkStatsDeltaExample(statsInc, 0); checkStatsDeltaExample(statsHigh, 1); + assertEquals(false, mWifiScoreCard.detectAbnormalAuthFailure(mWifiInfo.getSSID())); + } + + @Test + public void testHighAuthFailureRate() throws Exception { + makeRecentStatsWithAuthFailure(); + assertEquals(true, mWifiScoreCard.detectAbnormalAuthFailure(mWifiInfo.getSSID())); } } -- cgit v1.2.3