diff options
author | Kai Shi <kaishi@google.com> | 2020-06-16 21:09:17 -0700 |
---|---|---|
committer | Kai Shi <kaishi@google.com> | 2020-06-17 21:10:16 -0700 |
commit | 6d8147c663bfbe7507287054b0483feaf30d7c05 (patch) | |
tree | 3af26060cf467413588b158d131ee81bf4f17be6 /tests | |
parent | c4d7ad413909b181fd59b595dc66d7d6d39aa684 (diff) |
Check deauth reason and FW alert for abnormal disconnection
1)To improve abnormal disconnection detection, add deauth reason and FW
alert check. The list of reason codes is configurable through a 64-bit
mask and FW alert valid time is also configurable.
2)Move other abnormal connection failure and disconnection detection timing related parameters to DeviceConfig.
3)Log last rssi poll valid time in wifi metrics.
4)Reduce default value of rssi poll valid time from 3.1s to 2.1s
5)Reduce default value of scan rssi valid time for stationary state from
20s to 8s because mobility state detection could be delayed.
Updated-PDD: TRUE
Bug: 159178185
Test: atest com.android.server.wifi
Change-Id: I6e131f149d242e5dbf0b8b0087303e85ed428f9f
Merged-In: Ifbd5519841d616651cacc846056eda6ff64393e0
Diffstat (limited to 'tests')
4 files changed, 93 insertions, 14 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/DeviceConfigFacadeTest.java b/tests/wifitests/src/com/android/server/wifi/DeviceConfigFacadeTest.java index ce3eed098..bb03d42d7 100644 --- a/tests/wifitests/src/com/android/server/wifi/DeviceConfigFacadeTest.java +++ b/tests/wifitests/src/com/android/server/wifi/DeviceConfigFacadeTest.java @@ -84,6 +84,12 @@ public class DeviceConfigFacadeTest extends WifiBaseTest { return def; } }); + when(DeviceConfig.getLong(anyString(), anyString(), anyLong())) + .then(new AnswerWithArguments() { + public long answer(String namespace, String field, long def) { + return def; + } + }); when(DeviceConfig.getString(anyString(), anyString(), anyString())) .then(new AnswerWithArguments() { public String answer(String namespace, String field, String def) { @@ -187,6 +193,18 @@ public class DeviceConfigFacadeTest extends WifiBaseTest { mDeviceConfigFacade.getTxLinkSpeedLowThresholdMbps()); assertEquals(DeviceConfigFacade.DEFAULT_RX_LINK_SPEED_LOW_THRESHOLD_MBPS, mDeviceConfigFacade.getRxLinkSpeedLowThresholdMbps()); + assertEquals(DeviceConfigFacade.DEFAULT_HEALTH_MONITOR_RSSI_POLL_VALID_TIME_MS, + mDeviceConfigFacade.getHealthMonitorRssiPollValidTimeMs()); + assertEquals(DeviceConfigFacade.DEFAULT_HEALTH_MONITOR_SHORT_CONNECTION_DURATION_THR_MS, + mDeviceConfigFacade.getHealthMonitorShortConnectionDurationThrMs()); + assertEquals(DeviceConfigFacade.DEFAULT_ABNORMAL_DISCONNECTION_REASON_CODE_MASK, + mDeviceConfigFacade.getAbnormalDisconnectionReasonCodeMask()); + assertEquals(DeviceConfigFacade.DEFAULT_NONSTATIONARY_SCAN_RSSI_VALID_TIME_MS, + mDeviceConfigFacade.getNonstationaryScanRssiValidTimeMs()); + assertEquals(DeviceConfigFacade.DEFAULT_STATIONARY_SCAN_RSSI_VALID_TIME_MS, + mDeviceConfigFacade.getStationaryScanRssiValidTimeMs()); + assertEquals(DeviceConfigFacade.DEFAULT_HEALTH_MONITOR_FW_ALERT_VALID_TIME_MS, + mDeviceConfigFacade.getHealthMonitorFwAlertValidTimeMs()); } /** @@ -277,7 +295,18 @@ public class DeviceConfigFacadeTest extends WifiBaseTest { anyInt())).thenReturn(9); when(DeviceConfig.getInt(anyString(), eq("rx_link_speed_low_threshold_mbps"), anyInt())).thenReturn(10); - + when(DeviceConfig.getInt(anyString(), eq("health_monitor_short_connection_duration_thr_ms"), + anyInt())).thenReturn(30_000); + when(DeviceConfig.getLong(anyString(), eq("abnormal_disconnection_reason_code_mask"), + anyLong())).thenReturn(0xffff_fff3_0000_ffffL); + when(DeviceConfig.getInt(anyString(), eq("health_monitor_rssi_poll_valid_time_ms"), + anyInt())).thenReturn(2000); + when(DeviceConfig.getInt(anyString(), eq("nonstationary_scan_rssi_valid_time_ms"), + anyInt())).thenReturn(4000); + when(DeviceConfig.getInt(anyString(), eq("stationary_scan_rssi_valid_time_ms"), + anyInt())).thenReturn(3000); + when(DeviceConfig.getInt(anyString(), eq("health_monitor_fw_alert_valid_time_ms"), + anyInt())).thenReturn(1000); mOnPropertiesChangedListenerCaptor.getValue().onPropertiesChanged(null); // Verifying fields are updated to the new values @@ -326,5 +355,13 @@ public class DeviceConfigFacadeTest extends WifiBaseTest { assertEquals(50000, mDeviceConfigFacade.getOverlappingConnectionDurationThresholdMs()); assertEquals(9, mDeviceConfigFacade.getTxLinkSpeedLowThresholdMbps()); assertEquals(10, mDeviceConfigFacade.getRxLinkSpeedLowThresholdMbps()); + assertEquals(30_000, + mDeviceConfigFacade.getHealthMonitorShortConnectionDurationThrMs()); + assertEquals(0xffff_fff3_0000_ffffL, + mDeviceConfigFacade.getAbnormalDisconnectionReasonCodeMask()); + assertEquals(2000, mDeviceConfigFacade.getHealthMonitorRssiPollValidTimeMs()); + assertEquals(4000, mDeviceConfigFacade.getNonstationaryScanRssiValidTimeMs()); + assertEquals(3000, mDeviceConfigFacade.getStationaryScanRssiValidTimeMs()); + assertEquals(1000, mDeviceConfigFacade.getHealthMonitorFwAlertValidTimeMs()); } } diff --git a/tests/wifitests/src/com/android/server/wifi/WifiDiagnosticsTest.java b/tests/wifitests/src/com/android/server/wifi/WifiDiagnosticsTest.java index c89fe675a..e72f80887 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiDiagnosticsTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiDiagnosticsTest.java @@ -73,6 +73,7 @@ public class WifiDiagnosticsTest extends WifiBaseTest { @Mock WifiMetrics mWifiMetrics; @Mock Clock mClock; @Mock BugreportManager mBugreportManager; + @Mock WifiScoreCard mWifiScoreCard; private long mBootTimeMs = 0L; MockResources mResources; WifiDiagnostics mWifiDiagnostics; @@ -136,6 +137,7 @@ public class WifiDiagnosticsTest extends WifiBaseTest { when(mWifiInjector.getJavaRuntime()).thenReturn(mJavaRuntime); when(mWifiInjector.getWifiMetrics()).thenReturn(mWifiMetrics); when(mWifiInjector.getDeviceConfigFacade()).thenReturn(mDeviceConfigFacade); + when(mWifiInjector.getWifiScoreCard()).thenReturn(mWifiScoreCard); when(mDeviceConfigFacade.getBugReportMinWindowMs()).thenReturn(BUG_REPORT_MIN_WINDOW_MS); // needed to for the loop in WifiDiagnostics.readLogcatStreamLinesWithTimeout(). doAnswer(new AnswerWithArguments() { @@ -744,6 +746,7 @@ public class WifiDiagnosticsTest extends WifiBaseTest { assertArrayEquals(ALERT_DATA, alertReport.alertData); verify(mWifiMetrics).logFirmwareAlert(ALERT_REASON_CODE); + verify(mWifiScoreCard).noteFirmwareAlert(ALERT_REASON_CODE); } /** Verifies that we skip the firmware and driver dumps if verbose is not enabled. */ diff --git a/tests/wifitests/src/com/android/server/wifi/WifiHealthMonitorTest.java b/tests/wifitests/src/com/android/server/wifi/WifiHealthMonitorTest.java index 264fe9048..8bf1e2a4a 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiHealthMonitorTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiHealthMonitorTest.java @@ -200,6 +200,18 @@ public class WifiHealthMonitorTest extends WifiBaseTest { DeviceConfigFacade.DEFAULT_HEALTH_MONITOR_RATIO_THR_NUMERATOR); when(mDeviceConfigFacade.getHealthMonitorMinNumConnectionAttempt()).thenReturn( DeviceConfigFacade.DEFAULT_HEALTH_MONITOR_MIN_NUM_CONNECTION_ATTEMPT); + when(mDeviceConfigFacade.getHealthMonitorShortConnectionDurationThrMs()).thenReturn( + DeviceConfigFacade.DEFAULT_HEALTH_MONITOR_SHORT_CONNECTION_DURATION_THR_MS); + when(mDeviceConfigFacade.getAbnormalDisconnectionReasonCodeMask()).thenReturn( + DeviceConfigFacade.DEFAULT_ABNORMAL_DISCONNECTION_REASON_CODE_MASK); + when(mDeviceConfigFacade.getHealthMonitorRssiPollValidTimeMs()).thenReturn( + DeviceConfigFacade.DEFAULT_HEALTH_MONITOR_RSSI_POLL_VALID_TIME_MS); + when(mDeviceConfigFacade.getHealthMonitorFwAlertValidTimeMs()).thenReturn( + DeviceConfigFacade.DEFAULT_HEALTH_MONITOR_FW_ALERT_VALID_TIME_MS); + when(mDeviceConfigFacade.getNonstationaryScanRssiValidTimeMs()).thenReturn( + DeviceConfigFacade.DEFAULT_NONSTATIONARY_SCAN_RSSI_VALID_TIME_MS); + when(mDeviceConfigFacade.getStationaryScanRssiValidTimeMs()).thenReturn( + DeviceConfigFacade.DEFAULT_STATIONARY_SCAN_RSSI_VALID_TIME_MS); mWifiHealthMonitor = new WifiHealthMonitor(mContext, mWifiInjector, mClock, mWifiConfigManager, mWifiScoreCard, new Handler(mLooper.getLooper()), mWifiNative, "some seed", mDeviceConfigFacade); @@ -294,7 +306,7 @@ public class WifiHealthMonitorTest extends WifiBaseTest { millisecondsPass(1000); mWifiScoreCard.noteSignalPoll(mWifiInfo); millisecondsPass(2000); - int disconnectionReason = 3; + int disconnectionReason = 0; mWifiScoreCard.noteNonlocalDisconnect(disconnectionReason); millisecondsPass(10); mWifiScoreCard.resetConnectionState(); diff --git a/tests/wifitests/src/com/android/server/wifi/WifiScoreCardTest.java b/tests/wifitests/src/com/android/server/wifi/WifiScoreCardTest.java index 1ad767c6e..e5739a1c8 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiScoreCardTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiScoreCardTest.java @@ -104,7 +104,6 @@ public class WifiScoreCardTest extends WifiBaseTest { void millisecondsPass(long ms) { mMilliSecondsSinceBoot += ms; when(mClock.getElapsedSinceBootMillis()).thenReturn(mMilliSecondsSinceBoot); - when(mClock.getWallClockMillis()).thenReturn(mMilliSecondsSinceBoot + 1_500_000_000_000L); } void secondsPass(long s) { @@ -158,6 +157,13 @@ public class WifiScoreCardTest extends WifiBaseTest { DeviceConfigFacade.DEFAULT_HEALTH_MONITOR_RATIO_THR_NUMERATOR); when(mDeviceConfigFacade.getHealthMonitorMinNumConnectionAttempt()).thenReturn( DeviceConfigFacade.DEFAULT_HEALTH_MONITOR_MIN_NUM_CONNECTION_ATTEMPT); + when(mDeviceConfigFacade.getHealthMonitorShortConnectionDurationThrMs()).thenReturn( + DeviceConfigFacade.DEFAULT_HEALTH_MONITOR_SHORT_CONNECTION_DURATION_THR_MS); + when(mDeviceConfigFacade.getAbnormalDisconnectionReasonCodeMask()).thenReturn( + DeviceConfigFacade.DEFAULT_ABNORMAL_DISCONNECTION_REASON_CODE_MASK); + when(mDeviceConfigFacade.getHealthMonitorRssiPollValidTimeMs()).thenReturn(3000); + // Disable FW alert time check by default + when(mDeviceConfigFacade.getHealthMonitorFwAlertValidTimeMs()).thenReturn(-1); when(mDeviceConfigFacade.getBugReportThresholdExtraRatio()).thenReturn(1); mWifiScoreCard.enableVerboseLogging(true); } @@ -916,7 +922,7 @@ public class WifiScoreCardTest extends WifiBaseTest { // Disconnect from SSID_1 millisecondsPass(100); - int disconnectionReason = 3; + int disconnectionReason = 4; mWifiScoreCard.noteNonlocalDisconnect(disconnectionReason); millisecondsPass(100); mWifiScoreCard.resetConnectionState(); @@ -954,7 +960,7 @@ public class WifiScoreCardTest extends WifiBaseTest { checkShortConnectionExample(dailyStats, 0); } - private void makeShortConnectionExample() { + private void makeShortConnectionExample(boolean addFwAlert) { mWifiScoreCard.noteConnectionAttempt(mWifiInfo, -53, mWifiInfo.getSSID()); millisecondsPass(5000); mWifiInfo.setTxLinkSpeedMbps(100); @@ -964,8 +970,11 @@ public class WifiScoreCardTest extends WifiBaseTest { millisecondsPass(1000); mWifiScoreCard.noteSignalPoll(mWifiInfo); millisecondsPass(2000); - int disconnectionReason = 3; + int disconnectionReason = 34; mWifiScoreCard.noteNonlocalDisconnect(disconnectionReason); + if (addFwAlert) { + mWifiScoreCard.noteFirmwareAlert(6); + } millisecondsPass(1000); mWifiScoreCard.resetConnectionState(); } @@ -1007,12 +1016,13 @@ public class WifiScoreCardTest extends WifiBaseTest { } /** - * Check network stats after RSSI poll and disconnection. + * Check network stats after RSSI poll and disconnection, pass FW alert check */ @Test - public void testNetworkRssiPollShortNonlocalDisconnection() throws Exception { + public void testNetworkRssiPollShortNonlocalDisconnectionPassFwAlertCheck() throws Exception { + when(mDeviceConfigFacade.getHealthMonitorFwAlertValidTimeMs()).thenReturn(2000); // 1st connection session - makeShortConnectionExample(); + makeShortConnectionExample(/*addFwAlert*/true); // 2nd connection session makeNormalConnectionExample(); @@ -1029,6 +1039,23 @@ public class WifiScoreCardTest extends WifiBaseTest { } /** + * Check network stats after RSSI poll and disconnection, fail FW alert check + */ + @Test + public void testNetworkRssiPollShortNonlocalDisconnectionFailFwAlertCheck() throws Exception { + when(mDeviceConfigFacade.getHealthMonitorFwAlertValidTimeMs()).thenReturn(2000); + // 1st connection session + makeShortConnectionExample(/*addFwAlert*/false); + // 2nd connection session + makeNormalConnectionExample(); + + PerNetwork perNetwork = mWifiScoreCard.fetchByNetwork(mWifiInfo.getSSID()); + NetworkConnectionStats dailyStats = perNetwork.getRecentStats(); + assertEquals(0, dailyStats.getCount(CNT_SHORT_CONNECTION_NONLOCAL)); + assertEquals(0, dailyStats.getCount(CNT_DISCONNECTION_NONLOCAL)); + } + + /** * Check network stats after short connection with an old RSSI polling */ @Test @@ -1130,7 +1157,7 @@ public class WifiScoreCardTest extends WifiBaseTest { @Test public void testUpdateAfterDailyDetection() throws Exception { for (int i = 0; i < DEFAULT_HEALTH_MONITOR_MIN_NUM_CONNECTION_ATTEMPT; i++) { - makeShortConnectionExample(); + makeShortConnectionExample(/*addFwAlert*/false); } PerNetwork perNetwork = mWifiScoreCard.fetchByNetwork(mWifiInfo.getSSID()); @@ -1145,7 +1172,7 @@ public class WifiScoreCardTest extends WifiBaseTest { @Test public void testUpdateAfterSwBuildChange() throws Exception { for (int i = 0; i < DEFAULT_HEALTH_MONITOR_MIN_NUM_CONNECTION_ATTEMPT; i++) { - makeShortConnectionExample(); + makeShortConnectionExample(/*addFwAlert*/false); } PerNetwork perNetwork = mWifiScoreCard.fetchByNetwork(mWifiInfo.getSSID()); perNetwork.updateAfterDailyDetection(); @@ -1165,7 +1192,7 @@ public class WifiScoreCardTest extends WifiBaseTest { private void makeRecentStatsWithShortConnection() { for (int i = 0; i < DEFAULT_HEALTH_MONITOR_MIN_NUM_CONNECTION_ATTEMPT; i++) { - makeShortConnectionExample(); + makeShortConnectionExample(/*addFwAlert*/false); } } @@ -1196,7 +1223,7 @@ public class WifiScoreCardTest extends WifiBaseTest { @Test public void testDailyDetectionWithInsufficientRecentStats() throws Exception { PerNetwork perNetwork = mWifiScoreCard.lookupNetwork(mWifiInfo.getSSID()); - makeShortConnectionExample(); + makeShortConnectionExample(/*addFwAlert*/false); FailureStats statsDec = new FailureStats(); FailureStats statsInc = new FailureStats(); @@ -1269,7 +1296,7 @@ public class WifiScoreCardTest extends WifiBaseTest { makeRecentStatsWithGoodConnection(); // Add a small number of failures for each failure type after the SW build change for (int i = 0; i < mDeviceConfigFacade.getAuthFailureCountMin() - 1; i++) { - makeShortConnectionExample(); + makeShortConnectionExample(/*addFwAlert*/false); makeAssocTimeOutExample(); makeAuthFailureExample(); } |