summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--service/java/com/android/server/wifi/WifiLastResortWatchdog.java15
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiLastResortWatchdogTest.java175
2 files changed, 184 insertions, 6 deletions
diff --git a/service/java/com/android/server/wifi/WifiLastResortWatchdog.java b/service/java/com/android/server/wifi/WifiLastResortWatchdog.java
index a953404c5..896c1c816 100644
--- a/service/java/com/android/server/wifi/WifiLastResortWatchdog.java
+++ b/service/java/com/android/server/wifi/WifiLastResortWatchdog.java
@@ -128,8 +128,10 @@ public class WifiLastResortWatchdog {
}
mSsidFailureCount.put(ssid, ssidFailsAndApCount);
}
- // refresh config
- availableNetworkFailureCount.config = config;
+ // refresh config if it is not null
+ if (config != null) {
+ availableNetworkFailureCount.config = config;
+ }
// If we saw a network, set its Age to -1 here, aging iteration will set it to 0
availableNetworkFailureCount.age = -1;
mRecentAvailableNetworks.put(bssid, availableNetworkFailureCount);
@@ -185,6 +187,7 @@ public class WifiLastResortWatchdog {
// Have we met conditions to trigger the Watchdog Wifi restart?
boolean isRestartNeeded = checkTriggerCondition();
+ if (VDBG) Log.v(TAG, "isRestartNeeded = " + isRestartNeeded);
if (isRestartNeeded) {
// Stop the watchdog from triggering until re-enabled
setWatchdogTriggerEnabled(false);
@@ -292,7 +295,7 @@ public class WifiLastResortWatchdog {
* @return is the trigger condition true
*/
private boolean checkTriggerCondition() {
- if (VDBG) Log.v(TAG, "checkTriggerCondition:");
+ if (VDBG) Log.v(TAG, "checkTriggerCondition.");
// Don't check Watchdog trigger if wifi is in a connected state
// (This should not occur, but we want to protect against any race conditions)
if (mWifiIsConnected) return false;
@@ -492,8 +495,8 @@ public class WifiLastResortWatchdog {
*/
public int age = 0;
- AvailableNetworkFailureCount(WifiConfiguration config) {
- config = config;
+ AvailableNetworkFailureCount(WifiConfiguration configParam) {
+ this.config = configParam;
}
/**
@@ -525,7 +528,7 @@ public class WifiLastResortWatchdog {
public String toString() {
return ssid + ", HasEverConnected: " + ((config != null)
- ? config.getNetworkSelectionStatus().getHasEverConnected() : false)
+ ? config.getNetworkSelectionStatus().getHasEverConnected() : "null_config")
+ ", Failures: {"
+ "Assoc: " + associationRejection
+ ", Auth: " + authenticationFailure
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiLastResortWatchdogTest.java b/tests/wifitests/src/com/android/server/wifi/WifiLastResortWatchdogTest.java
index dabe11971..64f1ce0fd 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiLastResortWatchdogTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiLastResortWatchdogTest.java
@@ -17,6 +17,7 @@
package com.android.server.wifi;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.*;
import android.net.wifi.WifiConfiguration;
@@ -1472,4 +1473,178 @@ public class WifiLastResortWatchdogTest {
verify(mWifiMetrics, times(1)).addCountToNumLastResortWatchdogBadDhcpNetworksTotal(3);
verify(mWifiMetrics, times(1)).incrementNumLastResortWatchdogTriggersWithBadDhcp();
}
+
+ /**
+ * Case 21: Test config updates where new config is null.
+ * Create a scan result with an associated config and update the available networks list.
+ * Repeat this with a second scan result where the config is null.
+ * Expected behavior: The stored config should not be lost overwritten.
+ */
+ @Test
+ public void testUpdateNetworkWithNullConfig() {
+ List<Pair<ScanDetail, WifiConfiguration>> candidates =
+ new ArrayList<Pair<ScanDetail, WifiConfiguration>>();
+ String ssid = mSsids[0].replaceAll("^\"+", "").replaceAll("\"+$", "");
+ ScanDetail scanDetail = new ScanDetail(WifiSsid.createFromAsciiEncoded(ssid),
+ mBssids[0], mCaps[0], mLevels[0], mFrequencies[0], System.currentTimeMillis(), 0);
+ WifiConfiguration config = mock(WifiConfiguration.class);
+ WifiConfiguration.NetworkSelectionStatus networkSelectionStatus =
+ mock(WifiConfiguration.NetworkSelectionStatus.class);
+ when(config.getNetworkSelectionStatus()).thenReturn(networkSelectionStatus);
+ when(networkSelectionStatus.getHasEverConnected())
+ .thenReturn(true);
+ candidates.add(Pair.create(scanDetail, config));
+ mLastResortWatchdog.updateAvailableNetworks(candidates);
+
+ candidates.clear();
+
+ candidates.add(Pair.create(scanDetail, null));
+ mLastResortWatchdog.updateAvailableNetworks(candidates);
+
+ boolean watchdogTriggered = false;
+ for (int i = 0; i < WifiLastResortWatchdog.FAILURE_THRESHOLD; i++) {
+ watchdogTriggered = mLastResortWatchdog.noteConnectionFailureAndTriggerIfNeeded(
+ mSsids[0], mBssids[0], WifiLastResortWatchdog.FAILURE_CODE_AUTHENTICATION);
+ }
+ assertEquals(true, watchdogTriggered);
+ }
+
+ /**
+ * Case 22: Test config updates where hasEverConnected goes from false to true.
+ * Create a scan result with an associated config and update the available networks list.
+ * Repeat this with a second scan result where the config value for hasEverConnected
+ * is true.
+ * Expected behavior: The stored config should not be lost overwritten.
+ */
+ @Test
+ public void testUpdateNetworkWithHasEverConnectedTrue() {
+ List<Pair<ScanDetail, WifiConfiguration>> candidates =
+ new ArrayList<Pair<ScanDetail, WifiConfiguration>>();
+ String ssid = mSsids[0].replaceAll("^\"+", "").replaceAll("\"+$", "");
+ ScanDetail scanDetail = new ScanDetail(WifiSsid.createFromAsciiEncoded(ssid),
+ mBssids[0], mCaps[0], mLevels[0], mFrequencies[0], System.currentTimeMillis(), 0);
+ WifiConfiguration configHasEverConnectedFalse = mock(WifiConfiguration.class);
+ WifiConfiguration.NetworkSelectionStatus networkSelectionStatusFalse =
+ mock(WifiConfiguration.NetworkSelectionStatus.class);
+ when(configHasEverConnectedFalse.getNetworkSelectionStatus())
+ .thenReturn(networkSelectionStatusFalse);
+ when(networkSelectionStatusFalse.getHasEverConnected())
+ .thenReturn(false);
+ candidates.add(Pair.create(scanDetail, configHasEverConnectedFalse));
+ mLastResortWatchdog.updateAvailableNetworks(candidates);
+
+ boolean watchdogTriggered = false;
+ for (int i = 0; i < WifiLastResortWatchdog.FAILURE_THRESHOLD; i++) {
+ watchdogTriggered = mLastResortWatchdog.noteConnectionFailureAndTriggerIfNeeded(
+ mSsids[0], mBssids[0], WifiLastResortWatchdog.FAILURE_CODE_AUTHENTICATION);
+ }
+ assertEquals(false, watchdogTriggered);
+
+ candidates.clear();
+
+ WifiConfiguration configHasEverConnectedTrue = mock(WifiConfiguration.class);
+ WifiConfiguration.NetworkSelectionStatus networkSelectionStatusTrue =
+ mock(WifiConfiguration.NetworkSelectionStatus.class);
+ when(configHasEverConnectedTrue.getNetworkSelectionStatus())
+ .thenReturn(networkSelectionStatusTrue);
+ when(networkSelectionStatusTrue.getHasEverConnected())
+ .thenReturn(true);
+ candidates.add(Pair.create(scanDetail, configHasEverConnectedTrue));
+ mLastResortWatchdog.updateAvailableNetworks(candidates);
+
+ watchdogTriggered = mLastResortWatchdog.noteConnectionFailureAndTriggerIfNeeded(
+ mSsids[0], mBssids[0], WifiLastResortWatchdog.FAILURE_CODE_AUTHENTICATION);
+ assertEquals(true, watchdogTriggered);
+ }
+
+ /**
+ * Case 23: Test config updates where hasEverConnected goes from true to false.
+ * Create a scan result with an associated config and update the available networks list.
+ * Repeat this with a second scan result where hasEverConnected is false.
+ * Expected behavior: The stored config should not be lost overwritten.
+ */
+ @Test
+ public void testUpdateNetworkWithHasEverConnectedFalse() {
+ List<Pair<ScanDetail, WifiConfiguration>> candidates =
+ new ArrayList<Pair<ScanDetail, WifiConfiguration>>();
+ String ssid = mSsids[0].replaceAll("^\"+", "").replaceAll("\"+$", "");
+ ScanDetail scanDetail = new ScanDetail(WifiSsid.createFromAsciiEncoded(ssid),
+ mBssids[0], mCaps[0], mLevels[0], mFrequencies[0], System.currentTimeMillis(), 0);
+
+ WifiConfiguration configHasEverConnectedTrue = mock(WifiConfiguration.class);
+ WifiConfiguration.NetworkSelectionStatus networkSelectionStatusTrue =
+ mock(WifiConfiguration.NetworkSelectionStatus.class);
+ when(configHasEverConnectedTrue.getNetworkSelectionStatus())
+ .thenReturn(networkSelectionStatusTrue);
+ when(networkSelectionStatusTrue.getHasEverConnected())
+ .thenReturn(true);
+ candidates.add(Pair.create(scanDetail, configHasEverConnectedTrue));
+ mLastResortWatchdog.updateAvailableNetworks(candidates);
+
+ boolean watchdogTriggered = false;
+ for (int i = 0; i < WifiLastResortWatchdog.FAILURE_THRESHOLD; i++) {
+ watchdogTriggered = mLastResortWatchdog.noteConnectionFailureAndTriggerIfNeeded(
+ mSsids[0], mBssids[0], WifiLastResortWatchdog.FAILURE_CODE_AUTHENTICATION);
+ }
+ assertEquals(true, watchdogTriggered);
+
+ candidates.clear();
+
+ WifiConfiguration configHasEverConnectedFalse = mock(WifiConfiguration.class);
+ WifiConfiguration.NetworkSelectionStatus networkSelectionStatusFalse =
+ mock(WifiConfiguration.NetworkSelectionStatus.class);
+ when(configHasEverConnectedFalse.getNetworkSelectionStatus())
+ .thenReturn(networkSelectionStatusFalse);
+ when(networkSelectionStatusFalse.getHasEverConnected())
+ .thenReturn(false);
+ candidates.add(Pair.create(scanDetail, configHasEverConnectedFalse));
+ mLastResortWatchdog.updateAvailableNetworks(candidates);
+
+ for (int i = 0; i < WifiLastResortWatchdog.FAILURE_THRESHOLD; i++) {
+ watchdogTriggered = mLastResortWatchdog.noteConnectionFailureAndTriggerIfNeeded(
+ mSsids[0], mBssids[0], WifiLastResortWatchdog.FAILURE_CODE_AUTHENTICATION);
+ }
+ assertEquals(false, watchdogTriggered);
+ }
+
+ /**
+ * Case 24: Check toString method for accurate hasEverConnected value in
+ * AvailableNetworkFailureCount objects.
+ * Create an AvailableNetworkFailureCount instance and check output of toString method.
+ * Expected behavior: String contains HasEverConnected setting or null_config if there is not
+ * an associated config.
+ */
+ @Test
+ public void testHasEverConnectedValueInAvailableNetworkFailureCountToString() {
+ // Check with HasEverConnected true
+ WifiConfiguration configHasEverConnectedTrue = mock(WifiConfiguration.class);
+ WifiConfiguration.NetworkSelectionStatus networkSelectionStatusTrue =
+ mock(WifiConfiguration.NetworkSelectionStatus.class);
+ when(configHasEverConnectedTrue.getNetworkSelectionStatus())
+ .thenReturn(networkSelectionStatusTrue);
+ when(networkSelectionStatusTrue.getHasEverConnected()).thenReturn(true);
+ WifiLastResortWatchdog.AvailableNetworkFailureCount withConfigHECTrue =
+ new WifiLastResortWatchdog.AvailableNetworkFailureCount(configHasEverConnectedTrue);
+ String output = withConfigHECTrue.toString();
+ assertTrue(output.contains("HasEverConnected: true"));
+
+ // check with HasEverConnected false
+ WifiConfiguration configHasEverConnectedFalse = mock(WifiConfiguration.class);
+ WifiConfiguration.NetworkSelectionStatus networkSelectionStatusFalse =
+ mock(WifiConfiguration.NetworkSelectionStatus.class);
+ when(configHasEverConnectedFalse.getNetworkSelectionStatus())
+ .thenReturn(networkSelectionStatusFalse);
+ when(networkSelectionStatusFalse.getHasEverConnected()).thenReturn(false);
+ WifiLastResortWatchdog.AvailableNetworkFailureCount withConfigHECFalse =
+ new WifiLastResortWatchdog.AvailableNetworkFailureCount(
+ configHasEverConnectedFalse);
+ output = withConfigHECFalse.toString();
+ assertTrue(output.contains("HasEverConnected: false"));
+
+ // Check with a null config
+ WifiLastResortWatchdog.AvailableNetworkFailureCount withNullConfig =
+ new WifiLastResortWatchdog.AvailableNetworkFailureCount(null);
+ output = withNullConfig.toString();
+ assertTrue(output.contains("HasEverConnected: null_config"));
+ }
}