summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorNate Jiang <qiangjiang@google.com>2020-03-13 16:33:18 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2020-03-13 16:33:18 +0000
commita6ae5dbcd85ed2336d0ec5a35de96df9b290bf14 (patch)
treedd6906cb695ae8f7461ea7d1bf5c42e9b2d520c1 /tests
parent5e1e7aa6a606e55570608ea0c089e3b55381eb27 (diff)
parent5ef3baddf4c4a558200bf8d7abe4c726db607734 (diff)
Merge "Ignore metered network from Non-data Sim" into rvc-dev
Diffstat (limited to 'tests')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/NetworkSuggestionNominatorTest.java42
-rw-r--r--tests/wifitests/src/com/android/server/wifi/SavedNetworkNominatorTest.java29
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java5
-rw-r--r--tests/wifitests/src/com/android/server/wifi/util/TelephonyUtilTest.java10
4 files changed, 85 insertions, 1 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/NetworkSuggestionNominatorTest.java b/tests/wifitests/src/com/android/server/wifi/NetworkSuggestionNominatorTest.java
index ff1b35261..643678c8b 100644
--- a/tests/wifitests/src/com/android/server/wifi/NetworkSuggestionNominatorTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/NetworkSuggestionNominatorTest.java
@@ -941,6 +941,48 @@ 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 testSelectNetworkSuggestionForOneMatchMeteredNonDataSim() {
+ 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.meteredHint = true;
+ when(mTelephonyUtil.isCarrierNetworkFromNonDefaultDataSim(any())).thenReturn(true);
+ // 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());
+ }
+
private void setupAddToWifiConfigManager(WifiConfiguration...candidates) {
for (int i = 0; i < candidates.length; i++) {
WifiConfiguration candidate = candidates[i];
diff --git a/tests/wifitests/src/com/android/server/wifi/SavedNetworkNominatorTest.java b/tests/wifitests/src/com/android/server/wifi/SavedNetworkNominatorTest.java
index 7bd6a06c9..1a56fbbd9 100644
--- a/tests/wifitests/src/com/android/server/wifi/SavedNetworkNominatorTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/SavedNetworkNominatorTest.java
@@ -54,7 +54,8 @@ public class SavedNetworkNominatorTest extends WifiBaseTest {
mLocalLog = new LocalLog(512);
mSavedNetworkNominator = new SavedNetworkNominator(mWifiConfigManager,
mPasspointNetworkNominateHelper, mLocalLog, mTelephonyUtil);
-
+ when(mTelephonyUtil.isSimPresent(anyInt())).thenReturn(true);
+ when(mTelephonyUtil.getBestMatchSubscriptionId(any())).thenReturn(1);
}
/** Cleans up test. */
@@ -233,4 +234,30 @@ public class SavedNetworkNominatorTest extends WifiBaseTest {
false, false, mOnConnectableListener);
verify(mOnConnectableListener).onConnectable(scanDetail, configuration);
}
+
+ /**
+ * Verify if a network is metered and with non-data sim, will not nominate as a candidate.
+ */
+ @Test
+ public void ignoreNetworksIfMeteredAndFromNonDataSim() {
+ String[] ssids = {"\"test1\""};
+ String[] bssids = {"6c:f3:7f:ae:8c:f3"};
+ int[] freqs = {2470};
+ int[] levels = {RSSI_LEVEL};
+
+ ScanDetailsAndWifiConfigs scanDetailsAndConfigs =
+ WifiNetworkSelectorTestUtil.setupScanDetailsAndConfigForEapSimNetwork(ssids, bssids,
+ freqs, levels, mWifiConfigManager, mClock);
+ List<ScanDetail> scanDetails = scanDetailsAndConfigs.getScanDetails();
+ WifiConfiguration[] savedConfigs = scanDetailsAndConfigs.getWifiConfigs();
+ when(mTelephonyUtil.isCarrierNetworkFromNonDefaultDataSim(savedConfigs[0]))
+ .thenReturn(false);
+ mSavedNetworkNominator.nominateNetworks(scanDetails,
+ null, null, true, false, mOnConnectableListener);
+ verify(mOnConnectableListener).onConnectable(any(), any());
+ reset(mOnConnectableListener);
+ when(mTelephonyUtil.isCarrierNetworkFromNonDefaultDataSim(savedConfigs[0]))
+ .thenReturn(true);
+ verify(mOnConnectableListener, never()).onConnectable(any(), any());
+ }
}
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java
index 90dd4574d..fc5d06fa0 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java
@@ -2965,6 +2965,11 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest {
mWifiNetworkSuggestionsManager.setHasUserApprovedForApp(true, TEST_PACKAGE_1);
assertTrue(mWifiNetworkSuggestionsManager
.isPasspointSuggestionSharedWithUser(dummyConfiguration));
+ dummyConfiguration.meteredHint = true;
+ when(mTelephonyUtil.isCarrierNetworkFromNonDefaultDataSim(dummyConfiguration))
+ .thenReturn(true);
+ assertFalse(mWifiNetworkSuggestionsManager
+ .isPasspointSuggestionSharedWithUser(dummyConfiguration));
}
/**
diff --git a/tests/wifitests/src/com/android/server/wifi/util/TelephonyUtilTest.java b/tests/wifitests/src/com/android/server/wifi/util/TelephonyUtilTest.java
index 854596105..a07dafb6d 100644
--- a/tests/wifitests/src/com/android/server/wifi/util/TelephonyUtilTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/util/TelephonyUtilTest.java
@@ -1403,4 +1403,14 @@ public class TelephonyUtilTest extends WifiBaseTest {
assertEquals(CARRIER_NAME, mTelephonyUtil.getCarrierNameforSubId(DATA_SUBID));
assertNull(mTelephonyUtil.getCarrierNameforSubId(NON_DATA_SUBID));
}
+
+ @Test
+ public void testIsCarrierNetworkFromNonDataSim() {
+ WifiConfiguration config = new WifiConfiguration();
+ assertFalse(mTelephonyUtil.isCarrierNetworkFromNonDefaultDataSim(config));
+ config.carrierId = DATA_CARRIER_ID;
+ assertFalse(mTelephonyUtil.isCarrierNetworkFromNonDefaultDataSim(config));
+ config.carrierId = NON_DATA_CARRIER_ID;
+ assertTrue(mTelephonyUtil.isCarrierNetworkFromNonDefaultDataSim(config));
+ }
}