summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorNate Jiang <qiangjiang@google.com>2020-03-12 06:09:02 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2020-03-12 06:09:02 +0000
commit12018ef87a4854f7c9eac62bfade064ec20759cd (patch)
tree3d26d4a118913bda8e1ab8163dfe79d997fe131d /tests
parent2e8ff52fe705cf03ef1fcdf2652420c83956e08d (diff)
parent2a2cdc4e2db465bdcdd30bae9fbe245f0d1f0839 (diff)
Merge "Only nominate untrusted network when allowed" into rvc-dev
Diffstat (limited to 'tests')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/NetworkSuggestionNominatorTest.java91
1 files changed, 89 insertions, 2 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/NetworkSuggestionNominatorTest.java b/tests/wifitests/src/com/android/server/wifi/NetworkSuggestionNominatorTest.java
index 82925a43f..ff1b35261 100644
--- a/tests/wifitests/src/com/android/server/wifi/NetworkSuggestionNominatorTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/NetworkSuggestionNominatorTest.java
@@ -854,6 +854,93 @@ public class NetworkSuggestionNominatorTest extends WifiBaseTest {
verifyAddToWifiConfigManager(suggestions[0].wns.wifiConfiguration);
}
+ /**
+ * Ensure that we nominate the no matching network suggestion.
+ * Because the only matched suggestion is untrusted and untrusted is not allowed
+ * Expected connectable Networks: {}
+ */
+ @Test
+ public void testSelectNetworkSuggestionForOneMatchUntrustedNotAllow() {
+ String[] scanSsids = {"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[] levels = {-67, -76};
+ String[] suggestionSsids = {"\"" + scanSsids[0] + "\""};
+ int[] securities = {SECURITY_PSK};
+ boolean[] appInteractions = {true};
+ boolean[] meteredness = {true};
+ int[] priorities = {-1};
+ int[] uids = {TEST_UID};
+ String[] packageNames = {TEST_PACKAGE};
+ boolean[] autojoin = {true};
+ boolean[] shareWithUser = {true};
+
+ ScanDetail[] scanDetails =
+ buildScanDetails(scanSsids, bssids, freqs, caps, levels, mClock);
+ ExtendedWifiNetworkSuggestion[] suggestions = buildNetworkSuggestions(suggestionSsids,
+ securities, appInteractions, meteredness, priorities, uids,
+ packageNames, autojoin, shareWithUser);
+ suggestions[0].wns.wifiConfiguration.trusted = false;
+ // Link the scan result with suggestions.
+ linkScanDetailsWithNetworkSuggestions(scanDetails, suggestions);
+
+ List<Pair<ScanDetail, WifiConfiguration>> connectableNetworks = new ArrayList<>();
+ mNetworkSuggestionNominator.nominateNetworks(
+ Arrays.asList(scanDetails), null, null, true, false,
+ (ScanDetail scanDetail, WifiConfiguration configuration) -> {
+ connectableNetworks.add(Pair.create(scanDetail, configuration));
+ });
+
+ assertTrue(connectableNetworks.isEmpty());
+ }
+
+ /**
+ * Ensure that we nominate the one matching network suggestion.
+ * Because the only matched suggestion is untrusted and untrusted is allowed
+ * Expected connectable Networks: {suggestionSsids[0]}
+ */
+ @Test
+ public void testSelectNetworkSuggestionForOneMatchUntrustedAllow() {
+ String[] scanSsids = {"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[] levels = {-67, -76};
+ String[] suggestionSsids = {"\"" + scanSsids[0] + "\""};
+ int[] securities = {SECURITY_PSK};
+ boolean[] appInteractions = {true};
+ boolean[] meteredness = {true};
+ int[] priorities = {-1};
+ int[] uids = {TEST_UID};
+ String[] packageNames = {TEST_PACKAGE};
+ boolean[] autojoin = {true};
+ boolean[] shareWithUser = {true};
+
+ ScanDetail[] scanDetails =
+ buildScanDetails(scanSsids, bssids, freqs, caps, levels, mClock);
+ ExtendedWifiNetworkSuggestion[] suggestions = buildNetworkSuggestions(suggestionSsids,
+ securities, appInteractions, meteredness, priorities, uids,
+ packageNames, autojoin, shareWithUser);
+ suggestions[0].wns.wifiConfiguration.trusted = false;
+ // Link the scan result with suggestions.
+ linkScanDetailsWithNetworkSuggestions(scanDetails, suggestions);
+
+ setupAddToWifiConfigManager(suggestions[0].wns.wifiConfiguration);
+
+ List<Pair<ScanDetail, WifiConfiguration>> connectableNetworks = new ArrayList<>();
+ mNetworkSuggestionNominator.nominateNetworks(
+ Arrays.asList(scanDetails), null, null, true, true,
+ (ScanDetail scanDetail, WifiConfiguration configuration) -> {
+ connectableNetworks.add(Pair.create(scanDetail, configuration));
+ });
+
+
+ validateConnectableNetworks(connectableNetworks, scanSsids[0]);
+
+ verifyAddToWifiConfigManager(suggestions[0].wns.wifiConfiguration);
+ }
+
private void setupAddToWifiConfigManager(WifiConfiguration...candidates) {
for (int i = 0; i < candidates.length; i++) {
WifiConfiguration candidate = candidates[i];
@@ -914,7 +1001,7 @@ public class NetworkSuggestionNominatorTest extends WifiBaseTest {
* Build an array of scanDetails based on the caller supplied network SSID, BSSID,
* frequency, capability and RSSI level information.
*/
- public static ScanDetail[] buildScanDetails(String[] ssids, String[] bssids, int[] freqs,
+ private static ScanDetail[] buildScanDetails(String[] ssids, String[] bssids, int[] freqs,
String[] caps, int[] levels, Clock clock) {
if (ssids == null || ssids.length == 0) return new ScanDetail[0];
@@ -931,7 +1018,7 @@ public class NetworkSuggestionNominatorTest extends WifiBaseTest {
* Generate an array of {@link android.net.wifi.WifiConfiguration} based on the caller
* supplied network SSID and security information.
*/
- public static WifiConfiguration[] buildWifiConfigurations(String[] ssids, int[] securities) {
+ private static WifiConfiguration[] buildWifiConfigurations(String[] ssids, int[] securities) {
if (ssids == null || ssids.length == 0) return new WifiConfiguration[0];
WifiConfiguration[] configs = new WifiConfiguration[ssids.length];