summaryrefslogtreecommitdiffstats
path: root/tests/wifitests/src/com/android/server/wifi/hotspot2
diff options
context:
space:
mode:
authorEcco Park <eccopark@google.com>2019-01-30 01:00:15 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2019-01-30 01:00:15 +0000
commitf71fed24f316cdf228312c0320077cb509d60788 (patch)
tree73f7a2c2597bca06950009e1c6805bd20d87dfee /tests/wifitests/src/com/android/server/wifi/hotspot2
parentf167c24a7c5634b42583551357fec7e2a3409dde (diff)
parent21c656b1685937afc33b5ea9f4a14fc5b0e14b79 (diff)
downloadandroid_frameworks_opt_net_wifi-f71fed24f316cdf228312c0320077cb509d60788.tar.gz
android_frameworks_opt_net_wifi-f71fed24f316cdf228312c0320077cb509d60788.tar.bz2
android_frameworks_opt_net_wifi-f71fed24f316cdf228312c0320077cb509d60788.zip
Merge "Passpoint: auto-connection for SIM-based profiles."
Diffstat (limited to 'tests/wifitests/src/com/android/server/wifi/hotspot2')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/hotspot2/ANQPMatcherTest.java96
-rw-r--r--tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java247
-rw-r--r--tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointNetworkEvaluatorTest.java110
3 files changed, 445 insertions, 8 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/hotspot2/ANQPMatcherTest.java b/tests/wifitests/src/com/android/server/wifi/hotspot2/ANQPMatcherTest.java
index 134d27d0a..4d4ea4487 100644
--- a/tests/wifitests/src/com/android/server/wifi/hotspot2/ANQPMatcherTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/hotspot2/ANQPMatcherTest.java
@@ -51,6 +51,9 @@ import java.util.Set;
*/
@SmallTest
public class ANQPMatcherTest {
+ private static final String TEST_MCC_MNC = "123456";
+ private static final String TEST_3GPP_FQDN = String.format("wlan.mnc%s.mcc%s.3gppnetwork.org",
+ TEST_MCC_MNC.substring(3), TEST_MCC_MNC.substring(0, 3));
/**
* Verify that domain name match will fail when a null Domain Name ANQP element is provided.
*
@@ -362,4 +365,97 @@ public class ANQPMatcherTest {
// The MCC-MNC provided in 3GPP Network ANQP element doesn't match the IMSI parameter.
assertFalse(ANQPMatcher.matchThreeGPPNetwork(element, imsiParam, simImsiList));
}
+
+ /**
+ * Verify that it will return a EAP-Method from the NAI realm when there is a matched realm in
+ * the NAIRealm element.
+ */
+ @Test
+ public void getEapMethodForNAIRealmWithCarrierInMatch() {
+ // Test data.
+ String realm = TEST_3GPP_FQDN;
+ int eapMethodID = EAPConstants.EAP_AKA;
+
+ // Create a realm that has the EAP method
+ EAPMethod method = new EAPMethod(eapMethodID, null);
+ NAIRealmData realmData = new NAIRealmData(
+ Arrays.asList(new String[]{realm}), Arrays.asList(new EAPMethod[]{method}));
+
+ // Setup NAI Realm element.
+ NAIRealmElement element = new NAIRealmElement(
+ Arrays.asList(new NAIRealmData[]{realmData}));
+
+ assertEquals(EAPConstants.EAP_AKA,
+ ANQPMatcher.getCarrierEapMethodFromMatchingNAIRealm(TEST_3GPP_FQDN, element));
+ }
+
+ /**
+ * Verify that it will return -1 when there is a matched realm in the NAIRealm element, but it
+ * does not have a EAP Method.
+ */
+ @Test
+ public void getEapMethodForNAIRealmWithCarrierInMatchButNotEapMethod() {
+ // Test data.
+ String realm = TEST_3GPP_FQDN;
+ NAIRealmData realmData = new NAIRealmData(Arrays.asList(new String[]{realm}),
+ new ArrayList<>());
+
+ // Setup NAI Realm element.
+ NAIRealmElement element = new NAIRealmElement(
+ Arrays.asList(new NAIRealmData[]{realmData}));
+
+ assertEquals(-1,
+ ANQPMatcher.getCarrierEapMethodFromMatchingNAIRealm(TEST_3GPP_FQDN, element));
+ }
+
+ /**
+ * Verify that it will return -1 when there is a matched realm in the NAIRealm element, but it
+ * does have non-carrier EAP-method.
+ */
+ @Test
+ public void getEapMethodForNAIRealmWithCarrierInMatchButNotCarrierEapMethod() {
+ // Test data.
+ String realm = TEST_3GPP_FQDN;
+ int eapMethodID = EAPConstants.EAP_TTLS;
+ NonEAPInnerAuth authParam = new NonEAPInnerAuth(NonEAPInnerAuth.AUTH_TYPE_MSCHAP);
+ Set<AuthParam> authSet = new HashSet<>();
+ authSet.add(authParam);
+ Map<Integer, Set<AuthParam>> authMap = new HashMap<>();
+ authMap.put(authParam.getAuthTypeID(), authSet);
+
+ // Setup NAI Realm element.
+ EAPMethod method = new EAPMethod(eapMethodID, authMap);
+ NAIRealmData realmData = new NAIRealmData(
+ Arrays.asList(new String[]{realm}), Arrays.asList(new EAPMethod[]{method}));
+ NAIRealmElement element = new NAIRealmElement(
+ Arrays.asList(new NAIRealmData[]{realmData}));
+
+ assertEquals(-1,
+ ANQPMatcher.getCarrierEapMethodFromMatchingNAIRealm(TEST_3GPP_FQDN, element));
+ }
+
+ /**
+ * Verify that it will return -1 when there is no matched realm in the NAIRealm element.
+ */
+ @Test
+ public void getEapMethodForNAIRealmWithCarrierInNoMatch() {
+ // Test data.
+ String realm = "test.com";
+ int eapMethodID = EAPConstants.EAP_TTLS;
+ NonEAPInnerAuth authParam = new NonEAPInnerAuth(NonEAPInnerAuth.AUTH_TYPE_MSCHAP);
+ Set<AuthParam> authSet = new HashSet<>();
+ authSet.add(authParam);
+ Map<Integer, Set<AuthParam>> authMap = new HashMap<>();
+ authMap.put(authParam.getAuthTypeID(), authSet);
+
+ // Setup NAI Realm element.
+ EAPMethod method = new EAPMethod(eapMethodID, authMap);
+ NAIRealmData realmData = new NAIRealmData(
+ Arrays.asList(new String[]{realm}), Arrays.asList(new EAPMethod[]{method}));
+ NAIRealmElement element = new NAIRealmElement(
+ Arrays.asList(new NAIRealmData[]{realmData}));
+
+ assertEquals(-1,
+ ANQPMatcher.getCarrierEapMethodFromMatchingNAIRealm(TEST_3GPP_FQDN, element));
+ }
}
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 35b66c2b8..2442751b4 100644
--- a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java
@@ -30,6 +30,7 @@ import static android.net.wifi.WifiManager.EXTRA_URL;
import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder;
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.assertThat;
import static org.junit.Assert.assertTrue;
@@ -67,15 +68,18 @@ import android.net.wifi.hotspot2.pps.HomeSp;
import android.os.Looper;
import android.os.UserHandle;
import android.os.test.TestLooper;
+import android.telephony.TelephonyManager;
import android.util.Base64;
import android.util.Pair;
import androidx.test.filters.SmallTest;
+import com.android.dx.mockito.inline.extended.ExtendedMockito;
import com.android.server.wifi.Clock;
import com.android.server.wifi.FakeKeys;
import com.android.server.wifi.IMSIParameter;
import com.android.server.wifi.SIMAccessor;
+import com.android.server.wifi.ScanDetail;
import com.android.server.wifi.WifiConfigManager;
import com.android.server.wifi.WifiConfigStore;
import com.android.server.wifi.WifiKeyStore;
@@ -86,7 +90,10 @@ import com.android.server.wifi.hotspot2.anqp.Constants.ANQPElementType;
import com.android.server.wifi.hotspot2.anqp.DomainNameElement;
import com.android.server.wifi.hotspot2.anqp.HSOsuProvidersElement;
import com.android.server.wifi.hotspot2.anqp.I18Name;
+import com.android.server.wifi.hotspot2.anqp.NAIRealmData;
+import com.android.server.wifi.hotspot2.anqp.NAIRealmElement;
import com.android.server.wifi.hotspot2.anqp.OsuProviderInfo;
+import com.android.server.wifi.hotspot2.anqp.eap.EAPMethod;
import com.android.server.wifi.util.InformationElementUtil;
import com.android.server.wifi.util.InformationElementUtil.RoamingConsortium;
@@ -121,7 +128,7 @@ public class PasspointManagerTest {
private static final String TEST_FRIENDLY_NAME = "friendly name";
private static final String TEST_FRIENDLY_NAME2 = "second friendly name";
private static final String TEST_REALM = "realm.test.com";
- private static final String TEST_IMSI = "1234*";
+ private static final String TEST_IMSI = "123456*";
private static final IMSIParameter TEST_IMSI_PARAM = IMSIParameter.build(TEST_IMSI);
private static final long TEST_BSSID = 0x112233445566L;
@@ -131,6 +138,9 @@ public class PasspointManagerTest {
private static final String TEST_BSSID_STRING2 = "11:22:33:44:55:77";
private static final String TEST_SSID3 = "TestSSID3";
private static final String TEST_BSSID_STRING3 = "11:22:33:44:55:88";
+ private static final String TEST_MCC_MNC = "123456";
+ private static final String TEST_3GPP_FQDN = String.format("wlan.mnc%s.mcc%s.3gppnetwork.org",
+ TEST_MCC_MNC.substring(3), TEST_MCC_MNC.substring(0, 3));
private static final long TEST_HESSID = 0x5678L;
private static final int TEST_ANQP_DOMAIN_ID = 0;
@@ -286,16 +296,17 @@ public class PasspointManagerTest {
*
* @return {@link PasspointConfiguration}
*/
- private PasspointConfiguration createTestConfigWithSimCredential() {
+ private PasspointConfiguration createTestConfigWithSimCredential(String fqdn, String imsi,
+ String realm) {
PasspointConfiguration config = new PasspointConfiguration();
HomeSp homeSp = new HomeSp();
- homeSp.setFqdn(TEST_FQDN);
+ homeSp.setFqdn(fqdn);
homeSp.setFriendlyName(TEST_FRIENDLY_NAME);
config.setHomeSp(homeSp);
Credential credential = new Credential();
credential.setRealm(TEST_REALM);
Credential.SimCredential simCredential = new Credential.SimCredential();
- simCredential.setImsi(TEST_IMSI);
+ simCredential.setImsi(imsi);
simCredential.setEapType(EAPConstants.EAP_SIM);
credential.setSimCredential(simCredential);
config.setCredential(credential);
@@ -320,6 +331,23 @@ public class PasspointManagerTest {
}
/**
+ * Helper function for adding a test provider with SIM credentials to the manager. Return the
+ * mock provider that's added to the manager.
+ *
+ * @return {@link PasspointProvider}
+ */
+ private PasspointProvider addTestCarrierProvider(String fqdn, String imsi, String realm) {
+ PasspointConfiguration config = createTestConfigWithSimCredential(fqdn, imsi, realm);
+ PasspointProvider provider = createMockProvider(config);
+ when(mObjectFactory.makePasspointProvider(eq(config), eq(mWifiKeyStore),
+ eq(mSimAccessor), anyLong(), eq(TEST_CREATOR_UID))).thenReturn(provider);
+
+ assertTrue(mManager.addOrUpdateProvider(config, TEST_CREATOR_UID));
+
+ return provider;
+ }
+
+ /**
* Helper function for creating a ScanResult for testing.
*
* @return {@link ScanResult}
@@ -372,6 +400,31 @@ public class PasspointManagerTest {
}
/**
+ * Helper function for generating {@link ScanDetail} for testing.
+ */
+ private ScanDetail generateScanDetail(String ssid, String bssid, long hessid, int anqpDomaiId,
+ boolean isPasspoint) {
+ NetworkDetail networkDetail = mock(NetworkDetail.class);
+
+ ScanDetail scanDetail = mock(ScanDetail.class);
+ ScanResult scanResult = new ScanResult();
+ scanResult.SSID = ssid;
+ scanResult.BSSID = bssid;
+ scanResult.hessid = hessid;
+ scanResult.anqpDomainId = anqpDomaiId;
+ if (isPasspoint) {
+ lenient().when(networkDetail.isInterworking()).thenReturn(true);
+ scanResult.flags = ScanResult.FLAG_PASSPOINT_NETWORK;
+ } else {
+ lenient().when(networkDetail.isInterworking()).thenReturn(false);
+ }
+
+ lenient().when(scanDetail.getScanResult()).thenReturn(scanResult);
+ lenient().when(scanDetail.getNetworkDetail()).thenReturn(networkDetail);
+ return scanDetail;
+ }
+
+ /**
* Verify that the ANQP elements will be added to the ANQP cache on receiving a successful
* response.
*
@@ -587,7 +640,8 @@ public class PasspointManagerTest {
*/
@Test
public void addRemoveProviderWithValidSimCredential() throws Exception {
- PasspointConfiguration config = createTestConfigWithSimCredential();
+ PasspointConfiguration config = createTestConfigWithSimCredential(TEST_FQDN, TEST_IMSI,
+ TEST_REALM);
PasspointProvider provider = createMockProvider(config);
when(mObjectFactory.makePasspointProvider(eq(config), eq(mWifiKeyStore),
eq(mSimAccessor), anyLong(), eq(TEST_CREATOR_UID))).thenReturn(provider);
@@ -630,7 +684,8 @@ public class PasspointManagerTest {
@Test
public void addProviderWithExistingConfig() throws Exception {
// Add a provider with the original configuration.
- PasspointConfiguration origConfig = createTestConfigWithSimCredential();
+ PasspointConfiguration origConfig = createTestConfigWithSimCredential(TEST_FQDN, TEST_IMSI,
+ TEST_REALM);
PasspointProvider origProvider = createMockProvider(origConfig);
when(mObjectFactory.makePasspointProvider(eq(origConfig), eq(mWifiKeyStore),
eq(mSimAccessor), anyLong(), eq(TEST_CREATOR_UID))).thenReturn(origProvider);
@@ -1518,4 +1573,184 @@ public class PasspointManagerTest {
assertEquals(true,
mManager.startSubscriptionProvisioning(TEST_UID, osuProvider, mCallback));
}
+
+ /**
+ * Verify that it will return {@code null} if the EAP-Method provided is not a carrier
+ * EAP-Method.
+ */
+ @Test
+ public void verifyCreateEphemeralPasspointConfigurationWithNonCarrierEapMethod() {
+ // static mocking
+ MockitoSession session = ExtendedMockito.mockitoSession().mockStatic(
+ TelephonyManager.class).startMocking();
+ try {
+ TelephonyManager telephonyManager = mock(TelephonyManager.class);
+ when(TelephonyManager.from(any(Context.class))).thenReturn(telephonyManager);
+ when(telephonyManager.getNetworkOperator()).thenReturn("123456");
+ PasspointManager passpointManager = new PasspointManager(mContext, mWifiNative,
+ mWifiKeyStore, mClock,
+ mSimAccessor, mObjectFactory, mWifiConfigManager, mWifiConfigStore,
+ mWifiMetrics);
+
+ assertNull(passpointManager.createEphemeralPasspointConfigForCarrier(
+ EAPConstants.EAP_TLS));
+ } finally {
+ session.finishMocking();
+ }
+ }
+
+ /**
+ * Verify that it creates an ephemeral Passpoint configuration for the carrier.
+ */
+ @Test
+ public void verifyCreateEphemeralPasspointConfigurationWithCarrierEapMethod() {
+ // static mocking
+ MockitoSession session = ExtendedMockito.mockitoSession().mockStatic(
+ TelephonyManager.class).startMocking();
+ try {
+ TelephonyManager telephonyManager = mock(TelephonyManager.class);
+ String mccmnc = "123456";
+ when(TelephonyManager.from(any(Context.class))).thenReturn(telephonyManager);
+ when(telephonyManager.getNetworkOperator()).thenReturn(mccmnc);
+ when(telephonyManager.getNetworkOperatorName()).thenReturn("test");
+
+ PasspointManager passpointManager = new PasspointManager(mContext, mWifiNative,
+ mWifiKeyStore, mClock,
+ mSimAccessor, mObjectFactory, mWifiConfigManager, mWifiConfigStore,
+ mWifiMetrics);
+
+ PasspointConfiguration result =
+ passpointManager.createEphemeralPasspointConfigForCarrier(
+ EAPConstants.EAP_AKA);
+
+ assertNotNull(result);
+ assertTrue(result.validate());
+ assertEquals(Utils.getRealmForMccMnc(mccmnc), result.getHomeSp().getFqdn());
+ assertEquals(mccmnc + "*", result.getCredential().getSimCredential().getImsi());
+ } finally {
+ session.finishMocking();
+ }
+ }
+
+ /**
+ * Verify that it will not install the Passpoint configuration with Non-Carrier EAP method.
+ */
+ @Test
+ public void verifyInstallEphemeralPasspointConfigurationWithNonCarrierEapMethod() {
+ when(mWifiConfigManager.isSimPresent()).thenReturn(true);
+ PasspointConfiguration config = createTestConfigWithUserCredential("abc.com", "test");
+ PasspointProvider provider = createMockProvider(config);
+ when(mObjectFactory.makePasspointProvider(eq(config), eq(mWifiKeyStore),
+ eq(mSimAccessor), anyLong(), anyInt())).thenReturn(provider);
+
+ assertFalse(mManager.installEphemeralPasspointConfigForCarrier(config));
+ }
+
+ /**
+ * Verify that it installs the carrier Passpoint configuration successfully.
+ */
+ @Test
+ public void verifyInstallEphemeralPasspointConfiguration() {
+ when(mWifiConfigManager.isSimPresent()).thenReturn(true);
+ PasspointConfiguration config = createTestConfigWithSimCredential(TEST_FQDN, TEST_IMSI,
+ TEST_REALM);
+ PasspointProvider provider = createMockProvider(config);
+ when(mObjectFactory.makePasspointProvider(eq(config), eq(mWifiKeyStore),
+ eq(mSimAccessor), anyLong(), anyInt())).thenReturn(provider);
+
+ assertTrue(mManager.installEphemeralPasspointConfigForCarrier(config));
+ }
+
+ /**
+ * Verify that it returns {@code true} when it has Carrier Provider.
+ */
+ @Test
+ public void verifyHasProviderForCarrierWithMatch() {
+ addTestCarrierProvider(TEST_3GPP_FQDN, TEST_MCC_MNC, TEST_3GPP_FQDN);
+
+ assertTrue(mManager.hasCarrierProvider(TEST_MCC_MNC));
+ }
+
+ /**
+ * Verify that it returns {@code false} when it does not have Carrier Provider.
+ */
+ @Test
+ public void verifyHasProviderForCarrierWithNoMatch() {
+ addTestProvider(TEST_FQDN, TEST_FRIENDLY_NAME);
+
+ assertFalse(mManager.hasCarrierProvider(TEST_MCC_MNC));
+ }
+
+ /**
+ * Verify that it returns a carrier EAP-method from NAI-Realm matched with the carrier.
+ */
+ @Test
+ public void verifyFindEapMethodFromNAIRealmMatchedWithCarrierWithMatch() {
+ // static mocking
+ MockitoSession session = ExtendedMockito.mockitoSession().mockStatic(
+ TelephonyManager.class).mockStatic(
+ InformationElementUtil.class).startMocking();
+ try {
+ TelephonyManager telephonyManager = mock(TelephonyManager.class);
+ when(TelephonyManager.from(any(Context.class))).thenReturn(telephonyManager);
+ when(telephonyManager.getNetworkOperator()).thenReturn(TEST_MCC_MNC);
+ when(mWifiConfigManager.isSimPresent()).thenReturn(true);
+ List<ScanDetail> scanDetails = new ArrayList<>();
+ scanDetails.add(generateScanDetail(TEST_SSID, TEST_BSSID_STRING, TEST_HESSID,
+ TEST_ANQP_DOMAIN_ID, true));
+ InformationElementUtil.Vsa vsa = new InformationElementUtil.Vsa();
+
+ // ANQP_DOMAIN_ID(TEST_ANQP_KEY)
+ vsa.anqpDomainID = TEST_ANQP_DOMAIN_ID;
+ when(InformationElementUtil.getHS2VendorSpecificIE(isNull())).thenReturn(vsa);
+ Map<ANQPElementType, ANQPElement> anqpElementMapOfAp1 = new HashMap<>();
+ List<NAIRealmData> realmDataList = new ArrayList<>();
+ realmDataList.add(new NAIRealmData(Arrays.asList(TEST_3GPP_FQDN),
+ Arrays.asList(new EAPMethod(EAPConstants.EAP_AKA, null))));
+ anqpElementMapOfAp1.put(ANQPElementType.ANQPNAIRealm,
+ new NAIRealmElement(realmDataList));
+
+ ANQPData anqpData = new ANQPData(mClock, anqpElementMapOfAp1);
+ when(mAnqpCache.getEntry(TEST_ANQP_KEY)).thenReturn(anqpData);
+
+ PasspointManager passpointManager = new PasspointManager(mContext, mWifiNative,
+ mWifiKeyStore, mClock,
+ mSimAccessor, mObjectFactory, mWifiConfigManager, mWifiConfigStore,
+ mWifiMetrics);
+
+ assertEquals(EAPConstants.EAP_AKA,
+ passpointManager.findEapMethodFromNAIRealmMatchedWithCarrier(scanDetails));
+ } finally {
+ session.finishMocking();
+ }
+ }
+
+ /**
+ * Verify that it returns -1 when there is no NAI-Realm matched with the carrier.
+ */
+ @Test
+ public void verifyFindEapMethodFromNAIRealmMatchedWithCarrierWithNoMatch() {
+ // static mocking
+ MockitoSession session = ExtendedMockito.mockitoSession().mockStatic(
+ TelephonyManager.class).mockStatic(
+ InformationElementUtil.class).startMocking();
+ try {
+ TelephonyManager telephonyManager = mock(TelephonyManager.class);
+ when(TelephonyManager.from(any(Context.class))).thenReturn(telephonyManager);
+ when(telephonyManager.getNetworkOperator()).thenReturn(TEST_MCC_MNC);
+ when(mWifiConfigManager.isSimPresent()).thenReturn(true);
+ List<ScanDetail> scanDetails = new ArrayList<>();
+ scanDetails.add(generateScanDetail(TEST_SSID, TEST_BSSID_STRING, 0, 0, false));
+
+ PasspointManager passpointManager = new PasspointManager(mContext, mWifiNative,
+ mWifiKeyStore, mClock,
+ mSimAccessor, mObjectFactory, mWifiConfigManager, mWifiConfigStore,
+ mWifiMetrics);
+
+ assertEquals(-1,
+ passpointManager.findEapMethodFromNAIRealmMatchedWithCarrier(scanDetails));
+ } finally {
+ session.finishMocking();
+ }
+ }
}
diff --git a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointNetworkEvaluatorTest.java b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointNetworkEvaluatorTest.java
index dc7e9bb3b..fe0b26bac 100644
--- a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointNetworkEvaluatorTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointNetworkEvaluatorTest.java
@@ -20,6 +20,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.anyInt;
import static org.mockito.Mockito.eq;
@@ -29,15 +30,18 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;
+import android.net.wifi.EAPConstants;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.hotspot2.PasspointConfiguration;
import android.net.wifi.hotspot2.pps.HomeSp;
+import android.telephony.TelephonyManager;
import android.util.LocalLog;
import android.util.Pair;
import androidx.test.filters.SmallTest;
+import com.android.server.wifi.CarrierNetworkConfig;
import com.android.server.wifi.NetworkUpdateResult;
import com.android.server.wifi.ScanDetail;
import com.android.server.wifi.WifiConfigManager;
@@ -70,8 +74,11 @@ public class PasspointNetworkEvaluatorTest {
private static final PasspointProvider TEST_PROVIDER2 = generateProvider(TEST_CONFIG2);
@Mock PasspointManager mPasspointManager;
+ @Mock PasspointConfiguration mPasspointConfiguration;
@Mock WifiConfigManager mWifiConfigManager;
@Mock OnConnectableListener mOnConnectableListener;
+ @Mock TelephonyManager mTelephonyManager;
+ @Mock CarrierNetworkConfig mCarrierNetworkConfig;
LocalLog mLocalLog;
PasspointNetworkEvaluator mEvaluator;
@@ -108,7 +115,7 @@ public class PasspointNetworkEvaluatorTest {
* Helper function for generating {@link ScanDetail} for testing.
*
* @param ssid The SSID associated with the scan
- * @param rssiLevel The RSSI level associated with the scan
+ * @param bssid The BSSID associated with the scan
* @return {@link ScanDetail}
*/
private static ScanDetail generateScanDetail(String ssid, String bssid) {
@@ -135,7 +142,9 @@ public class PasspointNetworkEvaluatorTest {
initMocks(this);
mLocalLog = new LocalLog(512);
mEvaluator = new PasspointNetworkEvaluator(mPasspointManager, mWifiConfigManager,
- mLocalLog);
+ mLocalLog, mCarrierNetworkConfig, mTelephonyManager);
+ when(mWifiConfigManager.isSimPresent()).thenReturn(true);
+ when(mTelephonyManager.getNetworkOperator()).thenReturn("123456");
}
/**
@@ -367,6 +376,103 @@ public class PasspointNetworkEvaluatorTest {
}
/**
+ * Verify that it never creates an ephemeral Passpoint Configuration when the carrier does not
+ * support encrypted IMSI.
+ */
+ @Test
+ public void skipCreateEphemeralPasspointConfigurationWhenNoSupportEncryptedIMSI() {
+ // Setup ScanDetail and match providers.
+ List<ScanDetail> scanDetails = Arrays.asList(new ScanDetail[] {
+ generateScanDetail(TEST_SSID1, TEST_BSSID1)});
+ when(mCarrierNetworkConfig.isCarrierEncryptionInfoAvailable()).thenReturn(false);
+ when(mPasspointManager.hasCarrierProvider(anyString())).thenReturn(false);
+
+ assertEquals(null, mEvaluator.evaluateNetworks(
+ scanDetails, null, null, false, false, mOnConnectableListener));
+ verify(mPasspointManager, never()).createEphemeralPasspointConfigForCarrier(anyInt());
+ }
+
+ /**
+ * Verify that it never creates an ephemeral Passpoint Configuration when there is no SIM on the
+ * device.
+ */
+ @Test
+ public void skipCreateEphemeralPasspointConfigurationWithoutSIMCard() {
+ // Setup ScanDetail and match providers.
+ List<ScanDetail> scanDetails = Arrays.asList(new ScanDetail[] {
+ generateScanDetail(TEST_SSID1, TEST_BSSID1)});
+ when(mWifiConfigManager.isSimPresent()).thenReturn(false);
+ when(mPasspointManager.hasCarrierProvider(anyString())).thenReturn(false);
+ when(mCarrierNetworkConfig.isCarrierEncryptionInfoAvailable()).thenReturn(true);
+
+ assertEquals(null, mEvaluator.evaluateNetworks(
+ scanDetails, null, null, false, false, mOnConnectableListener));
+ verify(mPasspointManager, never()).createEphemeralPasspointConfigForCarrier(anyInt());
+ }
+
+ /**
+ * Verify that it never creates an ephemeral Passpoint Configuration when the profile for the
+ * carrier already exists.
+ */
+ @Test
+ public void skipCreateEphemeralPasspointConfigurationWhenProfileExists() {
+ // Setup ScanDetail and match providers.
+ List<ScanDetail> scanDetails = Arrays.asList(new ScanDetail[] {
+ generateScanDetail(TEST_SSID1, TEST_BSSID1)});
+ when(mCarrierNetworkConfig.isCarrierEncryptionInfoAvailable()).thenReturn(true);
+ when(mPasspointManager.hasCarrierProvider(anyString())).thenReturn(true);
+
+ assertEquals(null, mEvaluator.evaluateNetworks(
+ scanDetails, null, null, false, false, mOnConnectableListener));
+ verify(mPasspointManager, never()).createEphemeralPasspointConfigForCarrier(anyInt());
+ }
+
+ /**
+ * Verify that it creates an ephemeral Passpoint Configuration when a EAP-Method is found from
+ * NAI realms matched with the carrier.
+ */
+ @Test
+ public void createEphemeralPasspointConfigurationWhenEapMethodIsFoundFromMatchingNAIRealm() {
+ // Setup ScanDetail
+ List<ScanDetail> scanDetails = Arrays.asList(new ScanDetail[]{
+ generateScanDetail(TEST_SSID1, TEST_BSSID1)});
+ when(mCarrierNetworkConfig.isCarrierEncryptionInfoAvailable()).thenReturn(true);
+ when(mPasspointManager.hasCarrierProvider(anyString())).thenReturn(false);
+ when(mPasspointManager.findEapMethodFromNAIRealmMatchedWithCarrier(
+ any(List.class))).thenReturn(
+ EAPConstants.EAP_AKA);
+
+ assertEquals(null, mEvaluator.evaluateNetworks(
+ scanDetails, null, null, false, false, mOnConnectableListener));
+ verify(mPasspointManager).findEapMethodFromNAIRealmMatchedWithCarrier(any(List.class));
+ verify(mPasspointManager).createEphemeralPasspointConfigForCarrier(
+ eq(EAPConstants.EAP_AKA));
+ }
+
+ /**
+ * Verify that it installs the ephemeral configuration when the config is created for the
+ * carrier.
+ */
+ @Test
+ public void installEphemeralPasspointConfiguration() {
+ // Setup ScanDetail
+ List<ScanDetail> scanDetails = Arrays.asList(new ScanDetail[]{
+ generateScanDetail(TEST_SSID1, TEST_BSSID1)});
+ when(mCarrierNetworkConfig.isCarrierEncryptionInfoAvailable()).thenReturn(true);
+ when(mPasspointManager.hasCarrierProvider(anyString())).thenReturn(false);
+ when(mPasspointManager.findEapMethodFromNAIRealmMatchedWithCarrier(
+ any(List.class))).thenReturn(
+ EAPConstants.EAP_AKA);
+ when(mPasspointManager.createEphemeralPasspointConfigForCarrier(
+ EAPConstants.EAP_AKA)).thenReturn(mPasspointConfiguration);
+
+ assertEquals(null, mEvaluator.evaluateNetworks(
+ scanDetails, null, null, false, false, mOnConnectableListener));
+ verify(mPasspointManager).installEphemeralPasspointConfigForCarrier(
+ eq(mPasspointConfiguration));
+ }
+
+ /**
* Verify that when the current active network is matched, the scan info associated with
* the network is updated.
*