diff options
author | TreeHugger Robot <treehugger-gerrit@google.com> | 2019-03-11 03:49:42 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2019-03-11 03:49:42 +0000 |
commit | 10ad94b5b176b8703cd3853d2c313b7fb4267408 (patch) | |
tree | 4b3f70d9de2bbd658aa5192291d00b7b23916458 | |
parent | 3b788dc5f0bdcac7368be1aaff95e11e5b7ea9be (diff) | |
parent | 19a6fa3ee414186b4fec9d91d8498a31a44adaca (diff) | |
download | android_frameworks_opt_net_wifi-10ad94b5b176b8703cd3853d2c313b7fb4267408.tar.gz android_frameworks_opt_net_wifi-10ad94b5b176b8703cd3853d2c313b7fb4267408.tar.bz2 android_frameworks_opt_net_wifi-10ad94b5b176b8703cd3853d2c313b7fb4267408.zip |
Merge "LRWD: add time based logic to re-enable Watchdog"
-rw-r--r-- | service/java/com/android/server/wifi/WifiLastResortWatchdog.java | 14 | ||||
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/WifiLastResortWatchdogTest.java | 91 |
2 files changed, 96 insertions, 9 deletions
diff --git a/service/java/com/android/server/wifi/WifiLastResortWatchdog.java b/service/java/com/android/server/wifi/WifiLastResortWatchdog.java index 66956ef6e..8ebd938b3 100644 --- a/service/java/com/android/server/wifi/WifiLastResortWatchdog.java +++ b/service/java/com/android/server/wifi/WifiLastResortWatchdog.java @@ -67,6 +67,10 @@ public class WifiLastResortWatchdog { public static final String BUGREPORT_TITLE = "Wifi watchdog triggered"; public static final double PROB_TAKE_BUGREPORT_DEFAULT = 1; + // Number of milliseconds to wait before re-enable Watchdog triger + @VisibleForTesting + public static final long LAST_TRIGGER_TIMEOUT_MILLIS = 2 * 3600 * 1000; // 2 hours + /** * Cached WifiConfigurations of available networks seen within MAX_BSSID_AGE scan results * Key:BSSID, Value:Counters of failure types @@ -85,7 +89,7 @@ public class WifiLastResortWatchdog { // Is Watchdog allowed to trigger now? Set to false after triggering. Set to true after // successfully connecting or a new network (SSID) becomes available to connect to. private boolean mWatchdogAllowedToTrigger = true; - private long mTimeLastTrigger; + private long mTimeLastTrigger = 0; private WifiInjector mWifiInjector; private WifiMetrics mWifiMetrics; @@ -145,7 +149,13 @@ public class WifiLastResortWatchdog { // This is a new SSID, create new FailureCount for it and set AP count to 1 ssidFailsAndApCount = Pair.create(new AvailableNetworkFailureCount(config), 1); - setWatchdogTriggerEnabled(true); + // Do not re-enable Watchdog in LAST_TRIGGER_TIMEOUT_MILLIS + // after last time Watchdog be triggered + if (mTimeLastTrigger == 0 + || (mClock.getElapsedSinceBootMillis() - mTimeLastTrigger) + >= LAST_TRIGGER_TIMEOUT_MILLIS) { + setWatchdogTriggerEnabled(true); + } } else { final Integer numberOfAps = ssidFailsAndApCount.second; // This is not a new SSID, increment the AP count for it diff --git a/tests/wifitests/src/com/android/server/wifi/WifiLastResortWatchdogTest.java b/tests/wifitests/src/com/android/server/wifi/WifiLastResortWatchdogTest.java index 8e83285b5..a47b2cc17 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiLastResortWatchdogTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiLastResortWatchdogTest.java @@ -1381,7 +1381,8 @@ public class WifiLastResortWatchdogTest { } /** - * Case 24: Test enabling/disabling of Watchdog Trigger, trigger re-enabled after new network + * Case 24: Test enabling/disabling of Watchdog Trigger, trigger re-enabled after + * timeout mechanism with new network available. * In this test, we have 3 networks. Increment failures until Watchdog triggers and deactivates, * we then buffer a new network (network 4), then increment failures until all networks over * threshold Expected behavior: Watchdog able to trigger again after discovering a new network @@ -1394,6 +1395,9 @@ public class WifiLastResortWatchdogTest { boolean[] hasEverConnected = {false, true, false, false}; boolean watchdogTriggered; + final long timeAtFailure = 100; + when(mClock.getElapsedSinceBootMillis()).thenReturn(timeAtFailure); + // Buffer potential candidates 1,2,3 List<Pair<ScanDetail, WifiConfiguration>> candidates = createFilteredQnsCandidates( Arrays.copyOfRange(mSsids, 0, 3), @@ -1416,12 +1420,14 @@ public class WifiLastResortWatchdogTest { assertEquals(false, watchdogTriggered); } + when(mClock.getElapsedSinceBootMillis()) + .thenReturn(timeAtFailure + WifiLastResortWatchdog.LAST_TRIGGER_TIMEOUT_MILLIS); + candidates = createFilteredQnsCandidates(mSsids, mBssids, mFrequencies, mCaps, mLevels, mIsEphemeral, hasEverConnected); mLastResortWatchdog.updateAvailableNetworks(candidates); incrementFailuresUntilTrigger(mSsids, mBssids); - } /** @@ -1460,9 +1466,9 @@ public class WifiLastResortWatchdogTest { assertFailureCountEquals(bssids[i], 0, 0, 0); } - final long timeAtFailure = 100; - final long timeAtReconnect = 5000; - final long expectedDuration = timeAtReconnect - timeAtFailure; + long timeAtFailure = 100; + long timeAtReconnect = 5000; + long expectedDuration = timeAtReconnect - timeAtFailure; when(mClock.getElapsedSinceBootMillis()).thenReturn(timeAtFailure, timeAtReconnect); //Increment failure counts @@ -1528,6 +1534,11 @@ public class WifiLastResortWatchdogTest { mLastResortWatchdog.updateAvailableNetworks(candidates); } + timeAtFailure = 10100; + timeAtReconnect = 15000; + expectedDuration = timeAtReconnect - timeAtFailure; + when(mClock.getElapsedSinceBootMillis()).thenReturn(timeAtFailure, timeAtReconnect); + //Increment failure counts for (int i = 0; i < WifiLastResortWatchdog.FAILURE_THRESHOLD; i++) { mLastResortWatchdog.noteConnectionFailureAndTriggerIfNeeded( @@ -1540,12 +1551,17 @@ public class WifiLastResortWatchdogTest { ssids[0], bssids[0], WifiLastResortWatchdog.FAILURE_CODE_ASSOCIATION); } + // increment the timer to enable Watchdog + when(mClock.getElapsedSinceBootMillis()) + .thenReturn(timeAtFailure + WifiLastResortWatchdog.LAST_TRIGGER_TIMEOUT_MILLIS); + // Add network #5 back into the candidates candidates = createFilteredQnsCandidates(ssids, bssids, frequencies, caps, levels, isEphemeral, hasEverConnected); - // LastResortWatchdog should reactivate because there is a new network (#5) available, - // Not because it was successful + // LastResortWatchdog should reactivate if there is a new network (#5) + // available and time interval after last Watchdog trigger is over + // LAST_TRIGGER_TIMEOUT_MILLIS. mLastResortWatchdog.updateAvailableNetworks(candidates); // Simulate wifi connecting @@ -1996,4 +2012,65 @@ public class WifiLastResortWatchdogTest { verify(mWifiMetrics, times(1)).addCountToNumLastResortWatchdogBadDhcpNetworksTotal(1); verify(mWifiMetrics, times(1)).incrementNumLastResortWatchdogTriggersWithBadDhcp(); } + + /** + * Test Watchdog with time based logic. + * + * After Watchdog has triggered once and still fail to connect, + * Watchdog will not be allowed to work in 2 hours. + * Expected result: Watchdog won't be trigger again + */ + @Test + public void testWatchdogWithTimeBasedLogic() { + String[] ssids = {"\"test1\""}; + String[] bssids = {"6c:f3:7f:ae:8c:f3"}; + int[] frequencies = {2437}; + String[] caps = {"[WPA2-EAP-CCMP][ESS]"}; + int[] levels = {-60}; + boolean[] isEphemeral = {false}; + boolean[] hasEverConnected = {true}; + List<Pair<ScanDetail, WifiConfiguration>> candidates = createFilteredQnsCandidates(ssids, + bssids, frequencies, caps, levels, isEphemeral, hasEverConnected); + mLastResortWatchdog.updateAvailableNetworks(candidates); + + // Ensure new networks have zero'ed failure counts + for (int i = 0; i < mSsids.length; i++) { + assertFailureCountEquals(mBssids[i], 0, 0, 0); + } + + final long timeAtFailure = 100; + when(mClock.getElapsedSinceBootMillis()).thenReturn(timeAtFailure); + + incrementFailuresUntilTrigger(ssids, bssids); + + // Verify watchdog has triggered a restart + verify(mWifiMetrics, times(1)).incrementNumLastResortWatchdogTriggers(); + + // Age out network + for (int i = 0; i < WifiLastResortWatchdog.MAX_BSSID_AGE; i++) { + mLastResortWatchdog.updateAvailableNetworks(null); + } + assertEquals(mLastResortWatchdog.getRecentAvailableNetworks().size(), 0); + + when(mClock.getElapsedSinceBootMillis()).thenReturn(timeAtFailure + (300 * 1000)); + + // network back into the candidates + candidates = createFilteredQnsCandidates(ssids, + bssids, frequencies, caps, levels, isEphemeral, hasEverConnected); + mLastResortWatchdog.updateAvailableNetworks(candidates); + + // Ensure new networks have zero'ed failure counts + for (int i = 0; i < mSsids.length; i++) { + assertFailureCountEquals(mBssids[i], 0, 0, 0); + } + + // Increment failure counts + for (int i = 0; i < WifiLastResortWatchdog.FAILURE_THRESHOLD; i++) { + mLastResortWatchdog.noteConnectionFailureAndTriggerIfNeeded( + ssids[0], bssids[0], WifiLastResortWatchdog.FAILURE_CODE_ASSOCIATION); + } + + // Watchdog should not be triggerred since time based logic. + verify(mWifiMetrics, times(1)).incrementNumLastResortWatchdogTriggers(); + } } |