summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRandy Pan <zpan@google.com>2016-10-10 21:26:19 +0000
committerandroid-build-merger <android-build-merger@google.com>2016-10-10 21:26:19 +0000
commit818ebf58946a7235aa5d54e9afce9e9d22b945e3 (patch)
tree65b04734bcaf86ebd726fe011b3776f4a8effc69 /tests
parent6a5e90ea3e9054ad67f74483215d37cd6d712675 (diff)
parent0b9b32c53a83dea56417bda7bc9ddc1dc1e4222e (diff)
ExternalScoreEvaluator: factor in active network
am: 0b9b32c53a Change-Id: I9cdaad1221048b6494ffef562d80eb8b68068b24
Diffstat (limited to 'tests')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/ExternalScoreEvaluatorTest.java71
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTestUtil.java19
2 files changed, 84 insertions, 6 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/ExternalScoreEvaluatorTest.java b/tests/wifitests/src/com/android/server/wifi/ExternalScoreEvaluatorTest.java
index 16bd4f8d8..ada21461f 100644
--- a/tests/wifitests/src/com/android/server/wifi/ExternalScoreEvaluatorTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/ExternalScoreEvaluatorTest.java
@@ -416,4 +416,75 @@ public class ExternalScoreEvaluatorTest {
assertEquals("Expect null configuration", null, candidate);
}
+
+ /**
+ * Between two ephemeral networks with the same RSSI, choose
+ * the currently connected one.
+ */
+ @Test
+ public void chooseActiveEphemeralNetwork() {
+ String[] ssids = {"\"test1\"", "\"test2\""};
+ String[] bssids = {"6c:f3:7f:ae:8c:f3", "6c:f3:7f:ae:8c:f4"};
+ int[] freqs = {2470, 2437};
+ String[] caps = {"[ESS]", "[ESS]"};
+ int[] levels = {mThresholdQualifiedRssi2G + 28, mThresholdQualifiedRssi2G + 28};
+ boolean[] meteredHints = {true, true};
+ ScanResult[] scanResults = new ScanResult[2];
+ WifiConfiguration[] ephemeralNetworkConfigs = new WifiConfiguration[2];
+
+ List<ScanDetail> scanDetails = WifiNetworkSelectorTestUtil.buildScanDetails(
+ ssids, bssids, freqs, caps, levels, mClock);
+ WifiNetworkSelectorTestUtil.configureScoreCache(mScoreCache,
+ scanDetails, null, meteredHints);
+
+ // No saved networks.
+ when(mWifiConfigManager.getSavedNetworkForScanDetailAndCache(any(ScanDetail.class)))
+ .thenReturn(null);
+
+ for (int i = 0; i < 2; i++) {
+ scanResults[i] = scanDetails.get(i).getScanResult();
+ ephemeralNetworkConfigs[i] = WifiNetworkSelectorTestUtil
+ .setupEphemeralNetwork(mWifiConfigManager, i, scanResults[i], meteredHints[i]);
+ }
+
+ WifiConfiguration candidate = mExternalScoreEvaluator.evaluateNetworks(scanDetails,
+ null, bssids[1], true, true, null);
+
+ WifiConfigurationTestUtil.assertConfigurationEqual(ephemeralNetworkConfigs[1], candidate);
+ WifiNetworkSelectorTestUtil.verifySelectedScanResult(mWifiConfigManager,
+ scanResults[1], candidate);
+ assertEquals(meteredHints[1], candidate.meteredHint);
+ }
+
+ /**
+ * Between two externally scored saved networks with the same RSSI, choose
+ * the currently connected one.
+ */
+ @Test
+ public void chooseActiveSavedNetwork() {
+ String[] ssids = {"\"test1\"", "\"test2\""};
+ String[] bssids = {"6c:f3:7f:ae:8c:f3", "6c:f3:7f:ae:8c:f4"};
+ int[] freqs = {2470, 2437};
+ String[] caps = {"[WPA2-EAP-CCMP][ESS]", "[WPA2-EAP-CCMP][ESS]"};
+ int[] securities = {SECURITY_PSK, SECURITY_PSK};
+ int[] levels = {mThresholdQualifiedRssi2G + 28, mThresholdQualifiedRssi2G + 28};
+ boolean[] meteredHints = {false, false};
+
+ ScanDetailsAndWifiConfigs scanDetailsAndConfigs =
+ WifiNetworkSelectorTestUtil.setupScanDetailsAndConfigStore(ssids, bssids,
+ freqs, caps, levels, securities, mWifiConfigManager, mClock);
+ List<ScanDetail> scanDetails = scanDetailsAndConfigs.getScanDetails();
+ WifiConfiguration[] savedConfigs = scanDetailsAndConfigs.getWifiConfigs();
+ savedConfigs[0].useExternalScores = savedConfigs[1].useExternalScores = true;
+
+ WifiNetworkSelectorTestUtil.configureScoreCache(mScoreCache,
+ scanDetails, null, meteredHints);
+
+ WifiConfiguration candidate = mExternalScoreEvaluator.evaluateNetworks(scanDetails,
+ savedConfigs[1], bssids[1], true, true, null);
+
+ WifiConfigurationTestUtil.assertConfigurationEqual(savedConfigs[1], candidate);
+ WifiNetworkSelectorTestUtil.verifySelectedScanResult(mWifiConfigManager,
+ scanDetails.get(1).getScanResult(), candidate);
+ }
}
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTestUtil.java b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTestUtil.java
index db3aff14c..e01af28b1 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTestUtil.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTestUtil.java
@@ -309,17 +309,24 @@ public class WifiNetworkSelectorTestUtil {
for (int i = 0; i < scanDetails.size(); i++) {
ScanDetail scanDetail = scanDetails.get(i);
- byte rssiScore;
- Integer score = scores[i];
ScanResult scanResult = scanDetail.getScanResult();
WifiKey wifiKey = new WifiKey("\"" + scanResult.SSID + "\"", scanResult.BSSID);
NetworkKey ntwkKey = new NetworkKey(wifiKey);
- if (scores[i] == null) {
- rssiScore = WifiNetworkScoreCache.INVALID_NETWORK_SCORE;
+ RssiCurve rssiCurve;
+
+ if (scores != null) { // fixed score
+ byte rssiScore;
+ Integer score = scores[i];
+
+ if (scores[i] == null) {
+ rssiScore = WifiNetworkScoreCache.INVALID_NETWORK_SCORE;
+ } else {
+ rssiScore = scores[i].byteValue();
+ }
+ rssiCurve = new RssiCurve(-100, 100, new byte[] {rssiScore});
} else {
- rssiScore = scores[i].byteValue();
+ rssiCurve = new RssiCurve(-80, 20, new byte[] {-10, 0, 10, 20, 30, 40});
}
- RssiCurve rssiCurve = new RssiCurve(-100, 100, new byte[] {rssiScore});
ScoredNetwork scoredNetwork = new ScoredNetwork(ntwkKey, rssiCurve, meteredHints[i]);
networks.add(scoredNetwork);