summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorNate Jiang <qiangjiang@google.com>2019-12-10 02:34:07 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2019-12-10 02:34:07 +0000
commit47fc6c5f3eb6ba273c3f04890971a63c31324996 (patch)
tree57c9b66c1cf0f55d71e1145f3fe276dc7516f583 /tests
parentf05e2f3f34b31061c22e5ceaed861a4e9f97a69d (diff)
parent3fe95912af8f17c5964a607aa9133c3f87bbe920 (diff)
Merge changes Ic33d2d48,Ic40a0e39,I96ef09f5,I996dd19a
* changes: [passpoint] match the best scanDetail to the provider allows multiple passpoint candidates rename evaluator to nominator [Evaluator] evaluator will only nominate candidates
Diffstat (limited to 'tests')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/CarrierNetworkNominatorTest.java (renamed from tests/wifitests/src/com/android/server/wifi/CarrierNetworkEvaluatorTest.java)62
-rw-r--r--tests/wifitests/src/com/android/server/wifi/ConcreteCandidate.java8
-rw-r--r--tests/wifitests/src/com/android/server/wifi/NetworkSuggestionNominatorTest.java (renamed from tests/wifitests/src/com/android/server/wifi/NetworkSuggestionEvaluatorTest.java)144
-rw-r--r--tests/wifitests/src/com/android/server/wifi/SavedNetworkEvaluatorTest.java651
-rw-r--r--tests/wifitests/src/com/android/server/wifi/SavedNetworkNominatorTest.java216
-rw-r--r--tests/wifitests/src/com/android/server/wifi/ScoredNetworkNominatorTest.java (renamed from tests/wifitests/src/com/android/server/wifi/ScoredNetworkEvaluatorTest.java)345
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiCandidatesTest.java19
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java5
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTest.java200
-rw-r--r--tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java66
-rw-r--r--tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointNetworkNominatorTest.java (renamed from tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointNetworkEvaluatorTest.java)317
11 files changed, 647 insertions, 1386 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/CarrierNetworkEvaluatorTest.java b/tests/wifitests/src/com/android/server/wifi/CarrierNetworkNominatorTest.java
index 447cdc2d8..bf576be14 100644
--- a/tests/wifitests/src/com/android/server/wifi/CarrierNetworkEvaluatorTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/CarrierNetworkNominatorTest.java
@@ -17,7 +17,6 @@
package com.android.server.wifi;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
@@ -58,7 +57,7 @@ import java.util.Map;
* Unit tests for CarrierNeteworkEvaluator
*/
@SmallTest
-public class CarrierNetworkEvaluatorTest extends WifiBaseTest {
+public class CarrierNetworkNominatorTest extends WifiBaseTest {
private static final String CARRIER1_SSID = "\"carrier1\"";
private static final String CARRIER2_SSID = "\"carrier2\"";
private static final String CARRIER_SAVED_SSID = "\"carrier3-saved\"";
@@ -72,13 +71,13 @@ public class CarrierNetworkEvaluatorTest extends WifiBaseTest {
private static final int CARRIER_SAVED_EPH_NET_ID = 4;
private static final int NON_CARRIER_NET_ID = 5;
- private CarrierNetworkEvaluator mDut;
+ private CarrierNetworkNominator mDut;
@Mock private WifiConfigManager mWifiConfigManager;
@Mock private CarrierNetworkConfig mCarrierNetworkConfig;
@Mock private LocalLog mLocalLog;
@Mock private Clock mClock;
- @Mock private WifiNetworkSelector.NetworkEvaluator.OnConnectableListener mConnectableListener;
+ @Mock private WifiNetworkSelector.NetworkNominator.OnConnectableListener mConnectableListener;
@Mock private WifiInjector mWifiInjector;
@Mock private TelephonyManager mTelephonyManager;
@Mock private TelephonyManager mDataTelephonyManager;
@@ -156,7 +155,7 @@ public class CarrierNetworkEvaluatorTest extends WifiBaseTest {
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
- mDut = new CarrierNetworkEvaluator(mWifiConfigManager, mCarrierNetworkConfig, mLocalLog,
+ mDut = new CarrierNetworkNominator(mWifiConfigManager, mCarrierNetworkConfig, mLocalLog,
mWifiInjector);
when(mWifiInjector.makeTelephonyManager()).thenReturn(mTelephonyManager);
@@ -199,13 +198,8 @@ public class CarrierNetworkEvaluatorTest extends WifiBaseTest {
}
/**
- * Baseline positive test case: carrier Wi-Fi enabled (have cert), present >1 Carrier networks
- * of varying RSSI, include some none carrier networks with even better RSSI and some saved
- * carrier networks (one of which is ephemeral).
- *
* Desired behavior:
* - all Carrier Wi-Fi (including all saved networks) as connectable
- * - best Carrier Wi-Fi (highest RSSI) as return value
*/
@Test
public void testSelectOneFromMultiple() {
@@ -226,11 +220,11 @@ public class CarrierNetworkEvaluatorTest extends WifiBaseTest {
configureNewSsid(CARRIER_SAVED_EPH_NET_ID, scanDetails.get(3), true, false);
configureNewSsid(NON_CARRIER_NET_ID, scanDetails.get(4), false, true);
- WifiConfiguration selected = mDut.evaluateNetworks(scanDetails, null, null, false, false,
+ mDut.nominateNetworks(scanDetails, null, null, false, false,
mConnectableListener);
verify(mConnectableListener, times(4)).onConnectable(mScanDetailCaptor.capture(),
- mWifiConfigCaptor.capture(), anyInt());
+ mWifiConfigCaptor.capture());
assertEquals(4, mScanDetailCaptor.getAllValues().size());
assertEquals(CARRIER1_SSID.replace("\"", ""),
@@ -260,16 +254,12 @@ public class CarrierNetworkEvaluatorTest extends WifiBaseTest {
assertEquals(CARRIER_SAVED_EPH_SSID, config4.SSID);
assertTrue(config4.isEphemeral());
assertTrue(config4.allowedKeyManagement.get(WifiConfiguration.KeyMgmt.WPA_EAP));
-
- assertEquals(config2.getKey(), selected.getKey()); // SSID2 has the highest RSSI
- assertEquals("", selected.enterpriseConfig.getAnonymousIdentity());
- assertTrue(TelephonyUtil.isSimEapMethod(selected.enterpriseConfig.getEapMethod()));
}
/**
* Cert installed and no Carrier Wi-Fi visible
*
- * Desired behavior: no networks connectable or selected
+ * Desired behavior: no networks connectable.
*/
@Test
public void testSelectFromNoneAvailable() {
@@ -283,17 +273,16 @@ public class CarrierNetworkEvaluatorTest extends WifiBaseTest {
freqs, caps, levels, mClock);
configureNewSsid(NON_CARRIER_NET_ID, scanDetails.get(0), false, true);
- WifiConfiguration selected = mDut.evaluateNetworks(scanDetails, null, null, false, false,
+ mDut.nominateNetworks(scanDetails, null, null, false, false,
mConnectableListener);
- verify(mConnectableListener, never()).onConnectable(any(), any(), anyInt());
- assertNull(selected);
+ verify(mConnectableListener, never()).onConnectable(any(), any());
}
/**
* Multiple carrier Wi-Fi networks visible but no cert installed.
*
- * Desired behavior: no networks connectable or selected
+ * Desired behavior: no networks connectable.
*/
@Test
public void testNoCarrierCert() {
@@ -316,18 +305,17 @@ public class CarrierNetworkEvaluatorTest extends WifiBaseTest {
configureNewSsid(CARRIER_SAVED_EPH_NET_ID, scanDetails.get(3), true, false);
configureNewSsid(NON_CARRIER_NET_ID, scanDetails.get(4), false, true);
- WifiConfiguration selected = mDut.evaluateNetworks(scanDetails, null, null, false, false,
+ mDut.nominateNetworks(scanDetails, null, null, false, false,
mConnectableListener);
- verify(mConnectableListener, never()).onConnectable(any(), any(), anyInt());
- assertNull(selected);
+ verify(mConnectableListener, never()).onConnectable(any(), any());
}
/**
* One carrier Wi-Fi networks visible and cert installed but user has previously forgotten the
* network.
*
- * Desired behavior: no networks connectable or selected
+ * Desired behavior: no networks connectable.
*/
@Test
public void testAvailableButPreviouslyUserDeleted() {
@@ -345,17 +333,16 @@ public class CarrierNetworkEvaluatorTest extends WifiBaseTest {
freqs, caps, levels, mClock);
configureNewSsid(CARRIER1_NET_ID, scanDetails.get(0), true, false);
- WifiConfiguration selected = mDut.evaluateNetworks(scanDetails, null, null, false, false,
+ mDut.nominateNetworks(scanDetails, null, null, false, false,
mConnectableListener);
- verify(mConnectableListener, never()).onConnectable(any(), any(), anyInt());
- assertNull(selected);
+ verify(mConnectableListener, never()).onConnectable(any(), any());
}
/**
* One carrier Wi-Fi networks visible and cert installed but ssid is blacklisted.
*
- * Desired behavior: no networks connectable or selected
+ * Desired behavior: no networks connectable.
*/
@Test
public void testAvailableButBlacklisted() {
@@ -380,18 +367,17 @@ public class CarrierNetworkEvaluatorTest extends WifiBaseTest {
when(mWifiConfigManager.tryEnableNetwork(CARRIER1_NET_ID))
.thenReturn(false);
- WifiConfiguration selected = mDut.evaluateNetworks(scanDetails, null, null, false, false,
+ mDut.nominateNetworks(scanDetails, null, null, false, false,
mConnectableListener);
verify(mWifiConfigManager).getConfiguredNetwork(eq(blacklisted.getKey()));
- verify(mConnectableListener, never()).onConnectable(any(), any(), anyInt());
- assertNull(selected);
+ verify(mConnectableListener, never()).onConnectable(any(), any());
}
/**
* One carrier Wi-Fi network that is visible and supports encrypted IMSI.
*
- * Desired behavior: selected network supports encrypted IMSI by using EAP-SIM/AKA/AKA'
+ * Desired behavior: nominated network supports encrypted IMSI by using EAP-SIM/AKA/AKA'
* and has an empty anonymous identity. The anonymous identity will be populated with
* {@code anonymous@<realm>} by ClientModeImpl's handling of the
* {@link ClientModeImpl#CMD_START_CONNECT} event.
@@ -409,11 +395,13 @@ public class CarrierNetworkEvaluatorTest extends WifiBaseTest {
WifiConfiguration carrierConfig = configureNewSsid(CARRIER1_NET_ID, scanDetails.get(0),
true, false);
- WifiConfiguration selected = mDut.evaluateNetworks(scanDetails, null, null, false, false,
+ mDut.nominateNetworks(scanDetails, null, null, false, false,
mConnectableListener);
- assertEquals(carrierConfig.getKey(), selected.getKey());
- assertEquals("", selected.enterpriseConfig.getAnonymousIdentity());
- assertTrue(TelephonyUtil.isSimEapMethod(selected.enterpriseConfig.getEapMethod()));
+ verify(mConnectableListener).onConnectable(any(), mWifiConfigCaptor.capture());
+ assertEquals(carrierConfig.getKey(), mWifiConfigCaptor.getValue().getKey());
+ assertEquals("", mWifiConfigCaptor.getValue().enterpriseConfig.getAnonymousIdentity());
+ assertTrue(TelephonyUtil
+ .isSimEapMethod(mWifiConfigCaptor.getValue().enterpriseConfig.getEapMethod()));
}
}
diff --git a/tests/wifitests/src/com/android/server/wifi/ConcreteCandidate.java b/tests/wifitests/src/com/android/server/wifi/ConcreteCandidate.java
index 832daf30e..971ac3b4b 100644
--- a/tests/wifitests/src/com/android/server/wifi/ConcreteCandidate.java
+++ b/tests/wifitests/src/com/android/server/wifi/ConcreteCandidate.java
@@ -59,8 +59,8 @@ public final class ConcreteCandidate implements WifiCandidates.Candidate {
mIsEphemeral = candidate.isEphemeral();
mIsTrusted = candidate.isTrusted();
mIsMetered = candidate.isMetered();
- mEvaluatorId = candidate.getEvaluatorId();
- mEvaluatorScore = candidate.getEvaluatorScore();
+ mEvaluatorId = candidate.getNominatorId();
+ mEvaluatorScore = candidate.getNominatorScore();
mLastSelectionWeight = candidate.getLastSelectionWeight();
mScanRssi = candidate.getScanRssi();
mFrequency = candidate.getFrequency();
@@ -159,7 +159,7 @@ public final class ConcreteCandidate implements WifiCandidates.Candidate {
}
@Override
- public int getEvaluatorId() {
+ public int getNominatorId() {
return mEvaluatorId;
}
@@ -169,7 +169,7 @@ public final class ConcreteCandidate implements WifiCandidates.Candidate {
}
@Override
- public int getEvaluatorScore() {
+ public int getNominatorScore() {
return mEvaluatorScore;
}
diff --git a/tests/wifitests/src/com/android/server/wifi/NetworkSuggestionEvaluatorTest.java b/tests/wifitests/src/com/android/server/wifi/NetworkSuggestionNominatorTest.java
index b130ca794..c1e0e99fc 100644
--- a/tests/wifitests/src/com/android/server/wifi/NetworkSuggestionEvaluatorTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/NetworkSuggestionNominatorTest.java
@@ -16,6 +16,7 @@
package com.android.server.wifi;
+import static android.net.wifi.WifiConfiguration.INVALID_NETWORK_ID;
import static android.net.wifi.WifiConfiguration.NetworkSelectionStatus
.NETWORK_SELECTION_TEMPORARY_DISABLED;
@@ -50,10 +51,10 @@ import java.util.List;
import java.util.Set;
/**
- * Unit tests for {@link com.android.server.wifi.NetworkSuggestionEvaluator}.
+ * Unit tests for {@link NetworkSuggestionNominator}.
*/
@SmallTest
-public class NetworkSuggestionEvaluatorTest extends WifiBaseTest {
+public class NetworkSuggestionNominatorTest extends WifiBaseTest {
private static final int TEST_UID = 3555;
private static final int TEST_UID_OTHER = 3545;
private static final int TEST_NETWORK_ID = 55;
@@ -63,20 +64,19 @@ public class NetworkSuggestionEvaluatorTest extends WifiBaseTest {
private @Mock WifiConfigManager mWifiConfigManager;
private @Mock WifiNetworkSuggestionsManager mWifiNetworkSuggestionsManager;
private @Mock Clock mClock;
- private NetworkSuggestionEvaluator mNetworkSuggestionEvaluator;
+ private NetworkSuggestionNominator mNetworkSuggestionNominator;
/** Sets up test. */
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
- mNetworkSuggestionEvaluator = new NetworkSuggestionEvaluator(
+ mNetworkSuggestionNominator = new NetworkSuggestionNominator(
mWifiNetworkSuggestionsManager, mWifiConfigManager, new LocalLog(100));
}
/**
* Ensure that we ignore all scan results not matching the network suggestion.
- * Expected candidate: null
* Expected connectable Networks: {}
*/
@Test
@@ -102,19 +102,17 @@ public class NetworkSuggestionEvaluatorTest extends WifiBaseTest {
linkScanDetailsWithNetworkSuggestions(scanDetails, suggestions);
List<Pair<ScanDetail, WifiConfiguration>> connectableNetworks = new ArrayList<>();
- WifiConfiguration candidate = mNetworkSuggestionEvaluator.evaluateNetworks(
+ mNetworkSuggestionNominator.nominateNetworks(
Arrays.asList(scanDetails), null, null, true, false,
- (ScanDetail scanDetail, WifiConfiguration configuration, int score) -> {
+ (ScanDetail scanDetail, WifiConfiguration configuration) -> {
connectableNetworks.add(Pair.create(scanDetail, configuration));
});
- assertNull(candidate);
assertTrue(connectableNetworks.isEmpty());
}
/**
- * Ensure that we select the only matching network suggestion.
- * Expected candidate: suggestionSsids[0]
+ * Ensure that we nominate the only matching network suggestion.
* Expected connectable Networks: {suggestionSsids[0]}
*/
@Test
@@ -142,14 +140,12 @@ public class NetworkSuggestionEvaluatorTest extends WifiBaseTest {
setupAddToWifiConfigManager(suggestions[0].wns.wifiConfiguration);
List<Pair<ScanDetail, WifiConfiguration>> connectableNetworks = new ArrayList<>();
- WifiConfiguration candidate = mNetworkSuggestionEvaluator.evaluateNetworks(
+ mNetworkSuggestionNominator.nominateNetworks(
Arrays.asList(scanDetails), null, null, true, false,
- (ScanDetail scanDetail, WifiConfiguration configuration, int score) -> {
+ (ScanDetail scanDetail, WifiConfiguration configuration) -> {
connectableNetworks.add(Pair.create(scanDetail, configuration));
});
- assertNotNull(candidate);
- assertEquals(suggestionSsids[0] , candidate.SSID);
validateConnectableNetworks(connectableNetworks, scanSsids[0]);
@@ -157,9 +153,7 @@ public class NetworkSuggestionEvaluatorTest extends WifiBaseTest {
}
/**
- * Ensure that we select the network suggestion corresponding to the scan result with
- * highest RSSI.
- * Expected candidate: suggestionSsids[1]
+ * Ensure that we nominate the all network suggestion corresponding to the scan results
* Expected connectable Networks: {suggestionSsids[0], suggestionSsids[1]}
*/
@Test
@@ -188,15 +182,12 @@ public class NetworkSuggestionEvaluatorTest extends WifiBaseTest {
suggestions[1].wns.wifiConfiguration);
List<Pair<ScanDetail, WifiConfiguration>> connectableNetworks = new ArrayList<>();
- WifiConfiguration candidate = mNetworkSuggestionEvaluator.evaluateNetworks(
+ mNetworkSuggestionNominator.nominateNetworks(
Arrays.asList(scanDetails), null, null, true, false,
- (ScanDetail scanDetail, WifiConfiguration configuration, int score) -> {
+ (ScanDetail scanDetail, WifiConfiguration configuration) -> {
connectableNetworks.add(Pair.create(scanDetail, configuration));
});
- assertNotNull(candidate);
- assertEquals(suggestionSsids[1] , candidate.SSID);
-
validateConnectableNetworks(connectableNetworks, scanSsids[0], scanSsids[1]);
verifyAddToWifiConfigManager(suggestions[1].wns.wifiConfiguration,
@@ -204,10 +195,9 @@ public class NetworkSuggestionEvaluatorTest extends WifiBaseTest {
}
/**
- * Ensure that we select the network suggestion corresponding to the scan result with
+ * Ensure that we nominate the network suggestion corresponding to the scan result with
* higest priority.
- * Expected candidate: suggestionSsids[0]
- * Expected connectable Networks: {suggestionSsids[0], suggestionSsids[1]}
+ * Expected connectable Networks: {suggestionSsids[0]}
*/
@Test
public void testSelectNetworkSuggestionForMultipleMatchHighPriorityWins() {
@@ -235,26 +225,20 @@ public class NetworkSuggestionEvaluatorTest extends WifiBaseTest {
suggestions[1].wns.wifiConfiguration);
List<Pair<ScanDetail, WifiConfiguration>> connectableNetworks = new ArrayList<>();
- WifiConfiguration candidate = mNetworkSuggestionEvaluator.evaluateNetworks(
+ mNetworkSuggestionNominator.nominateNetworks(
Arrays.asList(scanDetails), null, null, true, false,
- (ScanDetail scanDetail, WifiConfiguration configuration, int score) -> {
+ (ScanDetail scanDetail, WifiConfiguration configuration) -> {
connectableNetworks.add(Pair.create(scanDetail, configuration));
});
- assertNotNull(candidate);
- assertEquals(suggestionSsids[0] , candidate.SSID);
-
validateConnectableNetworks(connectableNetworks, scanSsids[0]);
verifyAddToWifiConfigManager(suggestions[0].wns.wifiConfiguration);
}
/**
- * Ensure that we select the network suggestion corresponding to the scan result with
- * highest RSSI. The lower RSSI scan result has multiple matching suggestions
- * (should pick any one in the connectable networks).
+ * Ensure that we nominate one network when multiple suggestor suggested same network.
*
- * Expected candidate: suggestionSsids[0]
* Expected connectable Networks: {suggestionSsids[0],
* (suggestionSsids[1] || suggestionSsids[2]}
*/
@@ -285,15 +269,12 @@ public class NetworkSuggestionEvaluatorTest extends WifiBaseTest {
suggestions[1].wns.wifiConfiguration, suggestions[2].wns.wifiConfiguration);
List<Pair<ScanDetail, WifiConfiguration>> connectableNetworks = new ArrayList<>();
- WifiConfiguration candidate = mNetworkSuggestionEvaluator.evaluateNetworks(
+ mNetworkSuggestionNominator.nominateNetworks(
Arrays.asList(scanDetails), null, null, true, false,
- (ScanDetail scanDetail, WifiConfiguration configuration, int score) -> {
+ (ScanDetail scanDetail, WifiConfiguration configuration) -> {
connectableNetworks.add(Pair.create(scanDetail, configuration));
});
- assertNotNull(candidate);
- assertEquals(suggestionSsids[0] , candidate.SSID);
-
validateConnectableNetworks(connectableNetworks, scanSsids);
verifyAddToWifiConfigManager(suggestions[0].wns.wifiConfiguration,
@@ -301,14 +282,12 @@ public class NetworkSuggestionEvaluatorTest extends WifiBaseTest {
}
/**
- * Ensure that we select the network suggestion with the higest priority among network
- * suggestions from the same package. Among different packages, pick the suggestion
- * corresponding to the scan result with highest RSSI.
+ * Ensure that we nominate the network suggestion with the higest priority among network
+ * suggestions from the same package. Among different packages, nominate all the suggestion
+ * corresponding to the scan result.
*
- * The suggestion[1] has higher priority than suggestion[0] even though it has lower RSSI than
- * suggestion[0].
+ * The suggestion[1] has higher priority than suggestion[0].
*
- * Expected candidate: suggestionSsids[1]
* Expected connectable Networks: {suggestionSsids[1],
* (suggestionSsids[2],
* suggestionSsids[3]}
@@ -345,15 +324,12 @@ public class NetworkSuggestionEvaluatorTest extends WifiBaseTest {
suggestions[3].wns.wifiConfiguration);
List<Pair<ScanDetail, WifiConfiguration>> connectableNetworks = new ArrayList<>();
- WifiConfiguration candidate = mNetworkSuggestionEvaluator.evaluateNetworks(
+ mNetworkSuggestionNominator.nominateNetworks(
Arrays.asList(scanDetails), null, null, true, false,
- (ScanDetail scanDetail, WifiConfiguration configuration, int score) -> {
+ (ScanDetail scanDetail, WifiConfiguration configuration) -> {
connectableNetworks.add(Pair.create(scanDetail, configuration));
});
- assertNotNull(candidate);
- assertEquals(suggestionSsids[1] , candidate.SSID);
-
validateConnectableNetworks(connectableNetworks, scanSsids[1], scanSsids[2], scanSsids[3]);
verifyAddToWifiConfigManager(suggestions[1].wns.wifiConfiguration,
@@ -361,10 +337,10 @@ public class NetworkSuggestionEvaluatorTest extends WifiBaseTest {
}
/**
- * Ensure that we select the only matching network suggestion, but return null because
- * we failed the {@link WifiConfigManager} interactions.
- * Expected candidate: null.
- * Expected connectable Networks: {suggestionSsids[0], suggestionSsids[1]}
+ * Ensure that we nominate no candidate if the only matching network suggestion, but we failed
+ * the {@link WifiConfigManager} interactions.
+ *
+ * Expected connectable Networks: {}
*/
@Test
public void testSelectNetworkSuggestionForOneMatchButFailToAddToWifiConfigManager() {
@@ -389,16 +365,15 @@ public class NetworkSuggestionEvaluatorTest extends WifiBaseTest {
linkScanDetailsWithNetworkSuggestions(scanDetails, suggestions);
// Fail add to WifiConfigManager
when(mWifiConfigManager.addOrUpdateNetwork(any(), anyInt(), anyString()))
- .thenReturn(new NetworkUpdateResult(WifiConfiguration.INVALID_NETWORK_ID));
+ .thenReturn(new NetworkUpdateResult(INVALID_NETWORK_ID));
List<Pair<ScanDetail, WifiConfiguration>> connectableNetworks = new ArrayList<>();
- WifiConfiguration candidate = mNetworkSuggestionEvaluator.evaluateNetworks(
+ mNetworkSuggestionNominator.nominateNetworks(
Arrays.asList(scanDetails), null, null, true, false,
- (ScanDetail scanDetail, WifiConfiguration configuration, int score) -> {
+ (ScanDetail scanDetail, WifiConfiguration configuration) -> {
connectableNetworks.add(Pair.create(scanDetail, configuration));
});
- assertNull(candidate);
assertTrue(connectableNetworks.isEmpty());
verify(mWifiConfigManager, times(scanSsids.length))
@@ -412,9 +387,9 @@ public class NetworkSuggestionEvaluatorTest extends WifiBaseTest {
}
/**
- * Ensure that we select the only matching network suggestion, but that matches an existing
+ * Ensure that we nominate the only matching network suggestion, but that matches an existing
* saved network (maybe saved or maybe it exists from a previous connection attempt) .
- * Expected candidate: suggestionSsids[0]
+ *
* Expected connectable Networks: {suggestionSsids[0]}
*/
@Test
@@ -447,21 +422,19 @@ public class NetworkSuggestionEvaluatorTest extends WifiBaseTest {
.thenReturn(suggestions[0].wns.wifiConfiguration);
List<Pair<ScanDetail, WifiConfiguration>> connectableNetworks = new ArrayList<>();
- WifiConfiguration candidate = mNetworkSuggestionEvaluator.evaluateNetworks(
+ mNetworkSuggestionNominator.nominateNetworks(
Arrays.asList(scanDetails), null, null, true, false,
- (ScanDetail scanDetail, WifiConfiguration configuration, int score) -> {
+ (ScanDetail scanDetail, WifiConfiguration configuration) -> {
connectableNetworks.add(Pair.create(scanDetail, configuration));
});
- assertNotNull(candidate);
- assertEquals(suggestionSsids[0] , candidate.SSID);
-
validateConnectableNetworks(connectableNetworks, new String[] {scanSsids[0]});
// check for any saved networks.
verify(mWifiConfigManager, times(scanSsids.length))
.wasEphemeralNetworkDeleted(anyString());
- verify(mWifiConfigManager).getConfiguredNetwork(candidate.getKey());
+ verify(mWifiConfigManager)
+ .getConfiguredNetwork(suggestions[0].wns.wifiConfiguration.getKey());
verify(mWifiConfigManager).addOrUpdateNetwork(eq(suggestions[0].wns.wifiConfiguration),
eq(suggestions[0].perAppInfo.uid), eq(suggestions[0].perAppInfo.packageName));
verify(mWifiConfigManager).getConfiguredNetwork(
@@ -472,9 +445,9 @@ public class NetworkSuggestionEvaluatorTest extends WifiBaseTest {
}
/**
- * Ensure that we don't select the only matching network suggestion if it was previously
+ * Ensure that we don't nominate the only matching network suggestion if it was previously
* disabled by the user.
- * Expected candidate: null
+ *
* Expected connectable Networks: {}
*/
@Test
@@ -504,27 +477,24 @@ public class NetworkSuggestionEvaluatorTest extends WifiBaseTest {
when(mWifiConfigManager.wasEphemeralNetworkDeleted(suggestionSsids[0])).thenReturn(true);
List<Pair<ScanDetail, WifiConfiguration>> connectableNetworks = new ArrayList<>();
- WifiConfiguration candidate = mNetworkSuggestionEvaluator.evaluateNetworks(
+ mNetworkSuggestionNominator.nominateNetworks(
Arrays.asList(scanDetails), null, null, true, false,
- (ScanDetail scanDetail, WifiConfiguration configuration, int score) -> {
- connectableNetworks.add(Pair.create(scanDetail, configuration));
- });
+ (ScanDetail scanDetail, WifiConfiguration configuration) ->
+ connectableNetworks.add(Pair.create(scanDetail, configuration)));
- assertNull(candidate);
assertTrue(connectableNetworks.isEmpty());
- verify(mWifiConfigManager, times(scanSsids.length))
- .wasEphemeralNetworkDeleted(anyString());
+ verify(mWifiConfigManager, times(scanSsids.length)).wasEphemeralNetworkDeleted(anyString());
// Verify we did not try to add any new networks or other interactions with
// WifiConfigManager.
verifyNoMoreInteractions(mWifiConfigManager);
}
/**
- * Ensure that we don't select the only matching network suggestion if the network configuration
- * already exists (maybe saved or maybe it exists from a previous connection attempt) and
- * blacklisted.
- * Expected candidate: null
+ * Ensure that we don't nominate the only matching network suggestion if the network
+ * configuration already exists (maybe saved or maybe it exists from a previous connection
+ * attempt) and blacklisted.
+ *
* Expected connectable Networks: {}
*/
@Test
@@ -560,13 +530,12 @@ public class NetworkSuggestionEvaluatorTest extends WifiBaseTest {
.thenReturn(suggestions[0].wns.wifiConfiguration);
List<Pair<ScanDetail, WifiConfiguration>> connectableNetworks = new ArrayList<>();
- WifiConfiguration candidate = mNetworkSuggestionEvaluator.evaluateNetworks(
+ mNetworkSuggestionNominator.nominateNetworks(
Arrays.asList(scanDetails), null, null, true, false,
- (ScanDetail scanDetail, WifiConfiguration configuration, int score) -> {
+ (ScanDetail scanDetail, WifiConfiguration configuration) -> {
connectableNetworks.add(Pair.create(scanDetail, configuration));
});
- assertNull(candidate);
assertTrue(connectableNetworks.isEmpty());
verify(mWifiConfigManager, times(scanSsids.length))
@@ -585,10 +554,10 @@ public class NetworkSuggestionEvaluatorTest extends WifiBaseTest {
}
/**
- * Ensure that we do select the only matching network suggestion if the network configuration
+ * Ensure that we do nominate the only matching network suggestion if the network configuration
* already exists (maybe saved or maybe it exists from a previous connection attempt) and a
* temporary blacklist expired.
- * Expected candidate: suggestionSsids[0]
+ *
* Expected connectable Networks: {suggestionSsids[0]}
*/
@Test
@@ -626,15 +595,12 @@ public class NetworkSuggestionEvaluatorTest extends WifiBaseTest {
.thenReturn(true);
List<Pair<ScanDetail, WifiConfiguration>> connectableNetworks = new ArrayList<>();
- WifiConfiguration candidate = mNetworkSuggestionEvaluator.evaluateNetworks(
+ mNetworkSuggestionNominator.nominateNetworks(
Arrays.asList(scanDetails), null, null, true, false,
- (ScanDetail scanDetail, WifiConfiguration configuration, int score) -> {
+ (ScanDetail scanDetail, WifiConfiguration configuration) -> {
connectableNetworks.add(Pair.create(scanDetail, configuration));
});
- assertNotNull(candidate);
- assertEquals(suggestionSsids[0] , candidate.SSID);
-
validateConnectableNetworks(connectableNetworks, new String[] {scanSsids[0]});
verify(mWifiConfigManager, times(scanSsids.length))
diff --git a/tests/wifitests/src/com/android/server/wifi/SavedNetworkEvaluatorTest.java b/tests/wifitests/src/com/android/server/wifi/SavedNetworkEvaluatorTest.java
deleted file mode 100644
index 4f8170d0a..000000000
--- a/tests/wifitests/src/com/android/server/wifi/SavedNetworkEvaluatorTest.java
+++ /dev/null
@@ -1,651 +0,0 @@
-/*
- * Copyright (C) 2016 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.server.wifi;
-
-import static com.android.server.wifi.WifiConfigurationTestUtil.SECURITY_NONE;
-import static com.android.server.wifi.WifiConfigurationTestUtil.SECURITY_PSK;
-
-import static org.junit.Assert.*;
-import static org.mockito.Mockito.*;
-
-import android.content.Context;
-import android.content.res.Resources;
-import android.net.wifi.ScanResult;
-import android.net.wifi.WifiConfiguration;
-import android.os.SystemClock;
-import android.test.suitebuilder.annotation.SmallTest;
-import android.util.LocalLog;
-
-import com.android.server.wifi.WifiNetworkSelector.NetworkEvaluator.OnConnectableListener;
-import com.android.server.wifi.WifiNetworkSelectorTestUtil.ScanDetailsAndWifiConfigs;
-import com.android.server.wifi.util.TelephonyUtil;
-import com.android.wifi.resources.R;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-
-import java.util.List;
-
-/**
- * Unit tests for {@link com.android.server.wifi.SavedNetworkEvaluator}.
- */
-@SmallTest
-public class SavedNetworkEvaluatorTest extends WifiBaseTest {
-
- /** Sets up test. */
- @Before
- public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
- setupContext();
- setupResource();
- setupWifiConfigManager();
- mLocalLog = new LocalLog(512);
-
- when(mWifiConnectivityHelper.isFirmwareRoamingSupported()).thenReturn(false);
- when(mClock.getElapsedSinceBootMillis()).thenReturn(SystemClock.elapsedRealtime());
-
- mThresholdMinimumRssi2G = mResource.getInteger(
- R.integer.config_wifi_framework_wifi_score_bad_rssi_threshold_24GHz);
- mThresholdMinimumRssi5G = mResource.getInteger(
- R.integer.config_wifi_framework_wifi_score_bad_rssi_threshold_5GHz);
- mThresholdQualifiedRssi2G = mResource.getInteger(
- R.integer.config_wifi_framework_wifi_score_low_rssi_threshold_24GHz);
- mThresholdQualifiedRssi5G = mResource.getInteger(
- R.integer.config_wifi_framework_wifi_score_low_rssi_threshold_5GHz);
- mThresholdSaturatedRssi2G = mResource.getInteger(
- R.integer.config_wifi_framework_wifi_score_good_rssi_threshold_24GHz);
- mThresholdSaturatedRssi5G = mResource.getInteger(
- R.integer.config_wifi_framework_wifi_score_good_rssi_threshold_5GHz);
-
- mSavedNetworkEvaluator = new SavedNetworkEvaluator(mContext,
- new ScoringParams(mContext), mWifiConfigManager,
- mClock, mLocalLog, mWifiConnectivityHelper, mTelephonyUtil);
- }
-
- /** Cleans up test. */
- @After
- public void cleanup() {
- validateMockitoUsage();
- }
-
- private static final int INVALID_SUBID = 1;
- private static final int TEST_CARRIER_ID = 100;
-
- private SavedNetworkEvaluator mSavedNetworkEvaluator;
- @Mock private WifiConfigManager mWifiConfigManager;
- @Mock private WifiConnectivityHelper mWifiConnectivityHelper;
- @Mock private Context mContext;
- @Mock private Resources mResource;
- @Mock private Clock mClock;
- @Mock private OnConnectableListener mOnConnectableListener;
- @Mock private TelephonyUtil mTelephonyUtil;
- private LocalLog mLocalLog;
- private int mThresholdMinimumRssi2G;
- private int mThresholdMinimumRssi5G;
- private int mThresholdQualifiedRssi2G;
- private int mThresholdQualifiedRssi5G;
- private int mThresholdSaturatedRssi2G;
- private int mThresholdSaturatedRssi5G;
-
- private void setupContext() {
- when(mContext.getResources()).thenReturn(mResource);
- }
-
- private void setupResource() {
- when(mResource.getInteger(
- R.integer.config_wifi_framework_wifi_score_good_rssi_threshold_5GHz))
- .thenReturn(-57);
- when(mResource.getInteger(
- R.integer.config_wifi_framework_wifi_score_good_rssi_threshold_24GHz))
- .thenReturn(-60);
- when(mResource.getInteger(
- R.integer.config_wifi_framework_wifi_score_low_rssi_threshold_5GHz))
- .thenReturn(-70);
- when(mResource.getInteger(
- R.integer.config_wifi_framework_wifi_score_low_rssi_threshold_24GHz))
- .thenReturn(-73);
- when(mResource.getInteger(
- R.integer.config_wifi_framework_wifi_score_bad_rssi_threshold_5GHz))
- .thenReturn(-82);
- when(mResource.getInteger(
- R.integer.config_wifi_framework_wifi_score_bad_rssi_threshold_24GHz))
- .thenReturn(-85);
- when(mResource.getInteger(
- R.integer.config_wifi_framework_RSSI_SCORE_SLOPE))
- .thenReturn(4);
- when(mResource.getInteger(
- R.integer.config_wifi_framework_RSSI_SCORE_OFFSET))
- .thenReturn(85);
- when(mResource.getInteger(
- R.integer.config_wifi_framework_SAME_BSSID_AWARD))
- .thenReturn(24);
- when(mResource.getInteger(
- R.integer.config_wifi_framework_SECURITY_AWARD))
- .thenReturn(80);
- when(mResource.getInteger(
- R.integer.config_wifi_framework_5GHz_preference_boost_factor))
- .thenReturn(16);
- when(mResource.getInteger(
- R.integer.config_wifiFramework6ghzPreferenceBoostFactor))
- .thenReturn(16);
- when(mResource.getInteger(
- R.integer.config_wifi_framework_current_network_boost))
- .thenReturn(16);
- }
-
- private void setupWifiConfigManager() {
- when(mWifiConfigManager.getLastSelectedNetwork())
- .thenReturn(WifiConfiguration.INVALID_NETWORK_ID);
- }
-
- /**
- * Do not evaluate networks that {@link WifiConfiguration#useExternalScores}.
- */
- @Test
- public void ignoreNetworksIfUseExternalScores() {
- 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-PSK][ESS]", "[WPA2-PSK][ESS]"};
- int[] levels = {mThresholdQualifiedRssi2G + 8, mThresholdQualifiedRssi2G + 10};
- int[] securities = {SECURITY_PSK, SECURITY_PSK};
-
- ScanDetailsAndWifiConfigs scanDetailsAndConfigs =
- WifiNetworkSelectorTestUtil.setupScanDetailsAndConfigStore(ssids, bssids,
- freqs, caps, levels, securities, mWifiConfigManager, mClock);
- List<ScanDetail> scanDetails = scanDetailsAndConfigs.getScanDetails();
- WifiConfiguration[] savedConfigs = scanDetailsAndConfigs.getWifiConfigs();
- for (WifiConfiguration wifiConfiguration : savedConfigs) {
- wifiConfiguration.useExternalScores = true;
- }
-
- WifiConfiguration candidate = mSavedNetworkEvaluator.evaluateNetworks(scanDetails,
- null, null, true, false, mOnConnectableListener);
-
- assertNull(candidate);
- }
-
- /**
- * Do not evaluate networks which require SIM card when the SIM card is absent.
- */
- @Test
- public void ignoreNetworkIfSimIsAbsentForEapSimNetwork() {
- String[] ssids = {"\"test1\""};
- String[] bssids = {"6c:f3:7f:ae:8c:f3"};
- int[] freqs = {2470};
- int[] levels = {mThresholdQualifiedRssi2G + 8};
-
- ScanDetailsAndWifiConfigs scanDetailsAndConfigs =
- WifiNetworkSelectorTestUtil.setupScanDetailsAndConfigForEapSimNetwork(ssids, bssids,
- freqs, levels, mWifiConfigManager, mClock);
- List<ScanDetail> scanDetails = scanDetailsAndConfigs.getScanDetails();
- WifiConfiguration[] savedConfigs = scanDetailsAndConfigs.getWifiConfigs();
- savedConfigs[0].carrierId = TEST_CARRIER_ID;
- // SIM is absent
- when(mTelephonyUtil.getBestMatchSubscriptionId(any(WifiConfiguration.class)))
- .thenReturn(INVALID_SUBID);
- when(mTelephonyUtil.isSimPresent(eq(INVALID_SUBID))).thenReturn(false);
-
- WifiConfiguration candidate = mSavedNetworkEvaluator.evaluateNetworks(scanDetails,
- null, null, true, false, mOnConnectableListener);
-
- assertNull(candidate);
- }
-
- /**
- * Do not evaluate networks that {@link WifiConfiguration#isEphemeral}.
- */
- @Test
- public void ignoreEphemeralNetworks() {
- 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 + 8, mThresholdQualifiedRssi2G + 10};
- int[] securities = {SECURITY_NONE, SECURITY_NONE};
-
- ScanDetailsAndWifiConfigs scanDetailsAndConfigs =
- WifiNetworkSelectorTestUtil.setupScanDetailsAndConfigStore(ssids, bssids,
- freqs, caps, levels, securities, mWifiConfigManager, mClock);
- List<ScanDetail> scanDetails = scanDetailsAndConfigs.getScanDetails();
- WifiConfiguration[] savedConfigs = scanDetailsAndConfigs.getWifiConfigs();
- for (WifiConfiguration wifiConfiguration : savedConfigs) {
- wifiConfiguration.ephemeral = true;
- }
-
- WifiConfiguration candidate = mSavedNetworkEvaluator.evaluateNetworks(scanDetails,
- null, null, true, false, mOnConnectableListener);
-
- assertNull(candidate);
- }
-
- /**
- * Pick a worse candidate that allows auto-join over a better candidate that
- * disallows auto-join.
- */
- @Test
- public void ignoreNetworksIfAutojoinNotAllowed() {
- 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 + 8, mThresholdQualifiedRssi2G + 10};
- int[] securities = {SECURITY_NONE, SECURITY_NONE};
-
- ScanDetailsAndWifiConfigs scanDetailsAndConfigs =
- WifiNetworkSelectorTestUtil.setupScanDetailsAndConfigStore(ssids, bssids,
- freqs, caps, levels, securities, mWifiConfigManager, mClock);
- List<ScanDetail> scanDetails = scanDetailsAndConfigs.getScanDetails();
- WifiConfiguration[] savedConfigs = scanDetailsAndConfigs.getWifiConfigs();
-
- WifiConfiguration candidate = mSavedNetworkEvaluator.evaluateNetworks(scanDetails,
- null, null, true, false, mOnConnectableListener);
-
- ScanResult chosenScanResult = scanDetails.get(1).getScanResult();
- WifiConfigurationTestUtil.assertConfigurationEqual(savedConfigs[1], candidate);
- WifiNetworkSelectorTestUtil.verifySelectedScanResult(mWifiConfigManager,
- chosenScanResult, candidate);
-
- savedConfigs[1].allowAutojoin = false;
- candidate = mSavedNetworkEvaluator.evaluateNetworks(scanDetails,
- null, null, true, false, mOnConnectableListener);
-
- chosenScanResult = scanDetails.get(0).getScanResult();
- WifiConfigurationTestUtil.assertConfigurationEqual(savedConfigs[0], candidate);
- WifiNetworkSelectorTestUtil.verifySelectedScanResult(mWifiConfigManager,
- chosenScanResult, candidate);
- }
-
- /**
- * Do not return a candidate if all networks do not {@link WifiConfiguration#allowAutojoin}
- */
- @Test
- public void returnNoCandidateIfNoNetworksAllowAutojoin() {
- 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 + 8, mThresholdQualifiedRssi2G + 10};
- int[] securities = {SECURITY_NONE, SECURITY_NONE};
-
- ScanDetailsAndWifiConfigs scanDetailsAndConfigs =
- WifiNetworkSelectorTestUtil.setupScanDetailsAndConfigStore(ssids, bssids,
- freqs, caps, levels, securities, mWifiConfigManager, mClock);
- List<ScanDetail> scanDetails = scanDetailsAndConfigs.getScanDetails();
- WifiConfiguration[] savedConfigs = scanDetailsAndConfigs.getWifiConfigs();
- for (WifiConfiguration wifiConfiguration : savedConfigs) {
- wifiConfiguration.allowAutojoin = false;
- }
-
- WifiConfiguration candidate = mSavedNetworkEvaluator.evaluateNetworks(scanDetails,
- null, null, true, false, mOnConnectableListener);
-
- assertNull(candidate);
- }
-
- /**
- * Set the candidate {@link ScanResult} for all {@link WifiConfiguration}s regardless of
- * whether they are secure saved, open saved, or {@link WifiConfiguration#useExternalScores}.
- */
- @Test
- public void setCandidateScanResultsForAllSavedNetworks() {
- String[] ssids = {"\"test1\"", "\"test2\"", "\"test3\""};
- String[] bssids = {"6c:f3:7f:ae:8c:f3", "6c:f3:7f:ae:8c:f4", "6c:f3:7f:ae:8c:f5"};
- int[] freqs = {5200, 5220, 5240};
- String[] caps = {"[WPA2-PSK][ESS]", "[ESS]", "[WPA2-PSK][ESS]"};
- int[] levels =
- {mThresholdQualifiedRssi5G, mThresholdQualifiedRssi5G, mThresholdQualifiedRssi5G};
- int[] securities = {SECURITY_PSK, SECURITY_NONE, SECURITY_PSK};
-
- ScanDetailsAndWifiConfigs scanDetailsAndConfigs =
- WifiNetworkSelectorTestUtil.setupScanDetailsAndConfigStore(ssids, bssids,
- freqs, caps, levels, securities, mWifiConfigManager, mClock);
- List<ScanDetail> scanDetails = scanDetailsAndConfigs.getScanDetails();
- WifiConfiguration useExternalScoresConfig = scanDetailsAndConfigs.getWifiConfigs()[0];
- useExternalScoresConfig.useExternalScores = true;
- WifiConfiguration openNetworkConfig = scanDetailsAndConfigs.getWifiConfigs()[1];
- WifiConfiguration secureNetworkConfig = scanDetailsAndConfigs.getWifiConfigs()[2];
-
- mSavedNetworkEvaluator.evaluateNetworks(scanDetails,
- null, null, true, false, mOnConnectableListener);
-
- verify(mWifiConfigManager, atLeastOnce()).setNetworkCandidateScanResult(
- eq(useExternalScoresConfig.networkId),
- eq(scanDetails.get(0).getScanResult()),
- anyInt());
- verify(mWifiConfigManager, atLeastOnce()).setNetworkCandidateScanResult(
- eq(openNetworkConfig.networkId),
- eq(scanDetails.get(1).getScanResult()),
- anyInt());
- verify(mWifiConfigManager, atLeastOnce()).setNetworkCandidateScanResult(
- eq(secureNetworkConfig.networkId),
- eq(scanDetails.get(2).getScanResult()),
- anyInt());
- }
-
- /**
- * Between two 2G networks, choose the one with stronger RSSI value if other conditions
- * are the same and the RSSI values are not saturated.
- */
- @Test
- public void chooseStrongerRssi2GNetwork() {
- 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-PSK][ESS]", "[WPA2-PSK][ESS]"};
- int[] levels = {mThresholdQualifiedRssi2G + 8, mThresholdQualifiedRssi2G + 10};
- int[] securities = {SECURITY_PSK, SECURITY_PSK};
-
- ScanDetailsAndWifiConfigs scanDetailsAndConfigs =
- WifiNetworkSelectorTestUtil.setupScanDetailsAndConfigStore(ssids, bssids,
- freqs, caps, levels, securities, mWifiConfigManager, mClock);
- List<ScanDetail> scanDetails = scanDetailsAndConfigs.getScanDetails();
- WifiConfiguration[] savedConfigs = scanDetailsAndConfigs.getWifiConfigs();
-
- WifiConfiguration candidate = mSavedNetworkEvaluator.evaluateNetworks(scanDetails,
- null, null, true, false, mOnConnectableListener);
-
- ScanResult chosenScanResult = scanDetails.get(1).getScanResult();
- WifiConfigurationTestUtil.assertConfigurationEqual(savedConfigs[1], candidate);
- WifiNetworkSelectorTestUtil.verifySelectedScanResult(mWifiConfigManager,
- chosenScanResult, candidate);
- }
-
- /**
- * Between two 5G networks, choose the one with stronger RSSI value if other conditions
- * are the same and the RSSI values are not saturated.
- */
- @Test
- public void chooseStrongerRssi5GNetwork() {
- String[] ssids = {"\"test1\"", "\"test2\""};
- String[] bssids = {"6c:f3:7f:ae:8c:f3", "6c:f3:7f:ae:8c:f4"};
- int[] freqs = {5200, 5240};
- String[] caps = {"[WPA2-PSK][ESS]", "[WPA2-PSK][ESS]"};
- int[] levels = {mThresholdQualifiedRssi5G + 8, mThresholdQualifiedRssi5G + 10};
- int[] securities = {SECURITY_PSK, SECURITY_PSK};
-
- ScanDetailsAndWifiConfigs scanDetailsAndConfigs =
- WifiNetworkSelectorTestUtil.setupScanDetailsAndConfigStore(ssids, bssids,
- freqs, caps, levels, securities, mWifiConfigManager, mClock);
- List<ScanDetail> scanDetails = scanDetailsAndConfigs.getScanDetails();
- WifiConfiguration[] savedConfigs = scanDetailsAndConfigs.getWifiConfigs();
-
- WifiConfiguration candidate = mSavedNetworkEvaluator.evaluateNetworks(scanDetails,
- null, null, true, false, mOnConnectableListener);
-
- ScanResult chosenScanResult = scanDetails.get(1).getScanResult();
- WifiConfigurationTestUtil.assertConfigurationEqual(savedConfigs[1], candidate);
- WifiNetworkSelectorTestUtil.verifySelectedScanResult(mWifiConfigManager,
- chosenScanResult, candidate);
- }
-
- /**
- * Choose secure network over open network if other conditions are the same.
- */
- @Test
- public void chooseSecureNetworkOverOpenNetwork() {
- String[] ssids = {"\"test1\"", "\"test2\""};
- String[] bssids = {"6c:f3:7f:ae:8c:f3", "6c:f3:7f:ae:8c:f4"};
- int[] freqs = {5200, 5240};
- String[] caps = {"[ESS]", "[WPA2-PSK][ESS]"};
- int[] levels = {mThresholdQualifiedRssi5G, mThresholdQualifiedRssi5G};
- int[] securities = {SECURITY_NONE, SECURITY_PSK};
-
- ScanDetailsAndWifiConfigs scanDetailsAndConfigs =
- WifiNetworkSelectorTestUtil.setupScanDetailsAndConfigStore(ssids, bssids,
- freqs, caps, levels, securities, mWifiConfigManager, mClock);
- List<ScanDetail> scanDetails = scanDetailsAndConfigs.getScanDetails();
- WifiConfiguration[] savedConfigs = scanDetailsAndConfigs.getWifiConfigs();
-
- WifiConfiguration candidate = mSavedNetworkEvaluator.evaluateNetworks(scanDetails,
- null, null, true, false, mOnConnectableListener);
-
- ScanResult chosenScanResult = scanDetails.get(1).getScanResult();
- WifiConfigurationTestUtil.assertConfigurationEqual(savedConfigs[1], candidate);
- WifiNetworkSelectorTestUtil.verifySelectedScanResult(mWifiConfigManager,
- chosenScanResult, candidate);
- }
-
- /**
- * Choose 5G network over 2G network if other conditions are the same.
- */
- @Test
- public void choose5GNetworkOver2GNetwork() {
- String[] ssids = {"\"test1\"", "\"test2\""};
- String[] bssids = {"6c:f3:7f:ae:8c:f3", "6c:f3:7f:ae:8c:f4"};
- int[] freqs = {2437, 5240};
- String[] caps = {"[WPA2-PSK][ESS]", "[WPA2-PSK][ESS]"};
- int[] levels = {mThresholdQualifiedRssi2G, mThresholdQualifiedRssi5G};
- int[] securities = {SECURITY_PSK, SECURITY_PSK};
-
- ScanDetailsAndWifiConfigs scanDetailsAndConfigs =
- WifiNetworkSelectorTestUtil.setupScanDetailsAndConfigStore(ssids, bssids,
- freqs, caps, levels, securities, mWifiConfigManager, mClock);
- List<ScanDetail> scanDetails = scanDetailsAndConfigs.getScanDetails();
- WifiConfiguration[] savedConfigs = scanDetailsAndConfigs.getWifiConfigs();
-
- WifiConfiguration candidate = mSavedNetworkEvaluator.evaluateNetworks(scanDetails,
- null, null, true, false, mOnConnectableListener);
-
- ScanResult chosenScanResult = scanDetails.get(1).getScanResult();
- WifiConfigurationTestUtil.assertConfigurationEqual(savedConfigs[1], candidate);
- WifiNetworkSelectorTestUtil.verifySelectedScanResult(mWifiConfigManager,
- chosenScanResult, candidate);
- }
-
- /**
- * Verify that we stick to the currently connected network if the other one is
- * just slightly better scored.
- */
- @Test
- public void stickToCurrentNetwork() {
- String[] ssids = {"\"test1\"", "\"test2\""};
- String[] bssids = {"6c:f3:7f:ae:8c:f3", "6c:f3:7f:ae:8c:f4"};
- int[] freqs = {5200, 5240};
- String[] caps = {"[WPA2-PSK][ESS]", "[WPA2-PSK][ESS]"};
- // test2 has slightly stronger RSSI value than test1
- int[] levels = {mThresholdMinimumRssi5G + 2, mThresholdMinimumRssi5G + 4};
- int[] securities = {SECURITY_PSK, SECURITY_PSK};
-
- ScanDetailsAndWifiConfigs scanDetailsAndConfigs =
- WifiNetworkSelectorTestUtil.setupScanDetailsAndConfigStore(ssids, bssids,
- freqs, caps, levels, securities, mWifiConfigManager, mClock);
- List<ScanDetail> scanDetails = scanDetailsAndConfigs.getScanDetails();
- WifiConfiguration[] savedConfigs = scanDetailsAndConfigs.getWifiConfigs();
-
- // Simuluate we are connected to SSID test1 already.
- WifiConfiguration candidate = mSavedNetworkEvaluator.evaluateNetworks(scanDetails,
- savedConfigs[0], null, true, false, mOnConnectableListener);
-
- // Even though test2 has higher RSSI value, test1 is chosen because of the
- // currently connected network bonus.
- ScanResult chosenScanResult = scanDetails.get(0).getScanResult();
- WifiConfigurationTestUtil.assertConfigurationEqual(savedConfigs[0], candidate);
- WifiNetworkSelectorTestUtil.verifySelectedScanResult(mWifiConfigManager,
- chosenScanResult, candidate);
- }
-
- /**
- * Verify that we stick to the currently connected BSSID if the other one is
- * just slightly better scored.
- */
- @Test
- public void stickToCurrentBSSID() {
- // Same SSID
- String[] ssids = {"\"test1\"", "\"test1\""};
- String[] bssids = {"6c:f3:7f:ae:8c:f3", "6c:f3:7f:ae:8c:f4"};
- int[] freqs = {5200, 5240};
- String[] caps = {"[WPA2-PSK][ESS]", "[WPA2-PSK][ESS]"};
- // test2 has slightly stronger RSSI value than test1
- int[] levels = {mThresholdMinimumRssi5G + 2, mThresholdMinimumRssi5G + 6};
- int[] securities = {SECURITY_PSK, SECURITY_PSK};
-
- ScanDetailsAndWifiConfigs scanDetailsAndConfigs =
- WifiNetworkSelectorTestUtil.setupScanDetailsAndConfigStore(ssids, bssids,
- freqs, caps, levels, securities, mWifiConfigManager, mClock);
- List<ScanDetail> scanDetails = scanDetailsAndConfigs.getScanDetails();
- WifiConfiguration[] savedConfigs = scanDetailsAndConfigs.getWifiConfigs();
-
- // Simuluate we are connected to BSSID "6c:f3:7f:ae:8c:f3" already
- WifiConfiguration candidate = mSavedNetworkEvaluator.evaluateNetworks(scanDetails,
- null, bssids[0], true, false, mOnConnectableListener);
-
- // Even though test2 has higher RSSI value, test1 is chosen because of the
- // currently connected BSSID bonus.
- ScanResult chosenScanResult = scanDetails.get(0).getScanResult();
- WifiConfigurationTestUtil.assertConfigurationEqual(savedConfigs[0], candidate);
- }
-
- /**
- * Verify that the same BSSID award is applied to all the BSSIDs which are under the same
- * network as the currently connected BSSID.
- */
- @Test
- public void currentBssidAwardForAllBssidsWithinTheSameNetworkWhenFirmwareRoamingSupported() {
- // Three BSSIDs are carefully setup there:
- // BSSID_0 and BSSID_1 have the same SSID and security type, so they are considered under
- // the same 2.4 GHz network. BSSID_1 RSSI is stronger than BSSID_0.
- // BSSID_2 is under a 5GHz network different from BSSID_0 and BSSID_1. Its RSSI is
- // slightly stronger than BSSID_1.
- //
- // When firmware roaming is not supported, BSSID_2 has higher score than BSSID_0 and
- // BSSID_1.
- // When firmware roaming is suported, BSSID_1 has higher score than BSSID_2 because the
- // same BSSID award is now applied to both BSSID_0 and BSSID_1.
- String[] ssids = {"\"test1\"", "\"test1\"", "\"test2\""};
- String[] bssids = {"6c:f3:7f:ae:8c:f3", "6c:f3:7f:ae:8c:f4", "6c:f3:7f:ae:8c:f5"};
- int[] freqs = {2470, 2437, 5200};
- String[] caps = {"[WPA2-PSK][ESS]", "[WPA2-PSK][ESS]", "[WPA2-PSK][ESS]"};
- int[] levels = {mThresholdMinimumRssi2G + 2, mThresholdMinimumRssi2G + 5,
- mThresholdMinimumRssi5G + 7};
- int[] securities = {SECURITY_PSK, SECURITY_PSK, SECURITY_PSK};
-
- ScanDetailsAndWifiConfigs scanDetailsAndConfigs =
- WifiNetworkSelectorTestUtil.setupScanDetailsAndConfigStore(ssids, bssids,
- freqs, caps, levels, securities, mWifiConfigManager, mClock);
- List<ScanDetail> scanDetails = scanDetailsAndConfigs.getScanDetails();
- WifiConfiguration[] savedConfigs = scanDetailsAndConfigs.getWifiConfigs();
-
- // Firmware roaming is not supported.
- when(mWifiConnectivityHelper.isFirmwareRoamingSupported()).thenReturn(false);
- // Simuluate we are connected to BSSID_0 already.
- WifiConfiguration candidate = mSavedNetworkEvaluator.evaluateNetworks(scanDetails,
- savedConfigs[0], bssids[0], true, false, mOnConnectableListener);
- // Verify that BSSID_2 is chosen.
- ScanResult chosenScanResult = scanDetails.get(2).getScanResult();
- WifiConfigurationTestUtil.assertConfigurationEqual(savedConfigs[2], candidate);
- WifiNetworkSelectorTestUtil.verifySelectedScanResult(mWifiConfigManager,
- chosenScanResult, candidate);
-
- // Firmware roaming is supported.
- when(mWifiConnectivityHelper.isFirmwareRoamingSupported()).thenReturn(true);
- // Simuluate we are connected to BSSID_0 already.
- candidate = mSavedNetworkEvaluator.evaluateNetworks(scanDetails,
- savedConfigs[0], bssids[0], true, false, mOnConnectableListener);
- // Verify that BSSID_1 is chosen.
- chosenScanResult = scanDetails.get(1).getScanResult();
- WifiConfigurationTestUtil.assertConfigurationEqual(savedConfigs[1], candidate);
- WifiNetworkSelectorTestUtil.verifySelectedScanResult(mWifiConfigManager,
- chosenScanResult, candidate);
- }
-
- /**
- * One 2.4GHz network and one 5GHz network have the same security type. Perform
- * the following tests to verify that once across the RSSI saturation threshold
- * stronger RSSI value doesn't increase network score.
- *
- * 1) Both 2.4GHz network and 5GHz network have the same RSSI value,
- * mThresholdQualifiedRssi2G, which is below the saturation threshold. 5GHz
- * network is chosen because of the 5G band award.
- * 2) Bump up 2.4GHz network RSSI 20dBm higher. Verify that it helps the 2.4GHz network
- * score and it gets chosen over the 5GHz network.
- * 3) Bring both 2.4GHz network and 5GHz network RSSI value to mThresholdSaturatedRssi2G.
- * Verify that 5GHz network is chosen because of the 5G band award.
- * 4) Bump up 2.4GHz network RSSI to be 20dBm higher than mThresholdSaturatedRssi2G.
- * Verify that the incresed RSSI doesn't help 2.4GHz network score and 5GHz network
- * is still chosen.
- */
- @Test
- public void saturatedRssiAddsNoWeightToNetwork() {
- String[] ssids = {"\"test1\"", "\"test2\""};
- String[] bssids = {"6c:f3:7f:ae:8c:f3", "6c:f3:7f:ae:8c:f4"};
- int[] freqs = {2437, 5400};
- String[] caps = {"[WPA2-PSK][ESS]", "[WPA2-PSK][ESS]"};
- int[] securities = {SECURITY_PSK, SECURITY_PSK};
-
- // 1) The RSSI of both networks is mThresholdQualifiedRssi2G
- int[] levels = {mThresholdQualifiedRssi2G, mThresholdQualifiedRssi2G};
- ScanDetailsAndWifiConfigs scanDetailsAndConfigs =
- WifiNetworkSelectorTestUtil.setupScanDetailsAndConfigStore(ssids, bssids,
- freqs, caps, levels, securities, mWifiConfigManager, mClock);
- List<ScanDetail> scanDetails = scanDetailsAndConfigs.getScanDetails();
- WifiConfiguration[] savedConfigs = scanDetailsAndConfigs.getWifiConfigs();
- WifiConfiguration candidate = mSavedNetworkEvaluator.evaluateNetworks(scanDetails,
- null, null, false, false, mOnConnectableListener);
- // Verify that 5GHz network is chosen because of 5G band award
- ScanResult chosenScanResult = scanDetails.get(1).getScanResult();
- WifiConfigurationTestUtil.assertConfigurationEqual(savedConfigs[1], candidate);
- WifiNetworkSelectorTestUtil.verifySelectedScanResult(mWifiConfigManager,
- chosenScanResult, candidate);
-
- // 2) Bump up 2.4GHz network RSSI by 20dBm.
- levels[0] = mThresholdQualifiedRssi2G + 20;
- scanDetailsAndConfigs = WifiNetworkSelectorTestUtil.setupScanDetailsAndConfigStore(ssids,
- bssids, freqs, caps, levels, securities, mWifiConfigManager, mClock);
- scanDetails = scanDetailsAndConfigs.getScanDetails();
- savedConfigs = scanDetailsAndConfigs.getWifiConfigs();
- candidate = mSavedNetworkEvaluator.evaluateNetworks(scanDetails, null, null, false,
- false, mOnConnectableListener);
- // Verify that 2.4GHz network is chosen because of much higher RSSI value
- chosenScanResult = scanDetails.get(0).getScanResult();
- WifiConfigurationTestUtil.assertConfigurationEqual(savedConfigs[0], candidate);
- WifiNetworkSelectorTestUtil.verifySelectedScanResult(mWifiConfigManager,
- chosenScanResult, candidate);
-
- // 3) Bring both 2.4GHz network and 5GHz network RSSI to mThresholdSaturatedRssi2G
- levels[0] = levels[1] = mThresholdSaturatedRssi2G;
- scanDetailsAndConfigs = WifiNetworkSelectorTestUtil.setupScanDetailsAndConfigStore(ssids,
- bssids, freqs, caps, levels, securities, mWifiConfigManager, mClock);
- scanDetails = scanDetailsAndConfigs.getScanDetails();
- savedConfigs = scanDetailsAndConfigs.getWifiConfigs();
- candidate = mSavedNetworkEvaluator.evaluateNetworks(scanDetails, null, null, false,
- false, mOnConnectableListener);
- // Verify that 5GHz network is chosen because of 5G band award
- chosenScanResult = scanDetails.get(1).getScanResult();
- WifiConfigurationTestUtil.assertConfigurationEqual(savedConfigs[1], candidate);
- WifiNetworkSelectorTestUtil.verifySelectedScanResult(mWifiConfigManager,
- chosenScanResult, candidate);
-
- // 4) Bump 2.4GHz network RSSI to be 20dBm higher than mThresholdSaturatedRssi2G
- levels[0] = mThresholdSaturatedRssi2G + 20;
- scanDetailsAndConfigs = WifiNetworkSelectorTestUtil.setupScanDetailsAndConfigStore(ssids,
- bssids, freqs, caps, levels, securities, mWifiConfigManager, mClock);
- scanDetails = scanDetailsAndConfigs.getScanDetails();
- savedConfigs = scanDetailsAndConfigs.getWifiConfigs();
- candidate = mSavedNetworkEvaluator.evaluateNetworks(scanDetails, null, null, false,
- false, mOnConnectableListener);
- // Verify that the increased RSSI doesn't help 2.4GHz network and 5GHz network
- // is still chosen
- chosenScanResult = scanDetails.get(1).getScanResult();
- WifiConfigurationTestUtil.assertConfigurationEqual(savedConfigs[1], candidate);
- WifiNetworkSelectorTestUtil.verifySelectedScanResult(mWifiConfigManager,
- chosenScanResult, candidate);
- }
-}
diff --git a/tests/wifitests/src/com/android/server/wifi/SavedNetworkNominatorTest.java b/tests/wifitests/src/com/android/server/wifi/SavedNetworkNominatorTest.java
new file mode 100644
index 000000000..af4267564
--- /dev/null
+++ b/tests/wifitests/src/com/android/server/wifi/SavedNetworkNominatorTest.java
@@ -0,0 +1,216 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.server.wifi;
+
+import static com.android.server.wifi.WifiConfigurationTestUtil.SECURITY_NONE;
+import static com.android.server.wifi.WifiConfigurationTestUtil.SECURITY_PSK;
+
+import static org.mockito.Mockito.*;
+
+import android.net.wifi.WifiConfiguration;
+import android.test.suitebuilder.annotation.SmallTest;
+import android.util.LocalLog;
+
+import com.android.server.wifi.WifiNetworkSelector.NetworkNominator.OnConnectableListener;
+import com.android.server.wifi.WifiNetworkSelectorTestUtil.ScanDetailsAndWifiConfigs;
+import com.android.server.wifi.util.TelephonyUtil;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+import java.util.List;
+
+/**
+ * Unit tests for {@link SavedNetworkNominator}.
+ */
+@SmallTest
+public class SavedNetworkNominatorTest extends WifiBaseTest {
+
+ /** Sets up test. */
+ @Before
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ mLocalLog = new LocalLog(512);
+
+ mSavedNetworkEvaluator = new SavedNetworkNominator(mWifiConfigManager, mLocalLog,
+ mTelephonyUtil);
+ }
+
+ /** Cleans up test. */
+ @After
+ public void cleanup() {
+ validateMockitoUsage();
+ }
+
+ private ArgumentCaptor<WifiConfiguration> mWifiConfigurationArgumentCaptor =
+ ArgumentCaptor.forClass(WifiConfiguration.class);
+ private static final int INVALID_SUBID = 1;
+ private static final int TEST_CARRIER_ID = 100;
+ private static final int RSSI_LEVEL = -50;
+
+ private SavedNetworkNominator mSavedNetworkEvaluator;
+ @Mock private WifiConfigManager mWifiConfigManager;
+ @Mock private Clock mClock;
+ @Mock private OnConnectableListener mOnConnectableListener;
+ @Mock private TelephonyUtil mTelephonyUtil;
+ private LocalLog mLocalLog;
+
+ /**
+ * Do not evaluate networks that {@link WifiConfiguration#useExternalScores}.
+ */
+ @Test
+ public void ignoreNetworksIfUseExternalScores() {
+ 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-PSK][ESS]", "[WPA2-PSK][ESS]"};
+ int[] levels = {RSSI_LEVEL, RSSI_LEVEL};
+ int[] securities = {SECURITY_PSK, SECURITY_PSK};
+
+ ScanDetailsAndWifiConfigs scanDetailsAndConfigs =
+ WifiNetworkSelectorTestUtil.setupScanDetailsAndConfigStore(ssids, bssids,
+ freqs, caps, levels, securities, mWifiConfigManager, mClock);
+ List<ScanDetail> scanDetails = scanDetailsAndConfigs.getScanDetails();
+ WifiConfiguration[] savedConfigs = scanDetailsAndConfigs.getWifiConfigs();
+ for (WifiConfiguration wifiConfiguration : savedConfigs) {
+ wifiConfiguration.useExternalScores = true;
+ }
+
+ mSavedNetworkEvaluator.nominateNetworks(scanDetails,
+ null, null, true, false, mOnConnectableListener);
+
+ verify(mOnConnectableListener, never()).onConnectable(any(), any());
+ }
+
+ /**
+ * Do not evaluate networks which require SIM card when the SIM card is absent.
+ */
+ @Test
+ public void ignoreNetworkIfSimIsAbsentForEapSimNetwork() {
+ 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();
+ savedConfigs[0].carrierId = TEST_CARRIER_ID;
+ // SIM is absent
+ when(mTelephonyUtil.getBestMatchSubscriptionId(any(WifiConfiguration.class)))
+ .thenReturn(INVALID_SUBID);
+ when(mTelephonyUtil.isSimPresent(eq(INVALID_SUBID))).thenReturn(false);
+
+ mSavedNetworkEvaluator.nominateNetworks(scanDetails,
+ null, null, true, false, mOnConnectableListener);
+
+ verify(mOnConnectableListener, never()).onConnectable(any(), any());
+ }
+
+ /**
+ * Do not evaluate networks that {@link WifiConfiguration#isEphemeral}.
+ */
+ @Test
+ public void ignoreEphemeralNetworks() {
+ 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 = {RSSI_LEVEL, RSSI_LEVEL};
+ int[] securities = {SECURITY_NONE, SECURITY_NONE};
+
+ ScanDetailsAndWifiConfigs scanDetailsAndConfigs =
+ WifiNetworkSelectorTestUtil.setupScanDetailsAndConfigStore(ssids, bssids,
+ freqs, caps, levels, securities, mWifiConfigManager, mClock);
+ List<ScanDetail> scanDetails = scanDetailsAndConfigs.getScanDetails();
+ WifiConfiguration[] savedConfigs = scanDetailsAndConfigs.getWifiConfigs();
+ for (WifiConfiguration wifiConfiguration : savedConfigs) {
+ wifiConfiguration.ephemeral = true;
+ }
+
+ mSavedNetworkEvaluator.nominateNetworks(scanDetails,
+ null, null, true, false, mOnConnectableListener);
+
+ verify(mOnConnectableListener, never()).onConnectable(any(), any());
+ }
+
+ /**
+ * Pick a worse candidate that allows auto-join over a better candidate that
+ * disallows auto-join.
+ */
+ @Test
+ public void ignoreNetworksIfAutojoinNotAllowed() {
+ 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 = {RSSI_LEVEL, RSSI_LEVEL};
+ int[] securities = {SECURITY_NONE, SECURITY_NONE};
+
+ ScanDetailsAndWifiConfigs scanDetailsAndConfigs =
+ WifiNetworkSelectorTestUtil.setupScanDetailsAndConfigStore(ssids, bssids,
+ freqs, caps, levels, securities, mWifiConfigManager, mClock);
+ List<ScanDetail> scanDetails = scanDetailsAndConfigs.getScanDetails();
+ WifiConfiguration[] savedConfigs = scanDetailsAndConfigs.getWifiConfigs();
+
+ mSavedNetworkEvaluator.nominateNetworks(scanDetails,
+ null, null, true, false, mOnConnectableListener);
+
+ verify(mOnConnectableListener, times(2)).onConnectable(any(), any());
+ reset(mOnConnectableListener);
+ savedConfigs[1].allowAutojoin = false;
+ mSavedNetworkEvaluator.nominateNetworks(scanDetails,
+ null, null, true, false, mOnConnectableListener);
+ verify(mOnConnectableListener).onConnectable(any(),
+ mWifiConfigurationArgumentCaptor.capture());
+ WifiConfigurationTestUtil.assertConfigurationEqual(savedConfigs[0],
+ mWifiConfigurationArgumentCaptor.getValue());
+ }
+
+ /**
+ * Do not return a candidate if all networks do not {@link WifiConfiguration#allowAutojoin}
+ */
+ @Test
+ public void returnNoCandidateIfNoNetworksAllowAutojoin() {
+ 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 = {RSSI_LEVEL, RSSI_LEVEL};
+ int[] securities = {SECURITY_NONE, SECURITY_NONE};
+
+ ScanDetailsAndWifiConfigs scanDetailsAndConfigs =
+ WifiNetworkSelectorTestUtil.setupScanDetailsAndConfigStore(ssids, bssids,
+ freqs, caps, levels, securities, mWifiConfigManager, mClock);
+ List<ScanDetail> scanDetails = scanDetailsAndConfigs.getScanDetails();
+ WifiConfiguration[] savedConfigs = scanDetailsAndConfigs.getWifiConfigs();
+ for (WifiConfiguration wifiConfiguration : savedConfigs) {
+ wifiConfiguration.allowAutojoin = false;
+ }
+
+ mSavedNetworkEvaluator.nominateNetworks(scanDetails,
+ null, null, true, false, mOnConnectableListener);
+
+ verify(mOnConnectableListener, never()).onConnectable(any(), any());
+ }
+}
diff --git a/tests/wifitests/src/com/android/server/wifi/ScoredNetworkEvaluatorTest.java b/tests/wifitests/src/com/android/server/wifi/ScoredNetworkNominatorTest.java
index 6a2718ef2..3b7329002 100644
--- a/tests/wifitests/src/com/android/server/wifi/ScoredNetworkEvaluatorTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/ScoredNetworkNominatorTest.java
@@ -41,7 +41,7 @@ import android.util.LocalLog;
import androidx.test.filters.SmallTest;
-import com.android.server.wifi.WifiNetworkSelector.NetworkEvaluator.OnConnectableListener;
+import com.android.server.wifi.WifiNetworkSelector.NetworkNominator.OnConnectableListener;
import com.android.server.wifi.WifiNetworkSelectorTestUtil.ScanDetailsAndWifiConfigs;
import com.android.server.wifi.util.WifiPermissionsUtil;
@@ -57,10 +57,10 @@ import java.util.ArrayList;
import java.util.List;
/**
- * Unit tests for {@link ScoredNetworkEvaluator}.
+ * Unit tests for {@link ScoredNetworkNominator}.
*/
@SmallTest
-public class ScoredNetworkEvaluatorTest extends WifiBaseTest {
+public class ScoredNetworkNominatorTest extends WifiBaseTest {
private static final String TEST_PACKAGE_NAME = "name.package.test";
private static final int TEST_UID = 12345;
private static final NetworkScorerAppData TEST_APP_DATA = new NetworkScorerAppData(
@@ -81,7 +81,7 @@ public class ScoredNetworkEvaluatorTest extends WifiBaseTest {
@Captor private ArgumentCaptor<WifiConfiguration> mWifiConfigCaptor;
private WifiNetworkScoreCache mScoreCache;
- private ScoredNetworkEvaluator mScoredNetworkEvaluator;
+ private ScoredNetworkNominator mScoredNetworkEvaluator;
@Before
public void setUp() throws Exception {
@@ -101,7 +101,7 @@ public class ScoredNetworkEvaluatorTest extends WifiBaseTest {
ArgumentCaptor<ContentObserver> observerCaptor =
ArgumentCaptor.forClass(ContentObserver.class);
mScoreCache = new WifiNetworkScoreCache(mContext);
- mScoredNetworkEvaluator = new ScoredNetworkEvaluator(mContext,
+ mScoredNetworkEvaluator = new ScoredNetworkNominator(mContext,
new Handler(Looper.getMainLooper()), mFrameworkFacade, mNetworkScoreManager,
mPackageManager, mWifiConfigManager, new LocalLog(0), mScoreCache,
mWifiPermissionsUtil);
@@ -228,7 +228,7 @@ public class ScoredNetworkEvaluatorTest extends WifiBaseTest {
mContentObserver.onChange(false /* unused */);
- mScoredNetworkEvaluator.evaluateNetworks(null, null, null, false, false,
+ mScoredNetworkEvaluator.nominateNetworks(null, null, null, false, false,
mOnConnectableListener);
verifyZeroInteractions(mWifiConfigManager, mNetworkScoreManager);
@@ -293,121 +293,26 @@ public class ScoredNetworkEvaluatorTest extends WifiBaseTest {
int[] levels = {mThresholdQualifiedRssi2G + 8, mThresholdQualifiedRssi2G + 10};
Integer[] scores = {null, 120};
boolean[] meteredHints = {false, false};
-
List<ScanDetail> scanDetails = WifiNetworkSelectorTestUtil.buildScanDetails(
ssids, bssids, freqs, caps, levels, mClock);
WifiNetworkSelectorTestUtil.configureScoreCache(mScoreCache,
scanDetails, scores, meteredHints);
-
ScanResult scanResult = scanDetails.get(1).getScanResult();
WifiConfiguration ephemeralNetworkConfig = WifiNetworkSelectorTestUtil
.setupEphemeralNetwork(mWifiConfigManager, 1, scanDetails.get(1), meteredHints[1]);
-
// No saved networks.
when(mWifiConfigManager.getConfiguredNetworkForScanDetailAndCache(any(ScanDetail.class)))
.thenReturn(null);
-
// But when we create one, this is should be it.
when(mWifiConfigManager.addOrUpdateNetwork(any(), anyInt()))
.thenReturn(new NetworkUpdateResult(1));
-
// Untrusted networks allowed.
- WifiConfiguration candidate = mScoredNetworkEvaluator.evaluateNetworks(scanDetails,
- null, null, false, true, mOnConnectableListener);
-
- WifiConfigurationTestUtil.assertConfigurationEqual(ephemeralNetworkConfig, candidate);
- WifiNetworkSelectorTestUtil.verifySelectedScanResult(mWifiConfigManager,
- scanResult, candidate);
- assertEquals(meteredHints[1], candidate.meteredHint);
- verify(mOnConnectableListener, atLeastOnce())
- .onConnectable(any(), mWifiConfigCaptor.capture(), anyInt());
- assertTrue(mWifiConfigCaptor.getAllValues().stream()
- .anyMatch(c -> c.networkId == candidate.networkId));
- }
-
- /**
- * When no saved networks available, choose the available ephemeral networks
- * if untrusted networks are allowed.
- */
- @Test
- public void testEvaluateNetworks_chooseEphemeralNetworkBecauseOfNoSavedNetwork() {
- 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-PSK][ESS]", "[ESS]"};
- int[] levels = {mThresholdQualifiedRssi2G + 8, mThresholdQualifiedRssi2G + 10};
- Integer[] scores = {null, 120};
- boolean[] meteredHints = {false, true};
-
- List<ScanDetail> scanDetails = WifiNetworkSelectorTestUtil.buildScanDetails(
- ssids, bssids, freqs, caps, levels, mClock);
- WifiNetworkSelectorTestUtil.configureScoreCache(mScoreCache,
- scanDetails, scores, meteredHints);
-
- // No saved networks.
- when(mWifiConfigManager.getConfiguredNetworkForScanDetailAndCache(any(ScanDetail.class)))
- .thenReturn(null);
-
- ScanResult scanResult = scanDetails.get(1).getScanResult();
- WifiConfiguration ephemeralNetworkConfig = WifiNetworkSelectorTestUtil
- .setupEphemeralNetwork(mWifiConfigManager, 1, scanDetails.get(1), meteredHints[1]);
-
- // Untrusted networks allowed.
- WifiConfiguration candidate = mScoredNetworkEvaluator.evaluateNetworks(scanDetails,
- null, null, false, true, mOnConnectableListener);
-
- WifiConfigurationTestUtil.assertConfigurationEqual(ephemeralNetworkConfig, candidate);
- WifiNetworkSelectorTestUtil.verifySelectedScanResult(mWifiConfigManager,
- scanResult, candidate);
- assertEquals(meteredHints[1], candidate.meteredHint);
- verify(mOnConnectableListener, atLeastOnce())
- .onConnectable(any(), mWifiConfigCaptor.capture(), anyInt());
- assertTrue(mWifiConfigCaptor.getAllValues().stream()
- .anyMatch(c -> c.networkId == candidate.networkId));
- }
-
- /**
- * When no saved networks available, choose the highest scored ephemeral networks
- * if untrusted networks are allowed.
- */
- @Test
- public void testEvaluateNetworks_chooseHigherScoredEphemeralNetwork() {
- 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 + 8, mThresholdQualifiedRssi2G + 8};
- Integer[] scores = {100, 120};
- 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, scores, meteredHints);
-
- // No saved networks.
- when(mWifiConfigManager.getConfiguredNetworkForScanDetailAndCache(any(ScanDetail.class)))
- .thenReturn(null);
-
- for (int i = 0; i < 2; i++) {
- scanResults[i] = scanDetails.get(i).getScanResult();
- ephemeralNetworkConfigs[i] = WifiNetworkSelectorTestUtil.setupEphemeralNetwork(
- mWifiConfigManager, i, scanDetails.get(i), meteredHints[i]);
- }
-
- WifiConfiguration candidate = mScoredNetworkEvaluator.evaluateNetworks(scanDetails,
+ mScoredNetworkEvaluator.nominateNetworks(scanDetails,
null, null, false, true, mOnConnectableListener);
-
- WifiConfigurationTestUtil.assertConfigurationEqual(ephemeralNetworkConfigs[1], candidate);
- WifiNetworkSelectorTestUtil.verifySelectedScanResult(mWifiConfigManager,
- scanResults[1], candidate);
- assertEquals(meteredHints[1], candidate.meteredHint);
verify(mOnConnectableListener, atLeastOnce())
- .onConnectable(any(), mWifiConfigCaptor.capture(), anyInt());
+ .onConnectable(any(), mWifiConfigCaptor.capture());
assertTrue(mWifiConfigCaptor.getAllValues().stream()
- .anyMatch(c -> c.networkId == candidate.networkId));
+ .anyMatch(c -> c.networkId == ephemeralNetworkConfig.networkId));
}
/**
@@ -437,10 +342,10 @@ public class ScoredNetworkEvaluatorTest extends WifiBaseTest {
mWifiConfigManager, 1, scanDetails.get(1), meteredHints[1]);
// Untrusted networks not allowed.
- WifiConfiguration candidate = mScoredNetworkEvaluator.evaluateNetworks(scanDetails,
+ mScoredNetworkEvaluator.nominateNetworks(scanDetails,
null, null, false, false, mOnConnectableListener);
- assertEquals("Expect null configuration", null, candidate);
+ verify(mOnConnectableListener, never()).onConnectable(any(), any());
}
/**
@@ -467,146 +372,11 @@ public class ScoredNetworkEvaluatorTest extends WifiBaseTest {
WifiNetworkSelectorTestUtil.configureScoreCache(mScoreCache,
scanDetails, scores, meteredHints);
- WifiConfiguration candidate = mScoredNetworkEvaluator.evaluateNetworks(scanDetails,
+ mScoredNetworkEvaluator.nominateNetworks(scanDetails,
null, null, false, true, mOnConnectableListener);
- WifiConfigurationTestUtil.assertConfigurationEqual(savedConfigs[0], candidate);
- WifiNetworkSelectorTestUtil.verifySelectedScanResult(mWifiConfigManager,
- scanDetails.get(0).getScanResult(), candidate);
- verify(mOnConnectableListener, atLeastOnce())
- .onConnectable(any(), mWifiConfigCaptor.capture(), anyInt());
- assertTrue(mWifiConfigCaptor.getAllValues().stream()
- .anyMatch(c -> c.networkId == candidate.networkId));
- }
-
- /**
- * Choose externally scored saved network with higher score.
- */
- @Test
- public void testEvaluateNetworks_chooseSavedNetworkWithHigherExternalScore() {
- 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-PSK][ESS]", "[WPA2-PSK][ESS]"};
- int[] securities = {SECURITY_PSK, SECURITY_PSK};
- int[] levels = {mThresholdQualifiedRssi2G + 8, mThresholdQualifiedRssi2G + 8};
- Integer[] scores = {100, 120};
- boolean[] meteredHints = {false, false};
-
- WifiNetworkSelectorTestUtil.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, scores, meteredHints);
-
- WifiConfiguration candidate = mScoredNetworkEvaluator.evaluateNetworks(scanDetails,
- null, null, false, true, mOnConnectableListener);
-
- WifiConfigurationTestUtil.assertConfigurationEqual(savedConfigs[1], candidate);
- WifiNetworkSelectorTestUtil.verifySelectedScanResult(mWifiConfigManager,
- scanDetails.get(1).getScanResult(), candidate);
- verify(mOnConnectableListener, atLeastOnce())
- .onConnectable(any(), mWifiConfigCaptor.capture(), anyInt());
- assertTrue(mWifiConfigCaptor.getAllValues().stream()
- .anyMatch(c -> c.networkId == candidate.networkId));
- }
-
- /**
- * Prefer externally scored saved network over untrusted network when they have
- * the same score.
- */
- @Test
- public void testEvaluateNetworks_chooseExternallyScoredOverUntrustedNetworksWithSameScore() {
- 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-PSK][ESS]", "[ESS]"};
- int[] securities = {SECURITY_PSK, SECURITY_NONE};
- int[] levels = {mThresholdQualifiedRssi2G + 8, mThresholdQualifiedRssi2G + 8};
- Integer[] scores = {120, 120};
- boolean[] meteredHints = {false, true};
-
- WifiNetworkSelectorTestUtil.ScanDetailsAndWifiConfigs scanDetailsAndConfigs =
- WifiNetworkSelectorTestUtil.setupScanDetailsAndConfigStore(ssids, bssids,
- freqs, caps, levels, securities, mWifiConfigManager, mClock);
- List<ScanDetail> scanDetails = scanDetailsAndConfigs.getScanDetails();
- WifiConfiguration[] savedConfigs = scanDetailsAndConfigs.getWifiConfigs();
- savedConfigs[0].useExternalScores = true;
-
- WifiNetworkSelectorTestUtil.configureScoreCache(mScoreCache,
- scanDetails, scores, meteredHints);
-
- WifiConfiguration candidate = mScoredNetworkEvaluator.evaluateNetworks(scanDetails,
- null, null, false, true, mOnConnectableListener);
-
- WifiConfigurationTestUtil.assertConfigurationEqual(savedConfigs[0], candidate);
- WifiNetworkSelectorTestUtil.verifySelectedScanResult(mWifiConfigManager,
- scanDetails.get(0).getScanResult(), candidate);
- verify(mOnConnectableListener, atLeastOnce())
- .onConnectable(any(), mWifiConfigCaptor.capture(), anyInt());
- assertTrue(mWifiConfigCaptor.getAllValues().stream()
- .anyMatch(c -> c.networkId == candidate.networkId));
- }
-
- /**
- * Choose untrusted network when it has higher score than the externally scored
- * saved network.
- */
- @Test
- public void testEvaluateNetworks_chooseUntrustedWithHigherScoreThanExternallyScoredNetwork() {
- // Saved network.
- String[] savedSsids = {"\"test1\""};
- String[] savedBssids = {"6c:f3:7f:ae:8c:f3"};
- int[] savedFreqs = {2470};
- String[] savedCaps = {"[WPA2-PSK][ESS]"};
- int[] savedSecurities = {SECURITY_PSK};
- int[] savedLevels = {mThresholdQualifiedRssi2G + 8};
- // Ephemeral network.
- String[] ephemeralSsids = {"\"test2\""};
- String[] ephemeralBssids = {"6c:f3:7f:ae:8c:f4"};
- int[] ephemeralFreqs = {2437};
- String[] ephemeralCaps = {"[ESS]"};
- int[] ephemeralLevels = {mThresholdQualifiedRssi2G + 8};
- // Ephemeral network has higher score than the saved network.
- Integer[] scores = {100, 120};
- boolean[] meteredHints = {false, true};
-
- // Set up the saved network.
- WifiNetworkSelectorTestUtil.ScanDetailsAndWifiConfigs scanDetailsAndConfigs =
- WifiNetworkSelectorTestUtil.setupScanDetailsAndConfigStore(savedSsids,
- savedBssids, savedFreqs, savedCaps, savedLevels, savedSecurities,
- mWifiConfigManager, mClock);
- List<ScanDetail> scanDetails = scanDetailsAndConfigs.getScanDetails();
- WifiConfiguration[] savedConfigs = scanDetailsAndConfigs.getWifiConfigs();
- savedConfigs[0].useExternalScores = true;
-
- // Set up the ephemeral network.
- scanDetails.addAll(WifiNetworkSelectorTestUtil.buildScanDetails(
- ephemeralSsids, ephemeralBssids, ephemeralFreqs,
- ephemeralCaps, ephemeralLevels, mClock));
- ScanResult ephemeralScanResult = scanDetails.get(1).getScanResult();
- WifiConfiguration ephemeralNetworkConfig = WifiNetworkSelectorTestUtil
- .setupEphemeralNetwork(mWifiConfigManager, 1, scanDetails.get(1),
- meteredHints[1]);
-
- // Set up score cache for both the saved network and the ephemeral network.
- WifiNetworkSelectorTestUtil.configureScoreCache(mScoreCache,
- scanDetails, scores, meteredHints);
-
- WifiConfiguration candidate = mScoredNetworkEvaluator.evaluateNetworks(scanDetails,
- null, null, false, true, mOnConnectableListener);
-
- WifiConfigurationTestUtil.assertConfigurationEqual(ephemeralNetworkConfig, candidate);
- WifiNetworkSelectorTestUtil.verifySelectedScanResult(mWifiConfigManager,
- ephemeralScanResult, candidate);
- verify(mOnConnectableListener, atLeastOnce())
- .onConnectable(any(), mWifiConfigCaptor.capture(), anyInt());
- assertTrue(mWifiConfigCaptor.getAllValues().stream()
- .anyMatch(c -> c.networkId == candidate.networkId));
+ verify(mOnConnectableListener).onConnectable(any(), mWifiConfigCaptor.capture());
+ assertEquals(mWifiConfigCaptor.getValue().networkId, savedConfigs[0].networkId);
}
/**
@@ -634,91 +404,10 @@ public class ScoredNetworkEvaluatorTest extends WifiBaseTest {
WifiNetworkSelectorTestUtil.configureScoreCache(mScoreCache,
scanDetails, scores, meteredHints);
- WifiConfiguration candidate = mScoredNetworkEvaluator.evaluateNetworks(scanDetails,
+ mScoredNetworkEvaluator.nominateNetworks(scanDetails,
null, null, false, true, mOnConnectableListener);
- assertEquals("Expect null configuration", null, candidate);
- }
-
- /**
- * Between two ephemeral networks with the same RSSI, choose
- * the currently connected one.
- */
- @Test
- public void testEvaluateNetworks_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.getConfiguredNetworkForScanDetailAndCache(any(ScanDetail.class)))
- .thenReturn(null);
-
- for (int i = 0; i < 2; i++) {
- scanResults[i] = scanDetails.get(i).getScanResult();
- ephemeralNetworkConfigs[i] = WifiNetworkSelectorTestUtil.setupEphemeralNetwork(
- mWifiConfigManager, i, scanDetails.get(i), meteredHints[i]);
- }
-
- WifiConfiguration candidate = mScoredNetworkEvaluator.evaluateNetworks(
- scanDetails, ephemeralNetworkConfigs[1],
- bssids[1], true, true, mOnConnectableListener);
-
- WifiConfigurationTestUtil.assertConfigurationEqual(ephemeralNetworkConfigs[1], candidate);
- WifiNetworkSelectorTestUtil.verifySelectedScanResult(mWifiConfigManager,
- scanResults[1], candidate);
- assertEquals(meteredHints[1], candidate.meteredHint);
- verify(mOnConnectableListener, atLeastOnce())
- .onConnectable(any(), mWifiConfigCaptor.capture(), anyInt());
- assertTrue(mWifiConfigCaptor.getAllValues().stream()
- .anyMatch(c -> c.networkId == candidate.networkId));
- }
-
- /**
- * Between two externally scored saved networks with the same RSSI, choose
- * the currently connected one.
- */
- @Test
- public void testEvaluateNetworks_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-PSK][ESS]", "[WPA2-PSK][ESS]"};
- int[] securities = {SECURITY_PSK, SECURITY_PSK};
- int[] levels = {mThresholdQualifiedRssi2G + 28, mThresholdQualifiedRssi2G + 28};
- boolean[] meteredHints = {false, false};
-
- WifiNetworkSelectorTestUtil.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 = mScoredNetworkEvaluator.evaluateNetworks(scanDetails,
- savedConfigs[1], bssids[1], true, true, mOnConnectableListener);
-
- WifiConfigurationTestUtil.assertConfigurationEqual(savedConfigs[1], candidate);
- WifiNetworkSelectorTestUtil.verifySelectedScanResult(mWifiConfigManager,
- scanDetails.get(1).getScanResult(), candidate);
- verify(mOnConnectableListener, atLeastOnce())
- .onConnectable(any(), mWifiConfigCaptor.capture(), anyInt());
- assertTrue(mWifiConfigCaptor.getAllValues().stream()
- .anyMatch(c -> c.networkId == candidate.networkId));
-
+ verify(mOnConnectableListener).onConnectable(any(), mWifiConfigCaptor.capture());
+ assertEquals(mWifiConfigCaptor.getValue().networkId, savedConfigs[0].networkId);
}
}
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiCandidatesTest.java b/tests/wifitests/src/com/android/server/wifi/WifiCandidatesTest.java
index 65bedc476..336bdbe24 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiCandidatesTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiCandidatesTest.java
@@ -279,7 +279,24 @@ public class WifiCandidatesTest extends WifiBaseTest {
// Make sure we kept the one with a higher evaluatorScore
WifiCandidates.Candidate c;
c = mWifiCandidates.getGroupedCandidates().iterator().next().iterator().next();
- assertEquals(15, c.getEvaluatorScore());
assertEquals(90, c.getPredictedThroughputMbps());
+ assertEquals(15, c.getNominatorScore());
+ }
+
+ /**
+ * Tests passpiont network from same provider(FQDN) can have multiple candidates with different
+ * scanDetails.
+ */
+ @Test
+ public void testMultiplePasspointCandidatesWithSameFQDN() {
+ // Create a Passpoint WifiConfig
+ WifiConfiguration config1 = WifiConfigurationTestUtil.createPasspointNetwork();
+ mScanResult2.BSSID = mScanResult1.BSSID.replace('1', '2');
+ // Add candidates with different scanDetail for same passpoint WifiConfig.
+ assertTrue(mWifiCandidates.add(mScanDetail1, config1, 2, 0, 0.0, false, 100));
+ assertTrue(mWifiCandidates.add(mScanDetail2, config1, 2, 0, 0.0, false, 100));
+ // Both should survive and no faults.
+ assertEquals(2, mWifiCandidates.size());
+ assertEquals(0, mWifiCandidates.getFaultCount());
}
}
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java b/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java
index ec136ed3b..0eb8f84df 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java
@@ -461,9 +461,10 @@ public class WifiMetricsTest extends WifiBaseTest {
}
if (isProvider) {
PasspointProvider provider = mock(PasspointProvider.class);
- Pair<PasspointProvider, PasspointMatch> providerMatch = Pair.create(provider, null);
+ List<Pair<PasspointProvider, PasspointMatch>> matchedProviders = new ArrayList<>();
+ matchedProviders.add(Pair.create(provider, null));
when(mockNetworkDetail.isInterworking()).thenReturn(true);
- when(mPpm.matchProvider(eq(scanResult))).thenReturn(providerMatch);
+ when(mPpm.matchProvider(eq(scanResult))).thenReturn(matchedProviders);
}
return mockScanDetail;
}
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTest.java b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTest.java
index bddf3f946..a4744ff79 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTest.java
@@ -92,7 +92,7 @@ public class WifiNetworkSelectorTest extends WifiBaseTest {
mWifiNative,
mThroughputPredictor
);
- mWifiNetworkSelector.registerNetworkEvaluator(mDummyEvaluator);
+ mWifiNetworkSelector.registerNetworkNominator(mDummyEvaluator);
mDummyEvaluator.setEvaluatorToSelectCandidate(true);
when(mClock.getElapsedSinceBootMillis()).thenReturn(SystemClock.elapsedRealtime());
when(mCarrierNetworkConfig.isCarrierNetwork(any())).thenReturn(true);
@@ -101,6 +101,7 @@ public class WifiNetworkSelectorTest extends WifiBaseTest {
mScoreCardBasedScorer = new ScoreCardBasedScorer(mScoringParams);
mThroughputScorer = new ThroughputScorer(mScoringParams);
when(mWifiNative.getClientInterfaceName()).thenReturn("wlan0");
+ mWifiNetworkSelector.registerCandidateScorer(mCompatibilityScorer);
}
/** Cleans up test. */
@@ -112,20 +113,20 @@ public class WifiNetworkSelectorTest extends WifiBaseTest {
/**
* All this dummy network evaluator does is to pick the specified network in the scan results.
*/
- public class DummyNetworkEvaluator implements WifiNetworkSelector.NetworkEvaluator {
+ public class DummyNetworkNominator implements WifiNetworkSelector.NetworkNominator {
private static final String NAME = "DummyNetworkEvaluator";
- private boolean mEvaluatorShouldSelectCandidate = true;
+ private boolean mNominatorShouldSelectCandidate = true;
private int mNetworkIndexToReturn;
- private int mEvaluatorIdToReturn;
+ private int mNominatorIdToReturn;
- public DummyNetworkEvaluator(int networkIndexToReturn, int evaluatorIdToReturn) {
+ public DummyNetworkNominator(int networkIndexToReturn, int nominatorIdToReturn) {
mNetworkIndexToReturn = networkIndexToReturn;
- mEvaluatorIdToReturn = evaluatorIdToReturn;
+ mNominatorIdToReturn = nominatorIdToReturn;
}
- public DummyNetworkEvaluator() {
+ public DummyNetworkNominator() {
this(0, DUMMY_EVALUATOR_ID_1);
}
@@ -138,8 +139,8 @@ public class WifiNetworkSelectorTest extends WifiBaseTest {
}
@Override
- public @EvaluatorId int getId() {
- return mEvaluatorIdToReturn;
+ public @NominatorId int getId() {
+ return mNominatorIdToReturn;
}
@Override
@@ -151,10 +152,10 @@ public class WifiNetworkSelectorTest extends WifiBaseTest {
public void update(List<ScanDetail> scanDetails) {}
/**
- * Sets whether the evaluator should return a candidate for connection or null.
+ * Sets whether the nominator should return a candidate for connection or null.
*/
public void setEvaluatorToSelectCandidate(boolean shouldSelectCandidate) {
- mEvaluatorShouldSelectCandidate = shouldSelectCandidate;
+ mNominatorShouldSelectCandidate = shouldSelectCandidate;
}
/**
@@ -165,12 +166,12 @@ public class WifiNetworkSelectorTest extends WifiBaseTest {
* {@link WifiNetworkSelectorTestUtil#setupScanDetailsAndConfigStore}.
*/
@Override
- public WifiConfiguration evaluateNetworks(List<ScanDetail> scanDetails,
+ public void nominateNetworks(List<ScanDetail> scanDetails,
WifiConfiguration currentNetwork, String currentBssid, boolean connected,
boolean untrustedNetworkAllowed,
@NonNull OnConnectableListener onConnectableListener) {
- if (!mEvaluatorShouldSelectCandidate) {
- return null;
+ if (!mNominatorShouldSelectCandidate) {
+ return;
}
for (ScanDetail scanDetail : scanDetails) {
WifiConfiguration config =
@@ -183,13 +184,12 @@ public class WifiNetworkSelectorTest extends WifiBaseTest {
mWifiConfigManager.getConfiguredNetworkForScanDetailAndCache(
scanDetailToReturn);
assertNotNull("Saved network must not be null", configToReturn);
- onConnectableListener.onConnectable(scanDetailToReturn, configToReturn, 100);
- return configToReturn;
+ onConnectableListener.onConnectable(scanDetailToReturn, configToReturn);
}
}
private WifiNetworkSelector mWifiNetworkSelector = null;
- private DummyNetworkEvaluator mDummyEvaluator = new DummyNetworkEvaluator();
+ private DummyNetworkNominator mDummyEvaluator = new DummyNetworkNominator();
@Mock private WifiConfigManager mWifiConfigManager;
@Mock private Context mContext;
@Mock private CarrierNetworkConfig mCarrierNetworkConfig;
@@ -198,6 +198,7 @@ public class WifiNetworkSelectorTest extends WifiBaseTest {
@Mock private WifiCandidates.CandidateScorer mCandidateScorer;
@Mock private WifiMetrics mWifiMetrics;
@Mock private WifiNative mWifiNative;
+ @Mock private WifiNetworkSelector.NetworkNominator mNetworkNominator;
// For simulating the resources, we use a Spy on a MockResource
// (which is really more of a stub than a mock, in spite if its name).
@@ -793,11 +794,11 @@ public class WifiNetworkSelectorTest extends WifiBaseTest {
public void testMultipleEvaluatorsSetsNominatorIdCorrectly() {
// first dummy evaluator is registered in setup, returns index 0
// register a second network evaluator that also returns index 0, but with a different ID
- mWifiNetworkSelector.registerNetworkEvaluator(new DummyNetworkEvaluator(0,
- WifiNetworkSelector.NetworkEvaluator.EVALUATOR_ID_SCORED));
+ mWifiNetworkSelector.registerNetworkNominator(new DummyNetworkNominator(0,
+ WifiNetworkSelector.NetworkNominator.NOMINATOR_ID_SCORED));
// register a third network evaluator that also returns index 0, but with a different ID
- mWifiNetworkSelector.registerNetworkEvaluator(new DummyNetworkEvaluator(0,
- WifiNetworkSelector.NetworkEvaluator.EVALUATOR_ID_SAVED));
+ mWifiNetworkSelector.registerNetworkNominator(new DummyNetworkNominator(0,
+ WifiNetworkSelector.NetworkNominator.NOMINATOR_ID_SAVED));
String[] ssids = {"\"test1\"", "\"test2\""};
String[] bssids = {"6c:f3:7f:ae:8c:f3", "6c:f3:7f:ae:8c:f4"};
@@ -1391,18 +1392,6 @@ public class WifiNetworkSelectorTest extends WifiBaseTest {
}
/**
- * Test registerCandidateScorer.
- *
- * Just make sure it does not crash, for now.
- */
- @Test
- public void testRegisterCandidateScorer() {
- mWifiNetworkSelector.registerCandidateScorer(mCompatibilityScorer);
-
- test2GhzHighQuality5GhzAvailable();
- }
-
- /**
* Test that registering a new CandidateScorer causes it to be used
*/
@Test
@@ -1437,51 +1426,6 @@ public class WifiNetworkSelectorTest extends WifiBaseTest {
anyInt(), anyInt(), anyBoolean(), anyInt());
}
- /**
- * Tests that metrics are recorded for 2 scorers (legacy and another).
- */
- @Test
- public void testCandidateScorerMetrics_twoScorers() {
- mWifiNetworkSelector.registerCandidateScorer(mScoreCardBasedScorer);
-
- // add a second NetworkEvaluator that returns the second network in the scan list
- mWifiNetworkSelector.registerNetworkEvaluator(
- new DummyNetworkEvaluator(1, DUMMY_EVALUATOR_ID_2));
-
- test2GhzHighQuality5GhzAvailable();
-
- int registeredExpId = experimentIdFromIdentifier(mScoreCardBasedScorer.getIdentifier());
-
- // Wanted 2 times since test2GhzHighQuality5GhzAvailable() calls
- // WifiNetworkSelector.selectNetwork() twice
- verify(mWifiMetrics, times(2)).logNetworkSelectionDecision(registeredExpId,
- WifiNetworkSelector.LEGACY_CANDIDATE_SCORER_EXP_ID, true, 2);
- }
-
- /**
- * Tests that metrics are recorded for 2 scorers (legacy and legacy compatibility), when
- * legacy compatibility experiment is active.
- */
- @Test
- public void testCandidateScorerMetrics_twoScorers_experimentActive() {
- mWifiNetworkSelector.registerCandidateScorer(mCompatibilityScorer);
-
- // add a second NetworkEvaluator that returns the second network in the scan list
- mWifiNetworkSelector.registerNetworkEvaluator(
- new DummyNetworkEvaluator(1, DUMMY_EVALUATOR_ID_2));
-
- int compatibilityExpId = experimentIdFromIdentifier(mCompatibilityScorer.getIdentifier());
- mScoringParams.update("expid=" + compatibilityExpId);
- assertEquals(compatibilityExpId, mScoringParams.getExperimentIdentifier());
-
- test2GhzHighQuality5GhzAvailable();
-
- // Wanted 2 times since test2GhzHighQuality5GhzAvailable() calls
- // WifiNetworkSelector.selectNetwork() twice
- verify(mWifiMetrics, times(2)).logNetworkSelectionDecision(
- WifiNetworkSelector.LEGACY_CANDIDATE_SCORER_EXP_ID, compatibilityExpId, true, 2);
- }
-
private static final WifiCandidates.CandidateScorer NULL_SCORER =
new WifiCandidates.CandidateScorer() {
@Override
@@ -1496,60 +1440,6 @@ public class WifiNetworkSelectorTest extends WifiBaseTest {
}
};
- /**
- * Tests that metrics are recorded for 2 scorers (legacy and null) when one
- * candidate scorer returns null.
- */
- @Test
- public void testCandidateScorerMetrics_twoScorers_oneNull() {
- // add null scorer
- mWifiNetworkSelector.registerCandidateScorer(NULL_SCORER);
-
- // add a second NetworkEvaluator that returns the second network in the scan list
- mWifiNetworkSelector.registerNetworkEvaluator(
- new DummyNetworkEvaluator(1, DUMMY_EVALUATOR_ID_2));
-
- test2GhzHighQuality5GhzAvailable();
-
- int nullScorerId = experimentIdFromIdentifier(NULL_SCORER.getIdentifier());
-
- // Wanted 2 times since test2GhzHighQuality5GhzAvailable() calls
- // WifiNetworkSelector.selectNetwork() twice
- verify(mWifiMetrics, times(2)).logNetworkSelectionDecision(nullScorerId,
- WifiNetworkSelector.LEGACY_CANDIDATE_SCORER_EXP_ID, false, 2);
- }
-
- /**
- * Tests that metrics are recorded for 2 scorers (legacy and null) when the active
- * candidate scorer returns NONE.
- */
- @Test
- public void testCandidateScorerMetrics_twoScorers_nullActive() {
- int nullScorerId = experimentIdFromIdentifier(NULL_SCORER.getIdentifier());
-
- mScoringParams.update("expid=" + nullScorerId);
- assertEquals(nullScorerId, mScoringParams.getExperimentIdentifier());
-
- // add null scorer
- mWifiNetworkSelector.registerCandidateScorer(NULL_SCORER);
-
- // add a second NetworkEvaluator that returns the second network in the scan list
- mWifiNetworkSelector.registerNetworkEvaluator(
- new DummyNetworkEvaluator(1, DUMMY_EVALUATOR_ID_2));
-
- WifiConfiguration selected = mWifiNetworkSelector.selectNetwork(
- setUpTwoNetworks(-35, -40),
- EMPTY_BLACKLIST, mWifiInfo, false, true, true);
-
- assertNull(selected);
-
- verify(mWifiMetrics).logNetworkSelectionDecision(
- WifiNetworkSelector.LEGACY_CANDIDATE_SCORER_EXP_ID, nullScorerId, false, 2);
- verify(mWifiMetrics, atLeastOnce()).setNominatorForNetwork(anyInt(), anyInt());
- verify(mWifiMetrics, atLeastOnce()).setNetworkSelectorExperimentId(anyInt());
- verifyNoMoreInteractions(mWifiMetrics);
- }
-
private List<ScanDetail> setUpTwoNetworks(int rssiNetwork1, int rssiNetwork2) {
String[] ssids = {"\"test1\"", "\"test2\""};
String[] bssids = {"6c:f3:7f:ae:8c:f3", "6c:f3:7f:ae:8c:f4"};
@@ -1572,8 +1462,8 @@ public class WifiNetworkSelectorTest extends WifiBaseTest {
mWifiNetworkSelector.registerCandidateScorer(NULL_SCORER);
// add a second NetworkEvaluator that returns the second network in the scan list
- mWifiNetworkSelector.registerNetworkEvaluator(
- new DummyNetworkEvaluator(1, DUMMY_EVALUATOR_ID_2));
+ mWifiNetworkSelector.registerNetworkNominator(
+ new DummyNetworkNominator(1, DUMMY_EVALUATOR_ID_2));
int compatibilityExpId = experimentIdFromIdentifier(mCompatibilityScorer.getIdentifier());
mScoringParams.update("expid=" + compatibilityExpId);
@@ -1588,9 +1478,6 @@ public class WifiNetworkSelectorTest extends WifiBaseTest {
verify(mWifiMetrics, times(2)).logNetworkSelectionDecision(nullScorerId,
compatibilityExpId, false, 2);
- verify(mWifiMetrics, times(2)).logNetworkSelectionDecision(
- WifiNetworkSelector.LEGACY_CANDIDATE_SCORER_EXP_ID, compatibilityExpId, true, 2);
-
int expid = CompatibilityScorer.COMPATIBILITY_SCORER_DEFAULT_EXPID;
verify(mWifiMetrics, atLeastOnce()).setNetworkSelectorExperimentId(eq(expid));
}
@@ -1603,17 +1490,50 @@ public class WifiNetworkSelectorTest extends WifiBaseTest {
mWifiNetworkSelector.registerCandidateScorer(mThroughputScorer);
// add a second NetworkEvaluator that returns the second network in the scan list
- mWifiNetworkSelector.registerNetworkEvaluator(
- new DummyNetworkEvaluator(1, DUMMY_EVALUATOR_ID_2));
+ mWifiNetworkSelector.registerNetworkNominator(
+ new DummyNetworkNominator(1, DUMMY_EVALUATOR_ID_2));
test2GhzHighQuality5GhzAvailable();
int throughputExpId = experimentIdFromIdentifier(mThroughputScorer.getIdentifier());
+ int compatibilityExpId = experimentIdFromIdentifier(mCompatibilityScorer.getIdentifier());
// Wanted 2 times since test2GhzHighQuality5GhzAvailable() calls
// WifiNetworkSelector.selectNetwork() twice
verify(mWifiMetrics, times(2)).logNetworkSelectionDecision(throughputExpId,
- WifiNetworkSelector.LEGACY_CANDIDATE_SCORER_EXP_ID, true, 2);
+ compatibilityExpId, true, 2);
+ }
+
+ /**
+ * Tests that passpoint network candidate will update SSID with the latest scanDetail.
+ */
+ @Test
+ public void testPasspointCandidateUpdateWithLatestScanDetail() {
+ 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};
+ int[] securities = {SECURITY_EAP, SECURITY_EAP};
+ HashSet<String> blackList = new HashSet<>();
+ ScanDetailsAndWifiConfigs scanDetailsAndConfigs =
+ WifiNetworkSelectorTestUtil.setupScanDetailsAndConfigStore(ssids, bssids,
+ freqs, caps, levels, securities, mWifiConfigManager, mClock);
+ List<ScanDetail> scanDetails = scanDetailsAndConfigs.getScanDetails();
+ WifiConfiguration[] configs = scanDetailsAndConfigs.getWifiConfigs();
+ WifiConfiguration existingConfig = WifiConfigurationTestUtil.createPasspointNetwork();
+ existingConfig.SSID = ssids[1];
+ // Matched wifiConfig is an passpoint network with SSID from last scan.
+ when(mWifiConfigManager.getConfiguredNetwork(configs[0].networkId))
+ .thenReturn(existingConfig);
+ mWifiNetworkSelector.registerNetworkNominator(
+ new DummyNetworkNominator(0, DUMMY_EVALUATOR_ID_2));
+ WifiConfiguration candidate = mWifiNetworkSelector
+ .selectNetwork(scanDetails, blackList, mWifiInfo, false, true, true);
+ // Check if the wifiConfig is updated with the latest
+ verify(mWifiConfigManager).addOrUpdateNetwork(existingConfig,
+ existingConfig.creatorUid, existingConfig.creatorName);
+ assertEquals(ssids[0], candidate.SSID);
}
/**
diff --git a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java
index e4a3194f3..ef3f84afb 100644
--- a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java
@@ -863,13 +863,13 @@ public class PasspointManagerTest extends WifiBaseTest {
}
/**
- * Verify that a {code null} will be returned when no providers are installed.
+ * Verify that a empty list will be returned when no providers are installed.
*
* @throws Exception
*/
@Test
public void matchProviderWithNoProvidersInstalled() throws Exception {
- assertNull(mManager.matchProvider(createTestScanResult()));
+ assertTrue(mManager.matchProvider(createTestScanResult()).isEmpty());
}
/**
@@ -882,7 +882,7 @@ public class PasspointManagerTest extends WifiBaseTest {
addTestProvider(TEST_FQDN, TEST_FRIENDLY_NAME, TEST_PACKAGE);
when(mAnqpCache.getEntry(TEST_ANQP_KEY)).thenReturn(null);
- assertNull(mManager.matchProvider(createTestScanResult()));
+ assertTrue(mManager.matchProvider(createTestScanResult()).isEmpty());
// Verify that a request for ANQP elements is initiated.
verify(mAnqpRequestManager).requestANQPElements(eq(TEST_BSSID), any(ANQPNetworkKey.class),
anyBoolean(), anyBoolean());
@@ -901,8 +901,9 @@ public class PasspointManagerTest extends WifiBaseTest {
when(mAnqpCache.getEntry(TEST_ANQP_KEY)).thenReturn(entry);
when(provider.match(anyMap(), any(RoamingConsortium.class)))
.thenReturn(PasspointMatch.HomeProvider);
- Pair<PasspointProvider, PasspointMatch> result =
+ List<Pair<PasspointProvider, PasspointMatch>> results =
mManager.matchProvider(createTestScanResult());
+ Pair<PasspointProvider, PasspointMatch> result = results.get(0);
assertEquals(PasspointMatch.HomeProvider, result.second);
assertEquals(TEST_FQDN, result.first.getConfig().getHomeSp().getFqdn());
}
@@ -920,13 +921,55 @@ public class PasspointManagerTest extends WifiBaseTest {
when(mAnqpCache.getEntry(TEST_ANQP_KEY)).thenReturn(entry);
when(provider.match(anyMap(), any(RoamingConsortium.class)))
.thenReturn(PasspointMatch.RoamingProvider);
- Pair<PasspointProvider, PasspointMatch> result =
+ List<Pair<PasspointProvider, PasspointMatch>> results =
mManager.matchProvider(createTestScanResult());
+ Pair<PasspointProvider, PasspointMatch> result = results.get(0);
assertEquals(PasspointMatch.RoamingProvider, result.second);
assertEquals(TEST_FQDN, result.first.getConfig().getHomeSp().getFqdn());
}
/**
+ * When multiple providers matched for a single scanResult, when there is any home provider
+ * available, return all matched home provider. Otherwise return all roaming provider.
+ */
+ @Test
+ public void matchScanResultWithMultipleProviderAsHomeAndRoaming() {
+ // Only add roaming providers.
+ PasspointProvider roamingProvider1 =
+ addTestProvider(TEST_FQDN, TEST_FRIENDLY_NAME, TEST_PACKAGE);
+ PasspointProvider roamingProvider2 =
+ addTestProvider(TEST_FQDN2, TEST_FRIENDLY_NAME2, TEST_PACKAGE1);
+ ANQPData entry = new ANQPData(mClock, null);
+ when(mAnqpCache.getEntry(TEST_ANQP_KEY)).thenReturn(entry);
+ when(roamingProvider1.match(anyMap(), any(RoamingConsortium.class)))
+ .thenReturn(PasspointMatch.RoamingProvider);
+ when(roamingProvider2.match(anyMap(), any(RoamingConsortium.class)))
+ .thenReturn(PasspointMatch.RoamingProvider);
+ List<Pair<PasspointProvider, PasspointMatch>> results =
+ mManager.matchProvider(createTestScanResult());
+ // Return all matched roaming providers.
+ assertEquals(2, results.size());
+ for (Pair<PasspointProvider, PasspointMatch> result : results) {
+ assertEquals(PasspointMatch.RoamingProvider, result.second);
+ }
+ // Add home providers.
+ PasspointProvider homeProvider1 =
+ addTestProvider(TEST_FQDN + "home", TEST_FRIENDLY_NAME, TEST_PACKAGE);
+ PasspointProvider homeProvider2 =
+ addTestProvider(TEST_FQDN2 + "home", TEST_FRIENDLY_NAME2, TEST_PACKAGE1);
+ when(homeProvider1.match(anyMap(), any(RoamingConsortium.class)))
+ .thenReturn(PasspointMatch.HomeProvider);
+ when(homeProvider2.match(anyMap(), any(RoamingConsortium.class)))
+ .thenReturn(PasspointMatch.HomeProvider);
+ results = mManager.matchProvider(createTestScanResult());
+ // When home providers are available, should return all home providers.
+ assertEquals(2, results.size());
+ for (Pair<PasspointProvider, PasspointMatch> result : results) {
+ assertEquals(PasspointMatch.HomeProvider, result.second);
+ }
+ }
+
+ /**
* Verify that a {code null} will be returned when there is no matching provider.
*
* @throws Exception
@@ -939,7 +982,7 @@ public class PasspointManagerTest extends WifiBaseTest {
when(mAnqpCache.getEntry(TEST_ANQP_KEY)).thenReturn(entry);
when(provider.match(anyMap(), any(RoamingConsortium.class)))
.thenReturn(PasspointMatch.None);
- assertNull(mManager.matchProvider(createTestScanResult()));
+ assertTrue(mManager.matchProvider(createTestScanResult()).isEmpty());
}
/**
@@ -2066,8 +2109,9 @@ public class PasspointManagerTest extends WifiBaseTest {
when(providerNone.match(anyMap(), isNull()))
.thenReturn(PasspointMatch.None);
- Pair<PasspointProvider, PasspointMatch> result =
+ List<Pair<PasspointProvider, PasspointMatch>> results =
mManager.matchProvider(createTestScanResult());
+ Pair<PasspointProvider, PasspointMatch> result = results.get(0);
assertEquals(PasspointMatch.HomeProvider, result.second);
assertEquals(TEST_FQDN, result.first.getConfig().getHomeSp().getFqdn());
@@ -2112,8 +2156,9 @@ public class PasspointManagerTest extends WifiBaseTest {
when(providerNone.match(anyMap(), isNull()))
.thenReturn(PasspointMatch.None);
- Pair<PasspointProvider, PasspointMatch> result =
- mManager.matchProvider(createTestScanResult());
+ List<Pair<PasspointProvider, PasspointMatch>> results =
+ mManager.matchProvider(createTestScanResult());
+ Pair<PasspointProvider, PasspointMatch> result = results.get(0);
assertEquals(PasspointMatch.RoamingProvider, result.second);
assertEquals(TEST_FQDN2, result.first.getConfig().getHomeSp().getFqdn());
@@ -2160,8 +2205,9 @@ public class PasspointManagerTest extends WifiBaseTest {
when(providerNone.match(anyMap(), isNull()))
.thenReturn(PasspointMatch.None);
- Pair<PasspointProvider, PasspointMatch> result =
+ List<Pair<PasspointProvider, PasspointMatch>> results =
mManager.matchProvider(createTestScanResult());
+ Pair<PasspointProvider, PasspointMatch> result = results.get(0);
assertEquals(PasspointMatch.RoamingProvider, result.second);
assertEquals(TEST_FQDN2, result.first.getConfig().getHomeSp().getFqdn());
diff --git a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointNetworkEvaluatorTest.java b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointNetworkNominatorTest.java
index 96a8aac3d..7cf24abbb 100644
--- a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointNetworkEvaluatorTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointNetworkNominatorTest.java
@@ -19,7 +19,6 @@ package com.android.server.wifi.hotspot2;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.any;
@@ -27,6 +26,7 @@ import static org.mockito.Mockito.anyInt;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;
@@ -49,7 +49,10 @@ import com.android.server.wifi.ScanDetail;
import com.android.server.wifi.WifiConfigManager;
import com.android.server.wifi.WifiConfigurationTestUtil;
import com.android.server.wifi.WifiInjector;
-import com.android.server.wifi.WifiNetworkSelector.NetworkEvaluator.OnConnectableListener;
+import com.android.server.wifi.WifiNetworkSelector.NetworkNominator.OnConnectableListener;
+import com.android.server.wifi.hotspot2.anqp.ANQPElement;
+import com.android.server.wifi.hotspot2.anqp.Constants.ANQPElementType;
+import com.android.server.wifi.hotspot2.anqp.HSWanMetricsElement;
import com.android.server.wifi.util.ScanResultUtil;
import com.android.server.wifi.util.TelephonyUtil;
@@ -58,17 +61,21 @@ import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
/**
- * Unit tests for {@link com.android.server.wifi.hotspot2.PasspointNetworkEvaluator}.
+ * Unit tests for {@link PasspointNetworkNominator}.
*/
@SmallTest
-public class PasspointNetworkEvaluatorTest {
+public class PasspointNetworkNominatorTest {
// TODO(b/140763176): should extend WifiBaseTest, but if it does then it fails with NPE
private static final int TEST_NETWORK_ID = 1;
+ private static final int TEST_NETWORK_ID2 = 2;
private static final String TEST_SSID1 = "ssid1";
private static final String TEST_SSID2 = "ssid2";
private static final String TEST_BSSID1 = "01:23:45:56:78:9a";
@@ -79,6 +86,8 @@ public class PasspointNetworkEvaluatorTest {
private static final WifiConfiguration TEST_CONFIG2 = generateWifiConfig(TEST_FQDN2);
private static final PasspointProvider TEST_PROVIDER1 = generateProvider(TEST_CONFIG1);
private static final PasspointProvider TEST_PROVIDER2 = generateProvider(TEST_CONFIG2);
+ private ArgumentCaptor<WifiConfiguration> mWifiConfigurationArgumentCaptor =
+ ArgumentCaptor.forClass(WifiConfiguration.class);
@Mock PasspointManager mPasspointManager;
@Mock PasspointConfiguration mPasspointConfiguration;
@@ -88,7 +97,7 @@ public class PasspointNetworkEvaluatorTest {
@Mock CarrierNetworkConfig mCarrierNetworkConfig;
@Mock WifiInjector mWifiInjector;
LocalLog mLocalLog;
- PasspointNetworkEvaluator mEvaluator;
+ PasspointNetworkNominator mEvaluator;
/**
* Helper function for generating {@link WifiConfiguration} for testing.
@@ -130,6 +139,7 @@ public class PasspointNetworkEvaluatorTest {
NetworkDetail networkDetail = mock(NetworkDetail.class);
when(networkDetail.isInterworking()).thenReturn(true);
when(networkDetail.getAnt()).thenReturn(NetworkDetail.Ant.FreePublic);
+ when(networkDetail.isInternet()).thenReturn(true);
ScanDetail scanDetail = mock(ScanDetail.class);
ScanResult scanResult = new ScanResult();
@@ -149,7 +159,7 @@ public class PasspointNetworkEvaluatorTest {
public void setUp() throws Exception {
initMocks(this);
mLocalLog = new LocalLog(512);
- mEvaluator = new PasspointNetworkEvaluator(mPasspointManager, mWifiConfigManager, mLocalLog,
+ mEvaluator = new PasspointNetworkNominator(mPasspointManager, mWifiConfigManager, mLocalLog,
mWifiInjector, mSubscriptionManager);
// SIM is present
when(mSubscriptionManager.getActiveSubscriptionInfoList())
@@ -157,24 +167,23 @@ public class PasspointNetworkEvaluatorTest {
}
/**
- * Verify that null will be returned when evaluating scans without any matching providers.
- *
- * @throws Exception
+ * Verify that no candidate will be nominated when evaluating scans without any matching
+ * providers.
*/
@Test
- public void evaluateScansWithNoMatch() throws Exception {
+ public void evaluateScansWithNoMatch() {
List<ScanDetail> scanDetails = Arrays.asList(new ScanDetail[] {
generateScanDetail(TEST_SSID1, TEST_BSSID1),
generateScanDetail(TEST_SSID2, TEST_BSSID2)});
when(mPasspointManager.matchProvider(any(ScanResult.class))).thenReturn(null);
- assertEquals(null, mEvaluator.evaluateNetworks(
- scanDetails, null, null, false, false, mOnConnectableListener));
- verify(mOnConnectableListener, never()).onConnectable(any(), any(), anyInt());
+ mEvaluator.nominateNetworks(
+ scanDetails, null, null, false, false, mOnConnectableListener);
+ verify(mOnConnectableListener, never()).onConnectable(any(), any());
}
/**
* Verify that provider matching will not be performed when evaluating scans with no
- * interworking support, and null will be returned.
+ * interworking support, verify that no candidate will be nominated.
*
* @throws Exception
*/
@@ -186,16 +195,16 @@ public class PasspointNetworkEvaluatorTest {
when(scanDetail.getNetworkDetail()).thenReturn(networkDetail);
List<ScanDetail> scanDetails = Arrays.asList(new ScanDetail[] {scanDetail});
- assertEquals(null, mEvaluator.evaluateNetworks(
- scanDetails, null, null, false, false, mOnConnectableListener));
- verify(mOnConnectableListener, never()).onConnectable(any(), any(), anyInt());
+ mEvaluator.nominateNetworks(
+ scanDetails, null, null, false, false, mOnConnectableListener);
+ verify(mOnConnectableListener, never()).onConnectable(any(), any());
// Verify that no provider matching is performed.
verify(mPasspointManager, never()).matchProvider(any(ScanResult.class));
}
/**
* Verify that when a network matches a home provider is found, the correct network
- * information (WifiConfiguration) is setup and returned.
+ * information (WifiConfiguration) is setup and nominated.
*
* @throws Exception
*/
@@ -206,8 +215,8 @@ public class PasspointNetworkEvaluatorTest {
generateScanDetail(TEST_SSID2, TEST_BSSID2)});
// Setup matching providers for ScanDetail with TEST_SSID1.
- Pair<PasspointProvider, PasspointMatch> homeProvider = Pair.create(
- TEST_PROVIDER1, PasspointMatch.HomeProvider);
+ List<Pair<PasspointProvider, PasspointMatch>> homeProvider = new ArrayList<>();
+ homeProvider.add(Pair.create(TEST_PROVIDER1, PasspointMatch.HomeProvider));
// Return homeProvider for the first ScanDetail (TEST_SSID1) and a null (no match) for
// for the second (TEST_SSID2);
@@ -216,9 +225,9 @@ public class PasspointNetworkEvaluatorTest {
when(mWifiConfigManager.addOrUpdateNetwork(any(WifiConfiguration.class), anyInt()))
.thenReturn(new NetworkUpdateResult(TEST_NETWORK_ID));
when(mWifiConfigManager.getConfiguredNetwork(TEST_NETWORK_ID)).thenReturn(TEST_CONFIG1);
- assertNotNull(mEvaluator.evaluateNetworks(scanDetails, null, null, false,
- false, mOnConnectableListener));
- verify(mOnConnectableListener).onConnectable(any(), any(), anyInt());
+ mEvaluator.nominateNetworks(scanDetails, null, null, false,
+ false, mOnConnectableListener);
+ verify(mOnConnectableListener).onConnectable(any(), any());
// Verify the content of the WifiConfiguration that was added to WifiConfigManager.
ArgumentCaptor<WifiConfiguration> addedConfig =
@@ -239,19 +248,17 @@ public class PasspointNetworkEvaluatorTest {
/**
* Verify that when a network matches a roaming provider is found, the correct network
- * information (WifiConfiguration) is setup and returned.
- *
- * @throws Exception
+ * information (WifiConfiguration) is setup and nominated.
*/
@Test
- public void evaluateScansWithNetworkMatchingRoamingProvider() throws Exception {
+ public void evaluateScansWithNetworkMatchingRoamingProvider() {
List<ScanDetail> scanDetails = Arrays.asList(new ScanDetail[] {
generateScanDetail(TEST_SSID1, TEST_BSSID1),
generateScanDetail(TEST_SSID2, TEST_BSSID2)});
// Setup matching providers for ScanDetail with TEST_SSID1.
- Pair<PasspointProvider, PasspointMatch> roamingProvider = Pair.create(
- TEST_PROVIDER1, PasspointMatch.RoamingProvider);
+ List<Pair<PasspointProvider, PasspointMatch>> roamingProvider = new ArrayList<>();
+ roamingProvider.add(Pair.create(TEST_PROVIDER1, PasspointMatch.RoamingProvider));
// Return roamingProvider for the first ScanDetail (TEST_SSID1) and a null (no match) for
// for the second (TEST_SSID2);
@@ -260,9 +267,9 @@ public class PasspointNetworkEvaluatorTest {
when(mWifiConfigManager.addOrUpdateNetwork(any(WifiConfiguration.class), anyInt()))
.thenReturn(new NetworkUpdateResult(TEST_NETWORK_ID));
when(mWifiConfigManager.getConfiguredNetwork(TEST_NETWORK_ID)).thenReturn(TEST_CONFIG1);
- assertNotNull(mEvaluator.evaluateNetworks(scanDetails, null, null, false,
- false, mOnConnectableListener));
- verify(mOnConnectableListener).onConnectable(any(), any(), anyInt());
+ mEvaluator.nominateNetworks(scanDetails, null, null, false,
+ false, mOnConnectableListener);
+ verify(mOnConnectableListener).onConnectable(any(), any());
// Verify the content of the WifiConfiguration that was added to WifiConfigManager.
ArgumentCaptor<WifiConfiguration> addedConfig =
@@ -282,89 +289,39 @@ public class PasspointNetworkEvaluatorTest {
}
/**
- * Verify that when a network matches a home provider and another network matches a roaming
- * provider are found, the network that matched to a home provider is preferred.
+ * Verify that when a network matches a roaming provider is found for different scanDetails,
+ * will nominate both as the candidates.
*
* @throws Exception
*/
@Test
- public void evaluateScansWithHomeProviderNewtorkAndRoamingProviderNetwork() throws Exception {
+ public void evaluateScansWithHomeProviderNetworkAndRoamingProviderNetwork() throws Exception {
List<ScanDetail> scanDetails = Arrays.asList(new ScanDetail[] {
generateScanDetail(TEST_SSID1, TEST_BSSID1),
generateScanDetail(TEST_SSID2, TEST_BSSID2)});
// Setup matching providers for ScanDetail with TEST_SSID1.
- Pair<PasspointProvider, PasspointMatch> homeProvider = Pair.create(
- TEST_PROVIDER1, PasspointMatch.HomeProvider);
- Pair<PasspointProvider, PasspointMatch> roamingProvider = Pair.create(
- TEST_PROVIDER2, PasspointMatch.RoamingProvider);
+ List<Pair<PasspointProvider, PasspointMatch>> homeProvider = new ArrayList<>();
+ homeProvider.add(Pair.create(TEST_PROVIDER1, PasspointMatch.HomeProvider));
+ List<Pair<PasspointProvider, PasspointMatch>> roamingProvider = new ArrayList<>();
+ roamingProvider.add(Pair.create(TEST_PROVIDER2, PasspointMatch.RoamingProvider));
// Return homeProvider for the first ScanDetail (TEST_SSID1) and
// roamingProvider for the second (TEST_SSID2);
when(mPasspointManager.matchProvider(any(ScanResult.class)))
.thenReturn(homeProvider).thenReturn(roamingProvider);
when(mWifiConfigManager.addOrUpdateNetwork(any(WifiConfiguration.class), anyInt()))
- .thenReturn(new NetworkUpdateResult(TEST_NETWORK_ID));
+ .thenReturn(new NetworkUpdateResult(TEST_NETWORK_ID))
+ .thenReturn(new NetworkUpdateResult(TEST_NETWORK_ID + 1));
when(mWifiConfigManager.getConfiguredNetwork(TEST_NETWORK_ID)).thenReturn(TEST_CONFIG1);
- assertNotNull(mEvaluator.evaluateNetworks(scanDetails, null, null, false,
- false, mOnConnectableListener));
- verify(mOnConnectableListener).onConnectable(any(), any(), anyInt());
-
- // Verify the content of the WifiConfiguration that was added to WifiConfigManager.
- ArgumentCaptor<WifiConfiguration> addedConfig =
- ArgumentCaptor.forClass(WifiConfiguration.class);
- verify(mWifiConfigManager).addOrUpdateNetwork(addedConfig.capture(), anyInt());
- assertEquals(ScanResultUtil.createQuotedSSID(TEST_SSID1), addedConfig.getValue().SSID);
- assertEquals(TEST_FQDN1, addedConfig.getValue().FQDN);
- assertNotNull(addedConfig.getValue().enterpriseConfig);
- assertEquals("", addedConfig.getValue().enterpriseConfig.getAnonymousIdentity());
- assertTrue(addedConfig.getValue().isHomeProviderNetwork);
- verify(mWifiConfigManager).enableNetwork(
- eq(TEST_NETWORK_ID), eq(false), anyInt(), any());
- verify(mWifiConfigManager).setNetworkCandidateScanResult(
- eq(TEST_NETWORK_ID), any(ScanResult.class), anyInt());
- verify(mWifiConfigManager).updateScanDetailForNetwork(
- eq(TEST_NETWORK_ID), any(ScanDetail.class));
- }
-
- /**
- * Verify that when two networks both matches a home provider, with one of them being the
- * active network, the active network is preferred.
- *
- * @throws Exception
- */
- @Test
- public void evaluateScansWithActiveNetworkMatchingHomeProvider() throws Exception {
- List<ScanDetail> scanDetails = Arrays.asList(new ScanDetail[] {
- generateScanDetail(TEST_SSID1, TEST_BSSID1),
- generateScanDetail(TEST_SSID2, TEST_BSSID2)});
-
- // Setup matching providers for both ScanDetail.
- Pair<PasspointProvider, PasspointMatch> homeProvider = Pair.create(
- TEST_PROVIDER1, PasspointMatch.HomeProvider);
-
- // Setup currently connected network
- WifiConfiguration currentNetwork = new WifiConfiguration();
- currentNetwork.networkId = TEST_NETWORK_ID;
- currentNetwork.SSID = ScanResultUtil.createQuotedSSID(TEST_SSID2);
- String currentBssid = TEST_BSSID2;
-
- // Returning the same matching provider for both ScanDetail.
- when(mPasspointManager.matchProvider(any(ScanResult.class)))
- .thenReturn(homeProvider).thenReturn(homeProvider);
-
- WifiConfiguration config = mEvaluator.evaluateNetworks(scanDetails, currentNetwork,
- currentBssid, true, false, mOnConnectableListener);
-
- verify(mOnConnectableListener).onConnectable(any(), any(), anyInt());
-
- // Verify no new network is added to WifiConfigManager.
- verify(mWifiConfigManager, never()).addOrUpdateNetwork(
- any(WifiConfiguration.class), anyInt());
+ when(mWifiConfigManager.getConfiguredNetwork(TEST_NETWORK_ID + 1))
+ .thenReturn(TEST_CONFIG2);
+ mEvaluator.nominateNetworks(scanDetails, null, null, false,
+ false, mOnConnectableListener);
+ verify(mOnConnectableListener, times(2)).onConnectable(any(), any());
- // Verify current active network is returned.
- assertEquals(ScanResultUtil.createQuotedSSID(TEST_SSID2), config.SSID);
- assertEquals(TEST_NETWORK_ID, config.networkId);
+ verify(mWifiConfigManager, times(2))
+ .addOrUpdateNetwork(any(), anyInt());
}
/**
@@ -382,8 +339,8 @@ public class PasspointNetworkEvaluatorTest {
WifiEnterpriseConfig.Eap.SIM, WifiEnterpriseConfig.Phase2.NONE);
config.networkId = TEST_NETWORK_ID;
PasspointProvider testProvider = generateProvider(config);
- Pair<PasspointProvider, PasspointMatch> homeProvider = Pair.create(
- testProvider, PasspointMatch.HomeProvider);
+ List<Pair<PasspointProvider, PasspointMatch>> homeProvider = new ArrayList<>();
+ homeProvider.add(Pair.create(testProvider, PasspointMatch.HomeProvider));
when(mPasspointManager.matchProvider(any(ScanResult.class))).thenReturn(homeProvider);
when(testProvider.isSimCredential()).thenReturn(true);
// SIM is present
@@ -394,26 +351,29 @@ public class PasspointNetworkEvaluatorTest {
.thenReturn(new NetworkUpdateResult(TEST_NETWORK_ID));
when(mWifiConfigManager.getConfiguredNetwork(TEST_NETWORK_ID)).thenReturn(config);
- WifiConfiguration result = mEvaluator.evaluateNetworks(scanDetails, null, null, false,
+ mEvaluator.nominateNetworks(scanDetails, null, null, false,
false, mOnConnectableListener);
+ verify(mOnConnectableListener).onConnectable(any(),
+ mWifiConfigurationArgumentCaptor.capture());
+
- assertEquals("", result.enterpriseConfig.getAnonymousIdentity());
- assertTrue(TelephonyUtil.isSimEapMethod(result.enterpriseConfig.getEapMethod()));
+ assertEquals("", mWifiConfigurationArgumentCaptor.getValue()
+ .enterpriseConfig.getAnonymousIdentity());
+ assertTrue(TelephonyUtil.isSimEapMethod(
+ mWifiConfigurationArgumentCaptor.getValue().enterpriseConfig.getEapMethod()));
}
/**
* Verify that when the current active network is matched, the scan info associated with
* the network is updated.
- *
- * @throws Exception
*/
@Test
- public void evaluateScansMatchingActiveNetworkWithDifferentBSS() throws Exception {
+ public void evaluateScansMatchingActiveNetworkWithDifferentBSS() {
List<ScanDetail> scanDetails = Arrays.asList(new ScanDetail[] {
generateScanDetail(TEST_SSID1, TEST_BSSID2)});
// Setup matching provider.
- Pair<PasspointProvider, PasspointMatch> homeProvider = Pair.create(
- TEST_PROVIDER1, PasspointMatch.HomeProvider);
+ List<Pair<PasspointProvider, PasspointMatch>> homeProvider = new ArrayList<>();
+ homeProvider.add(Pair.create(TEST_PROVIDER1, PasspointMatch.HomeProvider));
// Setup currently connected network.
WifiConfiguration currentNetwork = new WifiConfiguration();
@@ -423,11 +383,14 @@ public class PasspointNetworkEvaluatorTest {
// Match the current connected network to a home provider.
when(mPasspointManager.matchProvider(any(ScanResult.class))).thenReturn(homeProvider);
+ when(mWifiConfigManager.addOrUpdateNetwork(any(WifiConfiguration.class), anyInt()))
+ .thenReturn(new NetworkUpdateResult(TEST_NETWORK_ID));
+ when(mWifiConfigManager.getConfiguredNetwork(TEST_NETWORK_ID)).thenReturn(currentNetwork);
- assertNotNull(mEvaluator.evaluateNetworks(scanDetails, currentNetwork,
- currentBssid, true, false, mOnConnectableListener));
+ mEvaluator.nominateNetworks(scanDetails, currentNetwork,
+ currentBssid, true, false, mOnConnectableListener);
- verify(mOnConnectableListener).onConnectable(any(), any(), anyInt());
+ verify(mOnConnectableListener).onConnectable(any(), any());
// Verify network candidate information is updated.
ArgumentCaptor<ScanResult> updatedCandidateScanResult =
@@ -443,8 +406,8 @@ public class PasspointNetworkEvaluatorTest {
}
/**
- * Verify that the current configuration for the passpoint network is disabled, it returns
- * {@null} for the candidate.
+ * Verify that the current configuration for the passpoint network is disabled, it will not
+ * nominated that network.
*/
@Test
public void evaluateNetworkWithDisabledWifiConfig() {
@@ -464,8 +427,8 @@ public class PasspointNetworkEvaluatorTest {
TEST_CONFIG1.networkId = TEST_NETWORK_ID;
// Setup matching providers for ScanDetail with TEST_SSID1.
- Pair<PasspointProvider, PasspointMatch> homeProvider = Pair.create(
- TEST_PROVIDER1, PasspointMatch.HomeProvider);
+ List<Pair<PasspointProvider, PasspointMatch>> homeProvider = new ArrayList<>();
+ homeProvider.add(Pair.create(TEST_PROVIDER1, PasspointMatch.HomeProvider));
// Return homeProvider for the first ScanDetail (TEST_SSID1) and a null (no match) for
// for the second (TEST_SSID2);
@@ -473,16 +436,16 @@ public class PasspointNetworkEvaluatorTest {
.thenReturn(null);
when(mWifiConfigManager.getConfiguredNetwork(anyString())).thenReturn(disableConfig);
- assertNull(mEvaluator.evaluateNetworks(scanDetails, null, null, false,
- false, mOnConnectableListener));
+ mEvaluator.nominateNetworks(scanDetails, null, null, false,
+ false, mOnConnectableListener);
verify(mWifiConfigManager, never()).addOrUpdateNetwork(any(WifiConfiguration.class),
anyInt());
- verify(mOnConnectableListener, never()).onConnectable(any(), any(), anyInt());
+ verify(mOnConnectableListener, never()).onConnectable(any(), any());
}
/**
* Verify that when a network matching a home provider is found, but the network was
- * disconnected previously by user, it returns {@code null} for candidate.
+ * disconnected previously by user, it will not nominated that network.
*/
@Test
public void evaluateScanResultWithHomeMatchButPreviouslyUserDisconnected() {
@@ -490,8 +453,8 @@ public class PasspointNetworkEvaluatorTest {
generateScanDetail(TEST_SSID1, TEST_BSSID1)});
// Setup matching providers for ScanDetail with TEST_SSID1.
- Pair<PasspointProvider, PasspointMatch> homeProvider = Pair.create(
- TEST_PROVIDER1, PasspointMatch.HomeProvider);
+ List<Pair<PasspointProvider, PasspointMatch>> homeProvider = new ArrayList<>();
+ homeProvider.add(Pair.create(TEST_PROVIDER1, PasspointMatch.HomeProvider));
// Return homeProvider for the first ScanDetail (TEST_SSID1).
when(mPasspointManager.matchProvider(any(ScanResult.class))).thenReturn(homeProvider);
@@ -500,8 +463,114 @@ public class PasspointNetworkEvaluatorTest {
when(mWifiConfigManager.getConfiguredNetwork(TEST_NETWORK_ID)).thenReturn(TEST_CONFIG1);
when(mWifiConfigManager.wasEphemeralNetworkDeleted("\"" + TEST_SSID1 + "\""))
.thenReturn(true);
- assertEquals(null, mEvaluator.evaluateNetworks(
- scanDetails, null, null, false, false, mOnConnectableListener));
- verify(mOnConnectableListener, never()).onConnectable(any(), any(), anyInt());
+ mEvaluator.nominateNetworks(
+ scanDetails, null, null, false, false, mOnConnectableListener);
+ verify(mOnConnectableListener, never()).onConnectable(any(), any());
+ }
+
+ /**
+ * Verify that when the WAN metrics status is 'LINK_STATUS_DOWN', it should be ignored.
+ * @throws Exception
+ */
+ @Test
+ public void evaluateScansWithNetworkMatchingHomeProviderWithAnqpLinkDown() throws Exception {
+ List<ScanDetail> scanDetails = Arrays.asList(new ScanDetail[]{
+ generateScanDetail(TEST_SSID1, TEST_BSSID1)});
+ // Setup matching providers for ScanDetail with TEST_SSID1.
+ List<Pair<PasspointProvider, PasspointMatch>> homeProvider = new ArrayList<>();
+ homeProvider.add(Pair.create(TEST_PROVIDER1, PasspointMatch.HomeProvider));
+
+ when(mPasspointManager.matchProvider(any(ScanResult.class))).thenReturn(homeProvider);
+ when(mWifiConfigManager.addOrUpdateNetwork(any(WifiConfiguration.class), anyInt()))
+ .thenReturn(new NetworkUpdateResult(TEST_NETWORK_ID));
+ when(mWifiConfigManager.getConfiguredNetwork(TEST_NETWORK_ID)).thenReturn(TEST_CONFIG1);
+ // Setup WAN metrics status is 'LINK_STATUS_DOWN'
+ HSWanMetricsElement wm = mock(HSWanMetricsElement.class);
+ Map<ANQPElementType, ANQPElement> anqpElements = new HashMap<>();
+ anqpElements.put(ANQPElementType.HSWANMetrics, wm);
+ when(mPasspointManager.getANQPElements(any(ScanResult.class)))
+ .thenReturn(anqpElements);
+ when(wm.getStatus()).thenReturn(HSWanMetricsElement.LINK_STATUS_DOWN);
+
+ mEvaluator.nominateNetworks(
+ scanDetails, null, null, false, false, mOnConnectableListener);
+ verify(mOnConnectableListener, never()).onConnectable(any(), any());
+ }
+
+ /**
+ * Verify that when same provider is match home and roaming for different scanDetail,
+ * the home provider matched scanDetail will be chosen.
+ */
+
+ @Test
+ public void evaluateScansWithNetworkMatchingBothHomeAndRoamingForSameProvider() {
+ ArgumentCaptor<WifiConfiguration> configurationArgumentCaptor =
+ ArgumentCaptor.forClass(WifiConfiguration.class);
+ List<ScanDetail> scanDetails = Arrays.asList(new ScanDetail[] {
+ generateScanDetail(TEST_SSID1, TEST_BSSID1),
+ generateScanDetail(TEST_SSID2, TEST_BSSID2)});
+
+ // Setup matching providers for ScanDetail.
+ List<Pair<PasspointProvider, PasspointMatch>> homeProvider = new ArrayList<>();
+ homeProvider.add(Pair.create(TEST_PROVIDER1, PasspointMatch.HomeProvider));
+ List<Pair<PasspointProvider, PasspointMatch>> roamingProvider = new ArrayList<>();
+ roamingProvider.add(Pair.create(TEST_PROVIDER1, PasspointMatch.RoamingProvider));
+ // Return homeProvider for the first ScanDetail (TEST_SSID1) and
+ // roamingProvider for the second (TEST_SSID2);
+ when(mPasspointManager.matchProvider(any(ScanResult.class)))
+ .thenReturn(roamingProvider).thenReturn(homeProvider);
+ when(mWifiConfigManager.addOrUpdateNetwork(any(WifiConfiguration.class), anyInt()))
+ .thenReturn(new NetworkUpdateResult(TEST_NETWORK_ID));
+ when(mWifiConfigManager.getConfiguredNetwork(TEST_NETWORK_ID)).thenReturn(TEST_CONFIG1);
+
+ mEvaluator.nominateNetworks(scanDetails, null, null, false,
+ false, mOnConnectableListener);
+ // verify Only home provider matched candidate will by chosen
+ verify(mOnConnectableListener).onConnectable(any(), configurationArgumentCaptor.capture());
+ assertTrue(configurationArgumentCaptor.getValue().isHomeProviderNetwork);
+ assertEquals(ScanResultUtil.createQuotedSSID(TEST_SSID2),
+ configurationArgumentCaptor.getValue().SSID);
+ }
+
+ /**
+ * For multiple scanDetails with matched providers, for each scanDetail nominate the best
+ * providers: if home available, return all home providers; otherwise return all roaming
+ * providers.
+ * ScanDetail1 matches home providerA, scanDetail2 matches roaming providerB, will nominate both
+ * matched pairs.
+ */
+ @Test
+ public void evaluateScansWithNetworkMatchingBothHomeAndRoamingForDifferentProvider() {
+ ArgumentCaptor<WifiConfiguration> configurationArgumentCaptor =
+ ArgumentCaptor.forClass(WifiConfiguration.class);
+ List<ScanDetail> scanDetails = Arrays.asList(new ScanDetail[] {
+ generateScanDetail(TEST_SSID1, TEST_BSSID1),
+ generateScanDetail(TEST_SSID2, TEST_BSSID2)});
+ // Setup matching providers for ScanDetail.
+ List<Pair<PasspointProvider, PasspointMatch>> homeProvider = new ArrayList<>();
+ homeProvider.add(Pair.create(TEST_PROVIDER1, PasspointMatch.HomeProvider));
+ List<Pair<PasspointProvider, PasspointMatch>> roamingProvider = new ArrayList<>();
+ roamingProvider.add(Pair.create(TEST_PROVIDER2, PasspointMatch.RoamingProvider));
+ // Return homeProvider for the first ScanDetail (TEST_SSID1) and
+ // roamingProvider for the second (TEST_SSID2);
+ when(mPasspointManager.matchProvider(any(ScanResult.class)))
+ .thenReturn(homeProvider).thenReturn(roamingProvider);
+ when(mWifiConfigManager.addOrUpdateNetwork(any(WifiConfiguration.class), anyInt()))
+ .thenReturn(new NetworkUpdateResult(TEST_NETWORK_ID))
+ .thenReturn(new NetworkUpdateResult(TEST_NETWORK_ID2));
+ when(mWifiConfigManager.getConfiguredNetwork(TEST_NETWORK_ID)).thenReturn(TEST_CONFIG1);
+ when(mWifiConfigManager.getConfiguredNetwork(TEST_NETWORK_ID2)).thenReturn(TEST_CONFIG2);
+
+ mEvaluator.nominateNetworks(scanDetails, null, null, false,
+ false, mOnConnectableListener);
+ // Nominate matched home provider for first ScanDetail (TEST_SSID1) and roaming provider for
+ // the second (TEST_SSID2).
+ verify(mOnConnectableListener, times(2))
+ .onConnectable(any(), configurationArgumentCaptor.capture());
+ List<WifiConfiguration> candidates = configurationArgumentCaptor.getAllValues();
+ assertTrue(candidates.stream().anyMatch(config -> config.isHomeProviderNetwork
+ && config.SSID.equals(ScanResultUtil.createQuotedSSID(TEST_SSID1))));
+ assertTrue(candidates.stream().anyMatch(config -> !config.isHomeProviderNetwork
+ && config.SSID.equals(ScanResultUtil.createQuotedSSID(TEST_SSID2))));
}
}