diff options
author | Stephen Chen <stewchen@google.com> | 2017-07-19 20:38:35 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2017-07-19 20:38:35 +0000 |
commit | 7246a9b3a1f20ab0fdb1ce532f36a2ab0e44fe2a (patch) | |
tree | 5ee95cd9b48ddb9aebab94b8df0d72fe0a394c8b /tests | |
parent | e15195bc7f5b8397fc2cdd8e41a9c8041a9296bf (diff) | |
parent | dad9e0f432c92d88c26ea3e6bf4d01fa82e7aac4 (diff) |
Merge "WifiNetworkSelector: cache filtered scan results" into oc-dr1-dev am: 9cffbf45e2
am: dad9e0f432
Change-Id: I93db4e87c002d9f3c66e4e642ff0838a78082444
Diffstat (limited to 'tests')
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTest.java | 156 |
1 files changed, 154 insertions, 2 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTest.java b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTest.java index e5f697885..fee9033ae 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTest.java @@ -42,6 +42,7 @@ import org.junit.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; +import java.util.ArrayList; import java.util.HashSet; import java.util.List; @@ -64,6 +65,7 @@ public class WifiNetworkSelectorTest { mWifiNetworkSelector = new WifiNetworkSelector(mContext, mWifiConfigManager, mClock, mLocalLog); mWifiNetworkSelector.registerNetworkEvaluator(mDummyEvaluator, 1); + mDummyEvaluator.setEvaluatorToSelectCandidate(true); when(mClock.getElapsedSinceBootMillis()).thenReturn(SystemClock.elapsedRealtime()); mThresholdMinimumRssi2G = mResource.getInteger( @@ -93,6 +95,8 @@ public class WifiNetworkSelectorTest { public class DummyNetworkEvaluator implements WifiNetworkSelector.NetworkEvaluator { private static final String NAME = "DummyNetworkEvaluator"; + private boolean mEvaluatorShouldSelectCandidate = true; + @Override public String getName() { return NAME; @@ -102,13 +106,27 @@ public class WifiNetworkSelectorTest { public void update(List<ScanDetail> scanDetails) {} /** - * Always return the first network in the scan results for connection. + * Sets whether the evaluator should return a candidate for connection or null. + */ + public void setEvaluatorToSelectCandidate(boolean shouldSelectCandidate) { + mEvaluatorShouldSelectCandidate = shouldSelectCandidate; + } + + /** + * This NetworkEvaluator can be configured to return a candidate or null. If returning a + * candidate, the first entry in the provided scanDetails will be selected. This requires + * that the mock WifiConfigManager be set up to return a WifiConfiguration for the first + * scanDetail entry, through + * {@link WifiNetworkSelectorTestUtil#setupScanDetailsAndConfigStore}. */ @Override public WifiConfiguration evaluateNetworks(List<ScanDetail> scanDetails, WifiConfiguration currentNetwork, String currentBssid, boolean connected, boolean untrustedNetworkAllowed, List<Pair<ScanDetail, WifiConfiguration>> connectableNetworks) { + if (!mEvaluatorShouldSelectCandidate) { + return null; + } ScanDetail scanDetail = scanDetails.get(0); mWifiConfigManager.setNetworkCandidateScanResult(0, scanDetail.getScanResult(), 100); @@ -200,6 +218,7 @@ public class WifiNetworkSelectorTest { WifiConfiguration candidate = mWifiNetworkSelector.selectNetwork(scanDetails, blacklist, mWifiInfo, false, true, false); assertEquals("Expect null configuration", null, candidate); + assertTrue(mWifiNetworkSelector.getConnectableScanDetails().isEmpty()); } @@ -229,6 +248,7 @@ public class WifiNetworkSelectorTest { WifiConfiguration candidate = mWifiNetworkSelector.selectNetwork(scanDetails, blacklist, mWifiInfo, false, true, false); assertEquals("Expect null configuration", null, candidate); + assertTrue(mWifiNetworkSelector.getConnectableScanDetails().isEmpty()); } /** @@ -267,6 +287,7 @@ public class WifiNetworkSelectorTest { blacklist, mWifiInfo, true, false, false); assertEquals("Expect null configuration", null, candidate); + assertTrue(mWifiNetworkSelector.getConnectableScanDetails().isEmpty()); } /** @@ -431,6 +452,7 @@ public class WifiNetworkSelectorTest { WifiConfiguration candidate = mWifiNetworkSelector.selectNetwork(scanDetails, blacklist, mWifiInfo, false, true, false); assertEquals("Expect null configuration", null, candidate); + assertTrue(mWifiNetworkSelector.getConnectableScanDetails().isEmpty()); } /** @@ -483,6 +505,7 @@ public class WifiNetworkSelectorTest { // The second network selection is skipped since current connected network is // missing from the scan results. assertEquals("Expect null configuration", null, candidate); + assertTrue(mWifiNetworkSelector.getConnectableScanDetails().isEmpty()); } /** @@ -682,7 +705,7 @@ public class WifiNetworkSelectorTest { // Make a network selection to connect to test1. ScanDetailsAndWifiConfigs scanDetailsAndConfigs = WifiNetworkSelectorTestUtil.setupScanDetailsAndConfigStore(ssids, bssids, - freqs, caps, levels, securities, mWifiConfigManager, mClock); + freqs, caps, levels, securities, mWifiConfigManager, mClock); List<ScanDetail> scanDetails = scanDetailsAndConfigs.getScanDetails(); HashSet<String> blacklist = new HashSet<String>(); WifiConfiguration candidate = mWifiNetworkSelector.selectNetwork(scanDetails, @@ -708,4 +731,133 @@ public class WifiNetworkSelectorTest { expectedResult, candidate); } } + + /** + * {@link WifiNetworkSelector#getFilteredScanDetailsForOpenUnsavedNetworks()} should filter out + * networks that are not open after network selection is made. + * + * Expected behavior: return open networks only + */ + @Test + public void getfilterOpenUnsavedNetworks_filtersForOpenNetworks() { + String[] ssids = {"\"test1\"", "\"test2\""}; + String[] bssids = {"6c:f3:7f:ae:8c:f3", "6c:f3:7f:ae:8c:f4"}; + int[] freqs = {2437, 5180}; + String[] caps = {"[WPA2-EAP-CCMP][ESS]", "[ESS]"}; + int[] levels = {mThresholdMinimumRssi2G + 1, mThresholdMinimumRssi5G + 1}; + mDummyEvaluator.setEvaluatorToSelectCandidate(false); + + List<ScanDetail> scanDetails = WifiNetworkSelectorTestUtil.buildScanDetails( + ssids, bssids, freqs, caps, levels, mClock); + HashSet<String> blacklist = new HashSet<>(); + + mWifiNetworkSelector.selectNetwork(scanDetails, blacklist, mWifiInfo, false, true, false); + List<ScanDetail> expectedOpenUnsavedNetworks = new ArrayList<>(); + expectedOpenUnsavedNetworks.add(scanDetails.get(1)); + assertEquals("Expect open unsaved networks", + expectedOpenUnsavedNetworks, + mWifiNetworkSelector.getFilteredScanDetailsForOpenUnsavedNetworks()); + } + + /** + * {@link WifiNetworkSelector#getFilteredScanDetailsForOpenUnsavedNetworks()} should filter out + * saved networks after network selection is made. This should return an empty list when there + * are no unsaved networks available. + * + * Expected behavior: return unsaved networks only. Return empty list if there are no unsaved + * networks. + */ + @Test + public void getfilterOpenUnsavedNetworks_filtersOutSavedNetworks() { + String[] ssids = {"\"test1\""}; + String[] bssids = {"6c:f3:7f:ae:8c:f3"}; + int[] freqs = {2437, 5180}; + String[] caps = {"[ESS]"}; + int[] levels = {mThresholdMinimumRssi2G + 1}; + int[] securities = {SECURITY_NONE}; + mDummyEvaluator.setEvaluatorToSelectCandidate(false); + + List<ScanDetail> unSavedScanDetails = WifiNetworkSelectorTestUtil.buildScanDetails( + ssids, bssids, freqs, caps, levels, mClock); + HashSet<String> blacklist = new HashSet<>(); + + mWifiNetworkSelector.selectNetwork( + unSavedScanDetails, blacklist, mWifiInfo, false, true, false); + assertEquals("Expect open unsaved networks", + unSavedScanDetails, + mWifiNetworkSelector.getFilteredScanDetailsForOpenUnsavedNetworks()); + + ScanDetailsAndWifiConfigs scanDetailsAndConfigs = + WifiNetworkSelectorTestUtil.setupScanDetailsAndConfigStore(ssids, bssids, + freqs, caps, levels, securities, mWifiConfigManager, mClock); + List<ScanDetail> savedScanDetails = scanDetailsAndConfigs.getScanDetails(); + + mWifiNetworkSelector.selectNetwork( + savedScanDetails, blacklist, mWifiInfo, false, true, false); + // Saved networks are filtered out. + assertTrue(mWifiNetworkSelector.getFilteredScanDetailsForOpenUnsavedNetworks().isEmpty()); + } + + /** + * {@link WifiNetworkSelector#getFilteredScanDetailsForOpenUnsavedNetworks()} should filter out + * bssid blacklisted networks. + * + * Expected behavior: do not return blacklisted network + */ + @Test + public void getfilterOpenUnsavedNetworks_filtersOutBlacklistedNetworks() { + String[] ssids = {"\"test1\"", "\"test2\""}; + String[] bssids = {"6c:f3:7f:ae:8c:f3", "6c:f3:7f:ae:8c:f4"}; + int[] freqs = {2437, 5180}; + String[] caps = {"[ESS]", "[ESS]"}; + int[] levels = {mThresholdMinimumRssi2G + 1, mThresholdMinimumRssi5G + 1}; + mDummyEvaluator.setEvaluatorToSelectCandidate(false); + + List<ScanDetail> scanDetails = WifiNetworkSelectorTestUtil.buildScanDetails( + ssids, bssids, freqs, caps, levels, mClock); + HashSet<String> blacklist = new HashSet<>(); + blacklist.add(bssids[0]); + + mWifiNetworkSelector.selectNetwork(scanDetails, blacklist, mWifiInfo, false, true, false); + List<ScanDetail> expectedOpenUnsavedNetworks = new ArrayList<>(); + expectedOpenUnsavedNetworks.add(scanDetails.get(1)); + assertEquals("Expect open unsaved networks", + expectedOpenUnsavedNetworks, + mWifiNetworkSelector.getFilteredScanDetailsForOpenUnsavedNetworks()); + } + + /** + * {@link WifiNetworkSelector#getFilteredScanDetailsForOpenUnsavedNetworks()} should return + * empty list when there are no open networks after network selection is made. + * + * Expected behavior: return empty list + */ + @Test + public void getfilterOpenUnsavedNetworks_returnsEmptyListWhenNoOpenNetworksPresent() { + String[] ssids = {"\"test1\"", "\"test2\""}; + String[] bssids = {"6c:f3:7f:ae:8c:f3", "6c:f3:7f:ae:8c:f4"}; + int[] freqs = {2437, 5180}; + String[] caps = {"[WPA2-EAP-CCMP][ESS]", "[WPA2-EAP-CCMP][ESS]"}; + int[] levels = {mThresholdMinimumRssi2G + 1, mThresholdMinimumRssi5G + 1}; + mDummyEvaluator.setEvaluatorToSelectCandidate(false); + + List<ScanDetail> scanDetails = WifiNetworkSelectorTestUtil.buildScanDetails( + ssids, bssids, freqs, caps, levels, mClock); + HashSet<String> blacklist = new HashSet<>(); + + mWifiNetworkSelector.selectNetwork(scanDetails, blacklist, mWifiInfo, false, true, false); + assertTrue(mWifiNetworkSelector.getFilteredScanDetailsForOpenUnsavedNetworks().isEmpty()); + } + + /** + * {@link WifiNetworkSelector#getFilteredScanDetailsForOpenUnsavedNetworks()} should return + * empty list when no network selection has been made. + * + * Expected behavior: return empty list + */ + @Test + public void getfilterOpenUnsavedNetworks_returnsEmptyListWhenNoNetworkSelectionMade() { + assertTrue(mWifiNetworkSelector.getFilteredScanDetailsForOpenUnsavedNetworks().isEmpty()); + } } + |