summaryrefslogtreecommitdiffstats
path: root/tests/wifitests/src/com/android/server/wifi/WifiLastResortWatchdogTest.java
diff options
context:
space:
mode:
authorRebecca Silberstein <silberst@google.com>2016-04-29 16:10:45 -0700
committerRebecca Silberstein <silberst@google.com>2016-04-29 16:33:28 -0700
commit91a8893f047b8a193e4516ab772b6f43882777f5 (patch)
tree9c7a67c2171a17ea32a2e77aa4a5fb2d775658b0 /tests/wifitests/src/com/android/server/wifi/WifiLastResortWatchdogTest.java
parentddf3afe31f5e2174643e41943e9e9b881033981a (diff)
downloadandroid_frameworks_opt_net_wifi-91a8893f047b8a193e4516ab772b6f43882777f5.tar.gz
android_frameworks_opt_net_wifi-91a8893f047b8a193e4516ab772b6f43882777f5.tar.bz2
android_frameworks_opt_net_wifi-91a8893f047b8a193e4516ab772b6f43882777f5.zip
WifiLastResortWatchdog: update config if not null
When new scan results are processed, networks already stored as the available networks may have updated configs passed in, but they may also have null configs. The null configs should not be used to update the stored config. Added a check to determine if the passed in config is not null before the update. In addition, debugging output also reported the value of HasEverConnected as false for networks with a null config. This was updated to report null_config instead. Added tests covering config updates. Added tests for debugging output. BUG: 28451079 Change-Id: Iff9888ab87c61619b2f865516eca22d87eb4f4b8
Diffstat (limited to 'tests/wifitests/src/com/android/server/wifi/WifiLastResortWatchdogTest.java')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiLastResortWatchdogTest.java175
1 files changed, 175 insertions, 0 deletions
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"));
+ }
}