summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSteven Liu <steveliu@google.com>2019-11-20 01:52:31 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2019-11-20 01:52:31 +0000
commit970933dfbb153bb05d30f3f67c25fb0b19d89a6e (patch)
tree704f5d86db981556f9597fce811af6c97ad72870 /tests
parentafe241c3d4c240f4cd43801315d4a02b2cf7658b (diff)
parent4d315c818814bc3ebd5e5c75062b41724c060a0e (diff)
Merge "Add support of passpoint with SIM credential for dual SIM"
Diffstat (limited to 'tests')
-rw-r--r--tests/wifitests/Android.bp1
-rw-r--r--tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java4
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java4
-rw-r--r--tests/wifitests/src/com/android/server/wifi/hotspot2/ANQPMatcherTest.java29
-rw-r--r--tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointConfigUserStoreDataTest.java12
-rw-r--r--tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java129
-rw-r--r--tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointNetworkEvaluatorTest.java28
-rw-r--r--tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointProviderTest.java87
-rw-r--r--tests/wifitests/src/com/android/server/wifi/util/TelephonyUtilTest.java309
9 files changed, 514 insertions, 89 deletions
diff --git a/tests/wifitests/Android.bp b/tests/wifitests/Android.bp
index 341ab0982..5dd90c1fc 100644
--- a/tests/wifitests/Android.bp
+++ b/tests/wifitests/Android.bp
@@ -246,7 +246,6 @@ android_test {
"com.android.server.wifi.ScoringParams.*",
"com.android.server.wifi.SelfRecovery",
"com.android.server.wifi.SelfRecovery.*",
- "com.android.server.wifi.SIMAccessor",
"com.android.server.wifi.SoftApManager",
"com.android.server.wifi.SoftApManager.*",
"com.android.server.wifi.SoftApModeConfiguration",
diff --git a/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java b/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java
index 2b3491b31..6f59ac264 100644
--- a/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java
@@ -501,6 +501,8 @@ public class ClientModeImplTest extends WifiBaseTest {
add(mock(SubscriptionInfo.class));
}};
when(mSubscriptionManager.getActiveSubscriptionInfoList()).thenReturn(subList);
+ when(mSubscriptionManager.getActiveSubscriptionIdList())
+ .thenReturn(new int[]{DATA_SUBID});
TelephonyUtil tu = new TelephonyUtil(mTelephonyManager, mSubscriptionManager);
mTelephonyUtil = spy(tu);
@@ -1029,7 +1031,7 @@ public class ClientModeImplTest extends WifiBaseTest {
/**
* When the SIM card was removed, if the current wifi connection is using it, the connection
- * should be disconnected.
+ * should be disconnected, otherwise, the connection shouldn't be impacted.
*/
@Test
public void testResetSimWhenConnectedSimRemoved() throws Exception {
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java
index edbd5cb7e..4ad2a251e 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java
@@ -4568,6 +4568,8 @@ public class WifiConfigManagerTest extends WifiBaseTest {
add(mock(SubscriptionInfo.class));
}};
when(mSubscriptionManager.getActiveSubscriptionInfoList()).thenReturn(subList);
+ when(mSubscriptionManager.getActiveSubscriptionIdList())
+ .thenReturn(new int[]{DATA_SUBID});
WifiConfiguration network = WifiConfigurationTestUtil.createEapNetwork();
WifiConfiguration simNetwork = WifiConfigurationTestUtil.createEapNetwork(
@@ -4624,6 +4626,8 @@ public class WifiConfigManagerTest extends WifiBaseTest {
add(mock(SubscriptionInfo.class));
}};
when(mSubscriptionManager.getActiveSubscriptionInfoList()).thenReturn(subList);
+ when(mSubscriptionManager.getActiveSubscriptionIdList())
+ .thenReturn(new int[]{DATA_SUBID});
WifiConfiguration peapSimNetwork = WifiConfigurationTestUtil.createEapNetwork(
WifiEnterpriseConfig.Eap.PEAP, WifiEnterpriseConfig.Phase2.SIM);
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 6173ebd09..7a30ae069 100644
--- a/tests/wifitests/src/com/android/server/wifi/hotspot2/ANQPMatcherTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/hotspot2/ANQPMatcherTest.java
@@ -43,7 +43,6 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
-import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -85,11 +84,11 @@ public class ANQPMatcherTest extends WifiBaseTest {
@Test
public void matchDomainNameUsingIMSI() throws Exception {
IMSIParameter imsiParam = new IMSIParameter("1234", true);
- List<String> simImsiList = Arrays.asList(new String[] {"123457890", "123498723"});
+ String simImsi = "123457890";
// 3GPP network domain with MCC=123 and MNC=456.
String[] domains = new String[] {"wlan.mnc457.mcc123.3gppnetwork.org"};
DomainNameElement element = new DomainNameElement(Arrays.asList(domains));
- assertTrue(ANQPMatcher.matchDomainName(element, null, imsiParam, simImsiList));
+ assertTrue(ANQPMatcher.matchDomainName(element, null, imsiParam, simImsi));
}
/**
@@ -304,46 +303,46 @@ public class ANQPMatcherTest extends WifiBaseTest {
@Test
public void matchThreeGPPNetworkWithNullElement() throws Exception {
IMSIParameter imsiParam = new IMSIParameter("1234", true);
- List<String> simImsiList = Arrays.asList(new String[] {"123456789", "123498723"});
- assertFalse(ANQPMatcher.matchThreeGPPNetwork(null, imsiParam, simImsiList));
+ String simImsi = "123456789";
+ assertFalse(ANQPMatcher.matchThreeGPPNetwork(null, imsiParam, simImsi));
}
/**
* Verify that 3GPP network will succeed when the given 3GPP Network ANQP element contained
- * a MCC-MNC that matches the both IMSI parameter and an IMSI from the IMSI list.
+ * a MCC-MNC that matches the both IMSI parameter and a SIM IMSI.
*
* @throws Exception
*/
@Test
public void matchThreeGPPNetwork() throws Exception {
IMSIParameter imsiParam = new IMSIParameter("1234", true);
- List<String> simImsiList = Arrays.asList(new String[] {"123456789", "123498723"});
+ String simImsi = "123456789";
CellularNetwork network = new CellularNetwork(Arrays.asList(new String[] {"123456"}));
ThreeGPPNetworkElement element =
new ThreeGPPNetworkElement(Arrays.asList(new CellularNetwork[] {network}));
// The MCC-MNC provided in 3GPP Network ANQP element matches both IMSI parameter
// and an IMSI from the installed SIM card.
- assertTrue(ANQPMatcher.matchThreeGPPNetwork(element, imsiParam, simImsiList));
+ assertTrue(ANQPMatcher.matchThreeGPPNetwork(element, imsiParam, simImsi));
}
/**
* Verify that 3GPP network will failed when the given 3GPP Network ANQP element contained
- * a MCC-MNC that match the IMSI parameter but not the IMSI list.
+ * a MCC-MNC that match the IMSI parameter but not the SIM IMSI.
*
* @throws Exception
*/
@Test
public void matchThreeGPPNetworkWithoutSimImsiMatch() throws Exception {
IMSIParameter imsiParam = new IMSIParameter("1234", true);
- List<String> simImsiList = Arrays.asList(new String[] {"123457890", "123498723"});
+ String simImsi = "123457890";
CellularNetwork network = new CellularNetwork(Arrays.asList(new String[] {"123456"}));
ThreeGPPNetworkElement element =
new ThreeGPPNetworkElement(Arrays.asList(new CellularNetwork[] {network}));
// The MCC-MNC provided in 3GPP Network ANQP element doesn't match any of the IMSIs
// from the installed SIM card.
- assertFalse(ANQPMatcher.matchThreeGPPNetwork(element, imsiParam, simImsiList));
+ assertFalse(ANQPMatcher.matchThreeGPPNetwork(element, imsiParam, simImsi));
}
/**
@@ -355,13 +354,13 @@ public class ANQPMatcherTest extends WifiBaseTest {
@Test
public void matchThreeGPPNetworkWithImsiParamMismatch() throws Exception {
IMSIParameter imsiParam = new IMSIParameter("1234", true);
- List<String> simImsiList = Arrays.asList(new String[] {"123457890", "123498723"});
+ String simImsi = "123457890";
CellularNetwork network = new CellularNetwork(Arrays.asList(new String[] {"123356"}));
ThreeGPPNetworkElement element =
new ThreeGPPNetworkElement(Arrays.asList(new CellularNetwork[] {network}));
// The MCC-MNC provided in 3GPP Network ANQP element doesn't match the IMSI parameter.
- assertFalse(ANQPMatcher.matchThreeGPPNetwork(element, imsiParam, simImsiList));
+ assertFalse(ANQPMatcher.matchThreeGPPNetwork(element, imsiParam, simImsi));
}
/**
@@ -372,10 +371,10 @@ public class ANQPMatcherTest extends WifiBaseTest {
@Test
public void verifyInvalidDomain() throws Exception {
IMSIParameter imsiParam = new IMSIParameter("1234", true);
- List<String> simImsiList = Arrays.asList(new String[] {"123457890", "123498723"});
+ String simImsi = "123457890";
// 3GPP network domain with MCC=123 and MNC=456.
String[] domains = new String[] {"wlan.mnc457.mccI23.3gppnetwork.org"};
DomainNameElement element = new DomainNameElement(Arrays.asList(domains));
- assertFalse(ANQPMatcher.matchDomainName(element, null, imsiParam, simImsiList));
+ assertFalse(ANQPMatcher.matchDomainName(element, null, imsiParam, simImsi));
}
}
diff --git a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointConfigUserStoreDataTest.java b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointConfigUserStoreDataTest.java
index 5a30d7164..18f6bf5ce 100644
--- a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointConfigUserStoreDataTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointConfigUserStoreDataTest.java
@@ -29,10 +29,10 @@ import android.util.Xml;
import androidx.test.filters.SmallTest;
import com.android.internal.util.FastXmlSerializer;
-import com.android.server.wifi.SIMAccessor;
import com.android.server.wifi.WifiBaseTest;
import com.android.server.wifi.WifiConfigStore;
import com.android.server.wifi.WifiKeyStore;
+import com.android.server.wifi.util.TelephonyUtil;
import com.android.server.wifi.util.WifiConfigStoreEncryptionUtil;
import org.junit.Before;
@@ -71,7 +71,7 @@ public class PasspointConfigUserStoreDataTest extends WifiBaseTest {
private static final boolean TEST_SHARED = false;
@Mock WifiKeyStore mKeyStore;
- @Mock SIMAccessor mSimAccessor;
+ @Mock TelephonyUtil mTelephonyUtil;
@Mock PasspointConfigUserStoreData.DataSource mDataSource;
PasspointConfigUserStoreData mConfigStoreData;
@@ -79,7 +79,7 @@ public class PasspointConfigUserStoreDataTest extends WifiBaseTest {
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
- mConfigStoreData = new PasspointConfigUserStoreData(mKeyStore, mSimAccessor, mDataSource);
+ mConfigStoreData = new PasspointConfigUserStoreData(mKeyStore, mTelephonyUtil, mDataSource);
}
/**
@@ -245,12 +245,12 @@ public class PasspointConfigUserStoreDataTest extends WifiBaseTest {
// Setup expected data.
List<PasspointProvider> providerList = new ArrayList<>();
providerList.add(new PasspointProvider(createFullPasspointConfiguration(),
- mKeyStore, mSimAccessor, TEST_PROVIDER_ID, TEST_CREATOR_UID, TEST_CREATOR_PACKAGE,
+ mKeyStore, mTelephonyUtil, TEST_PROVIDER_ID, TEST_CREATOR_UID, TEST_CREATOR_PACKAGE,
false, Arrays.asList(TEST_CA_CERTIFICATE_ALIAS),
TEST_CLIENT_PRIVATE_KEY_AND_CERT_ALIAS, null,
TEST_HAS_EVER_CONNECTED, TEST_SHARED));
- providerList.add(new PasspointProvider(createFullPasspointConfiguration(),
- mKeyStore, mSimAccessor, TEST_PROVIDER_ID_2, TEST_CREATOR_UID, TEST_CREATOR_PACKAGE,
+ providerList.add(new PasspointProvider(createFullPasspointConfiguration(), mKeyStore,
+ mTelephonyUtil, TEST_PROVIDER_ID_2, TEST_CREATOR_UID, TEST_CREATOR_PACKAGE,
true, Arrays.asList(TEST_CA_CERTIFICATE_ALIAS, TEST_CA_CERTIFICATE_ALIAS_2),
TEST_CLIENT_PRIVATE_KEY_AND_CERT_ALIAS, TEST_REMEDIATION_CA_CERTIFICATE_ALIAS,
TEST_HAS_EVER_CONNECTED, TEST_SHARED));
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 447d8b13b..ccfb1f0d1 100644
--- a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java
@@ -42,12 +42,15 @@ import static org.mockito.Mockito.anyBoolean;
import static org.mockito.Mockito.anyInt;
import static org.mockito.Mockito.anyLong;
import static org.mockito.Mockito.anyMap;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.lenient;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.reset;
+import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -73,7 +76,9 @@ import android.os.Handler;
import android.os.Looper;
import android.os.UserHandle;
import android.os.test.TestLooper;
+import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
+import android.telephony.TelephonyManager;
import android.util.Base64;
import android.util.Pair;
@@ -82,8 +87,6 @@ import androidx.test.filters.SmallTest;
import com.android.server.wifi.ClientModeImpl;
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.WifiBaseTest;
import com.android.server.wifi.WifiConfigManager;
import com.android.server.wifi.WifiConfigStore;
@@ -101,6 +104,7 @@ import com.android.server.wifi.hotspot2.anqp.I18Name;
import com.android.server.wifi.hotspot2.anqp.OsuProviderInfo;
import com.android.server.wifi.util.InformationElementUtil;
import com.android.server.wifi.util.InformationElementUtil.RoamingConsortium;
+import com.android.server.wifi.util.TelephonyUtil;
import org.junit.Before;
import org.junit.Test;
@@ -111,6 +115,7 @@ import org.mockito.MockitoSession;
import java.nio.charset.StandardCharsets;
import java.security.GeneralSecurityException;
import java.security.KeyStore;
+import java.security.cert.Certificate;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.Arrays;
@@ -137,7 +142,9 @@ public class PasspointManagerTest extends WifiBaseTest {
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 = "123456*";
- private static final IMSIParameter TEST_IMSI_PARAM = IMSIParameter.build(TEST_IMSI);
+ private static final String FULL_IMSI = "123456789123456";
+ private static final int TEST_CARRIER_ID = 10;
+ private static final int TEST_SUBID = 1;
private static final long TEST_BSSID = 0x112233445566L;
private static final String TEST_SSID = "TestSSID";
@@ -165,7 +172,6 @@ public class PasspointManagerTest extends WifiBaseTest {
@Mock WifiNative mWifiNative;
@Mock WifiKeyStore mWifiKeyStore;
@Mock Clock mClock;
- @Mock SIMAccessor mSimAccessor;
@Mock PasspointObjectFactory mObjectFactory;
@Mock PasspointEventHandler.Callbacks mCallbacks;
@Mock AnqpCache mAnqpCache;
@@ -185,6 +191,7 @@ public class PasspointManagerTest extends WifiBaseTest {
@Mock AppOpsManager mAppOpsManager;
@Mock WifiInjector mWifiInjector;
@Mock ClientModeImpl mClientModeImpl;
+ @Mock TelephonyManager mTelephonyManager;
@Mock SubscriptionManager mSubscriptionManager;
@Mock WifiNetworkSuggestionsManager mWifiNetworkSuggestionsManager;
@@ -193,6 +200,7 @@ public class PasspointManagerTest extends WifiBaseTest {
PasspointManager mManager;
ArgumentCaptor<AppOpsManager.OnOpChangedListener> mAppOpChangedListenerCaptor =
ArgumentCaptor.forClass(AppOpsManager.OnOpChangedListener.class);
+ TelephonyUtil mTelephonyUtil;
/** Sets up test. */
@Before
@@ -215,11 +223,12 @@ public class PasspointManagerTest extends WifiBaseTest {
when(mWifiInjector.getClientModeImpl()).thenReturn(mClientModeImpl);
when(mWifiInjector.getWifiNetworkSuggestionsManager())
.thenReturn(mWifiNetworkSuggestionsManager);
+ mTelephonyUtil = new TelephonyUtil(mTelephonyManager, mSubscriptionManager);
mLooper = new TestLooper();
mHandler = new Handler(mLooper.getLooper());
mManager = new PasspointManager(mContext, mWifiInjector, mHandler, mWifiNative,
- mWifiKeyStore, mClock, mSimAccessor, mObjectFactory, mWifiConfigManager,
- mWifiConfigStore, mWifiMetrics, mSubscriptionManager);
+ mWifiKeyStore, mClock, mObjectFactory, mWifiConfigManager,
+ mWifiConfigStore, mWifiMetrics, mTelephonyUtil);
ArgumentCaptor<PasspointEventHandler.Callbacks> callbacks =
ArgumentCaptor.forClass(PasspointEventHandler.Callbacks.class);
verify(mObjectFactory).makePasspointEventHandler(any(WifiNative.class),
@@ -230,7 +239,7 @@ public class PasspointManagerTest extends WifiBaseTest {
ArgumentCaptor<PasspointConfigUserStoreData.DataSource> userDataSource =
ArgumentCaptor.forClass(PasspointConfigUserStoreData.DataSource.class);
verify(mObjectFactory).makePasspointConfigUserStoreData(
- any(WifiKeyStore.class), any(SIMAccessor.class), userDataSource.capture());
+ any(WifiKeyStore.class), any(TelephonyUtil.class), userDataSource.capture());
mCallbacks = callbacks.getValue();
mSharedDataSource = sharedDataSource.getValue();
mUserDataSource = userDataSource.getValue();
@@ -368,7 +377,7 @@ public class PasspointManagerTest extends WifiBaseTest {
PasspointConfiguration config = createTestConfigWithUserCredential(fqdn, friendlyName);
PasspointProvider provider = createMockProvider(config, wifiConfig);
when(mObjectFactory.makePasspointProvider(eq(config), eq(mWifiKeyStore),
- eq(mSimAccessor), anyLong(), eq(TEST_CREATOR_UID), eq(TEST_PACKAGE),
+ eq(mTelephonyUtil), anyLong(), eq(TEST_CREATOR_UID), eq(TEST_PACKAGE),
eq(false))).thenReturn(provider);
when(provider.getPackageName()).thenReturn(packageName);
assertTrue(mManager.addOrUpdateProvider(config, TEST_CREATOR_UID, TEST_PACKAGE, false));
@@ -609,7 +618,7 @@ public class PasspointManagerTest extends WifiBaseTest {
PasspointProvider provider = createMockProvider(config);
when(provider.getPackageName()).thenReturn(TEST_PACKAGE);
when(mObjectFactory.makePasspointProvider(eq(config), eq(mWifiKeyStore),
- eq(mSimAccessor), anyLong(), eq(TEST_CREATOR_UID), eq(TEST_PACKAGE),
+ eq(mTelephonyUtil), anyLong(), eq(TEST_CREATOR_UID), eq(TEST_PACKAGE),
eq(false))).thenReturn(provider);
assertTrue(mManager.addOrUpdateProvider(config, TEST_CREATOR_UID, TEST_PACKAGE, false));
verifyInstalledConfig(config);
@@ -656,7 +665,7 @@ public class PasspointManagerTest extends WifiBaseTest {
TEST_REALM);
PasspointProvider provider = createMockProvider(config);
when(mObjectFactory.makePasspointProvider(eq(config), eq(mWifiKeyStore),
- eq(mSimAccessor), anyLong(), eq(TEST_CREATOR_UID), eq(TEST_PACKAGE),
+ eq(mTelephonyUtil), anyLong(), eq(TEST_CREATOR_UID), eq(TEST_PACKAGE),
eq(false))).thenReturn(provider);
assertTrue(mManager.addOrUpdateProvider(config, TEST_CREATOR_UID, TEST_PACKAGE, false));
verifyInstalledConfig(config);
@@ -690,6 +699,47 @@ public class PasspointManagerTest extends WifiBaseTest {
}
/**
+ * Verify that if the passpoint profile has full IMSI, the carrier ID should be updated when
+ * the matched SIM card is present.
+ * @throws Exception
+ */
+ @Test
+ public void addProviderWithValidFullImsiOfSimCredential() throws Exception {
+ PasspointConfiguration config =
+ createTestConfigWithSimCredential(TEST_FQDN, FULL_IMSI, TEST_REALM);
+ X509Certificate[] certArr = new X509Certificate[] {FakeKeys.CA_CERT0};
+ config.getCredential().setCaCertificates(certArr);
+ SubscriptionInfo subInfo = mock(SubscriptionInfo.class);
+ when(subInfo.getSubscriptionId()).thenReturn(TEST_SUBID);
+ when(subInfo.getCarrierId()).thenReturn(TEST_CARRIER_ID);
+ TelephonyManager specifiedTm = mock(TelephonyManager.class);
+ when(mTelephonyManager.createForSubscriptionId(eq(TEST_SUBID))).thenReturn(specifiedTm);
+ when(specifiedTm.getSubscriberId()).thenReturn(FULL_IMSI);
+ List<SubscriptionInfo> subInfoList = new ArrayList<>() {{
+ add(subInfo);
+ }};
+ when(mSubscriptionManager.getActiveSubscriptionInfoList()).thenReturn(subInfoList);
+ doNothing().when(mCertVerifier).verifyCaCert(any(X509Certificate.class));
+ when(mWifiKeyStore.putCaCertInKeyStore(any(String.class), any(Certificate.class)))
+ .thenReturn(true);
+ PasspointObjectFactory spyFactory = spy(new PasspointObjectFactory());
+ doReturn(mCertVerifier).when(spyFactory).makeCertificateVerifier();
+ PasspointManager ut = new PasspointManager(mContext, mWifiInjector, mHandler, mWifiNative,
+ mWifiKeyStore, mClock, spyFactory, mWifiConfigManager,
+ mWifiConfigStore, mWifiMetrics, mTelephonyUtil);
+
+ assertTrue(ut.addOrUpdateProvider(config, TEST_CREATOR_UID, TEST_PACKAGE, true));
+
+ assertEquals(TEST_CARRIER_ID, config.getCarrierId());
+ List<String> fqdnList = new ArrayList<>(){{
+ add(TEST_FQDN);
+ }};
+ assertEquals(TEST_CARRIER_ID,
+ ut.getWifiConfigsForPasspointProfiles(fqdnList).get(0).carrierId);
+
+ }
+
+ /**
* Verify that adding a user saved provider with the same base domain as the existing provider
* will succeed, and verify that the existing provider is replaced by the new provider with
* the new configuration.
@@ -703,7 +753,7 @@ public class PasspointManagerTest extends WifiBaseTest {
TEST_REALM);
PasspointProvider origProvider = createMockProvider(origConfig);
when(mObjectFactory.makePasspointProvider(eq(origConfig), eq(mWifiKeyStore),
- eq(mSimAccessor), anyLong(), eq(TEST_CREATOR_UID), eq(TEST_PACKAGE),
+ eq(mTelephonyUtil), anyLong(), eq(TEST_CREATOR_UID), eq(TEST_PACKAGE),
eq(false))).thenReturn(origProvider);
assertTrue(mManager.addOrUpdateProvider(origConfig, TEST_CREATOR_UID, TEST_PACKAGE, false));
verifyInstalledConfig(origConfig);
@@ -725,7 +775,7 @@ public class PasspointManagerTest extends WifiBaseTest {
TEST_FRIENDLY_NAME);
PasspointProvider newProvider = createMockProvider(newConfig);
when(mObjectFactory.makePasspointProvider(eq(newConfig), eq(mWifiKeyStore),
- eq(mSimAccessor), anyLong(), eq(TEST_CREATOR_UID), eq(TEST_PACKAGE),
+ eq(mTelephonyUtil), anyLong(), eq(TEST_CREATOR_UID), eq(TEST_PACKAGE),
eq(false))).thenReturn(newProvider);
assertTrue(mManager.addOrUpdateProvider(newConfig, TEST_CREATOR_UID, TEST_PACKAGE, false));
verifyInstalledConfig(newConfig);
@@ -755,7 +805,7 @@ public class PasspointManagerTest extends WifiBaseTest {
PasspointProvider provider = mock(PasspointProvider.class);
when(provider.installCertsAndKeys()).thenReturn(false);
when(mObjectFactory.makePasspointProvider(eq(config), eq(mWifiKeyStore),
- eq(mSimAccessor), anyLong(), eq(TEST_CREATOR_UID), eq(TEST_PACKAGE), eq(false)))
+ eq(mTelephonyUtil), anyLong(), eq(TEST_CREATOR_UID), eq(TEST_PACKAGE), eq(false)))
.thenReturn(provider);
assertFalse(mManager.addOrUpdateProvider(config, TEST_CREATOR_UID, TEST_PACKAGE, false));
verify(mWifiMetrics).incrementNumPasspointProviderInstallation();
@@ -791,7 +841,7 @@ public class PasspointManagerTest extends WifiBaseTest {
config.setUpdateIdentifier(1);
PasspointProvider provider = createMockProvider(config);
when(mObjectFactory.makePasspointProvider(eq(config), eq(mWifiKeyStore),
- eq(mSimAccessor), anyLong(), eq(TEST_CREATOR_UID), eq(TEST_PACKAGE),
+ eq(mTelephonyUtil), anyLong(), eq(TEST_CREATOR_UID), eq(TEST_PACKAGE),
eq(false))).thenReturn(provider);
assertTrue(mManager.addOrUpdateProvider(config, TEST_CREATOR_UID, TEST_PACKAGE, false));
verify(mCertVerifier, never()).verifyCaCert(any(X509Certificate.class));
@@ -932,6 +982,39 @@ public class PasspointManagerTest extends WifiBaseTest {
}
/**
+ * Verify that if the Carrier ID is updated during match, the config should be persisted.
+ */
+ @Test
+ public void getAllMatchingProvidersUpdatedConfigWithFullImsiSimCredential() {
+ // static mocking
+ MockitoSession session =
+ com.android.dx.mockito.inline.extended.ExtendedMockito.mockitoSession().mockStatic(
+ InformationElementUtil.class).startMocking();
+ try {
+ PasspointProvider provider = addTestProvider(TEST_FQDN + 0, TEST_FRIENDLY_NAME,
+ TEST_PACKAGE);
+ when(provider.tryUpdateCarrierId()).thenReturn(true);
+ reset(mWifiConfigManager);
+
+ ANQPData entry = new ANQPData(mClock, null);
+ InformationElementUtil.Vsa vsa = new InformationElementUtil.Vsa();
+ vsa.anqpDomainID = TEST_ANQP_DOMAIN_ID2;
+
+ when(mAnqpCache.getEntry(TEST_ANQP_KEY2)).thenReturn(entry);
+ when(InformationElementUtil.getHS2VendorSpecificIE(isNull())).thenReturn(vsa);
+ when(provider.match(anyMap(), isNull()))
+ .thenReturn(PasspointMatch.HomeProvider);
+
+ List<Pair<PasspointProvider, PasspointMatch>> matchedProviders =
+ mManager.getAllMatchedProviders(createTestScanResult());
+
+ verify(mWifiConfigManager).saveToStore(eq(true));
+
+ } finally {
+ session.finishMocking();
+ }
+ }
+ /**
* Verify that an expected map of FQDN and a list of ScanResult will be returned when provided
* scanResults are matched to installed Passpoint profiles.
*/
@@ -1273,7 +1356,7 @@ public class PasspointManagerTest extends WifiBaseTest {
PasspointProvider provider = createMockProvider(config);
// Verify the provider ID used to create the new provider.
when(mObjectFactory.makePasspointProvider(eq(config), eq(mWifiKeyStore),
- eq(mSimAccessor), eq(providerIndex), eq(TEST_CREATOR_UID),
+ eq(mTelephonyUtil), eq(providerIndex), eq(TEST_CREATOR_UID),
eq(TEST_PACKAGE), eq(false))).thenReturn(provider);
assertTrue(mManager.addOrUpdateProvider(config, TEST_CREATOR_UID, TEST_PACKAGE, false));
@@ -1625,7 +1708,7 @@ public class PasspointManagerTest extends WifiBaseTest {
TEST_REALM);
PasspointProvider provider = createMockProvider(config);
when(mObjectFactory.makePasspointProvider(eq(config), eq(mWifiKeyStore),
- eq(mSimAccessor), anyLong(), eq(TEST_CREATOR_UID), eq(TEST_PACKAGE),
+ eq(mTelephonyUtil), anyLong(), eq(TEST_CREATOR_UID), eq(TEST_PACKAGE),
eq(false))).thenReturn(provider);
assertTrue(mManager.addOrUpdateProvider(config, TEST_CREATOR_UID, TEST_PACKAGE, false));
verifyInstalledConfig(config);
@@ -1667,7 +1750,7 @@ public class PasspointManagerTest extends WifiBaseTest {
when(provider.getPackageName()).thenReturn(TEST_PACKAGE);
when(provider.isFromSuggestion()).thenReturn(true);
when(mObjectFactory.makePasspointProvider(eq(config), eq(mWifiKeyStore),
- eq(mSimAccessor), anyLong(), eq(TEST_CREATOR_UID), eq(TEST_PACKAGE),
+ eq(mTelephonyUtil), anyLong(), eq(TEST_CREATOR_UID), eq(TEST_PACKAGE),
eq(true))).thenReturn(provider);
assertTrue(mManager.addOrUpdateProvider(config, TEST_CREATOR_UID, TEST_PACKAGE, true));
verify(mWifiMetrics).incrementNumPasspointProviderInstallation();
@@ -1736,7 +1819,7 @@ public class PasspointManagerTest extends WifiBaseTest {
PasspointProvider origProvider = createMockProvider(origConfig);
when(origProvider.getPackageName()).thenReturn(TEST_PACKAGE);
when(mObjectFactory.makePasspointProvider(eq(origConfig), eq(mWifiKeyStore),
- eq(mSimAccessor), anyLong(), eq(TEST_CREATOR_UID), eq(TEST_PACKAGE),
+ eq(mTelephonyUtil), anyLong(), eq(TEST_CREATOR_UID), eq(TEST_PACKAGE),
eq(true))).thenReturn(origProvider);
assertTrue(mManager.addOrUpdateProvider(origConfig, TEST_CREATOR_UID, TEST_PACKAGE, true));
verify(mWifiMetrics).incrementNumPasspointProviderInstallation();
@@ -1770,7 +1853,7 @@ public class PasspointManagerTest extends WifiBaseTest {
when(newProvider.isFromSuggestion()).thenReturn(true);
when(newProvider.getPackageName()).thenReturn(TEST_PACKAGE);
when(mObjectFactory.makePasspointProvider(eq(newConfig), eq(mWifiKeyStore),
- eq(mSimAccessor), anyLong(), eq(TEST_CREATOR_UID), eq(TEST_PACKAGE),
+ eq(mTelephonyUtil), anyLong(), eq(TEST_CREATOR_UID), eq(TEST_PACKAGE),
eq(true))).thenReturn(newProvider);
assertTrue(mManager.addOrUpdateProvider(newConfig, TEST_CREATOR_UID, TEST_PACKAGE, true));
verify(mWifiConfigManager).removePasspointConfiguredNetwork(
@@ -1801,7 +1884,7 @@ public class PasspointManagerTest extends WifiBaseTest {
PasspointProvider origProvider = createMockProvider(origConfig);
when(origProvider.getPackageName()).thenReturn(TEST_PACKAGE);
when(mObjectFactory.makePasspointProvider(eq(origConfig), eq(mWifiKeyStore),
- eq(mSimAccessor), anyLong(), eq(TEST_CREATOR_UID), eq(TEST_PACKAGE),
+ eq(mTelephonyUtil), anyLong(), eq(TEST_CREATOR_UID), eq(TEST_PACKAGE),
eq(true))).thenReturn(origProvider);
assertTrue(mManager.addOrUpdateProvider(origConfig, TEST_CREATOR_UID, TEST_PACKAGE, true));
verify(mWifiMetrics).incrementNumPasspointProviderInstallation();
@@ -1821,7 +1904,7 @@ public class PasspointManagerTest extends WifiBaseTest {
TEST_FRIENDLY_NAME);
PasspointProvider newProvider = createMockProvider(newConfig);
when(mObjectFactory.makePasspointProvider(eq(newConfig), eq(mWifiKeyStore),
- eq(mSimAccessor), anyLong(), eq(TEST_CREATOR_UID), eq(TEST_PACKAGE),
+ eq(mTelephonyUtil), anyLong(), eq(TEST_CREATOR_UID), eq(TEST_PACKAGE),
eq(false))).thenReturn(newProvider);
assertTrue(mManager.addOrUpdateProvider(newConfig, TEST_CREATOR_UID, TEST_PACKAGE, false));
verify(mWifiConfigManager).removePasspointConfiguredNetwork(
@@ -1852,7 +1935,7 @@ public class PasspointManagerTest extends WifiBaseTest {
PasspointProvider origProvider = createMockProvider(origConfig);
when(origProvider.getPackageName()).thenReturn(TEST_PACKAGE);
when(mObjectFactory.makePasspointProvider(eq(origConfig), eq(mWifiKeyStore),
- eq(mSimAccessor), anyLong(), eq(TEST_CREATOR_UID), eq(TEST_PACKAGE),
+ eq(mTelephonyUtil), anyLong(), eq(TEST_CREATOR_UID), eq(TEST_PACKAGE),
eq(false))).thenReturn(origProvider);
assertTrue(mManager.addOrUpdateProvider(origConfig, TEST_CREATOR_UID, TEST_PACKAGE, false));
verifyInstalledConfig(origConfig);
@@ -1875,7 +1958,7 @@ public class PasspointManagerTest extends WifiBaseTest {
when(newProvider.isFromSuggestion()).thenReturn(true);
when(newProvider.getPackageName()).thenReturn(TEST_PACKAGE1);
when(mObjectFactory.makePasspointProvider(eq(newConfig), eq(mWifiKeyStore),
- eq(mSimAccessor), anyLong(), eq(TEST_CREATOR_UID), eq(TEST_PACKAGE1),
+ eq(mTelephonyUtil), anyLong(), eq(TEST_CREATOR_UID), eq(TEST_PACKAGE1),
eq(true))).thenReturn(newProvider);
assertFalse(mManager.addOrUpdateProvider(newConfig, TEST_CREATOR_UID, TEST_PACKAGE1, true));
verify(mWifiConfigManager, never()).removePasspointConfiguredNetwork(
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 d5cdd5a96..96a8aac3d 100644
--- a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointNetworkEvaluatorTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointNetworkEvaluatorTest.java
@@ -368,34 +368,6 @@ public class PasspointNetworkEvaluatorTest {
}
/**
- * Verify that null will be returned when matching a SIM credential provider without SIM
- * card installed.
- *
- * @throws Exception
- */
- @Test
- public void evaluateScanMatchingSIMProviderWithoutSIMCard() throws Exception {
- // Setup ScanDetail and match providers.
- List<ScanDetail> scanDetails = Arrays.asList(new ScanDetail[] {
- generateScanDetail(TEST_SSID1, TEST_BSSID1)});
- PasspointProvider testProvider = mock(PasspointProvider.class);
- Pair<PasspointProvider, PasspointMatch> homeProvider = Pair.create(
- testProvider, PasspointMatch.HomeProvider);
-
- when(mPasspointManager.matchProvider(any(ScanResult.class))).thenReturn(homeProvider);
- when(testProvider.isSimCredential()).thenReturn(true);
- // SIM is absent
- when(mSubscriptionManager.getActiveSubscriptionInfoList())
- .thenReturn(Collections.emptyList());
-
- assertEquals(null, mEvaluator.evaluateNetworks(
- scanDetails, null, null, false, false, mOnConnectableListener));
-
- verify(mOnConnectableListener, never()).onConnectable(any(), any(), anyInt());
- verify(testProvider, never()).getWifiConfig();
- }
-
- /**
* Verify that anonymous identity is empty when matching a SIM credential provider with a
* network that supports encrypted IMSI and anonymous identity. The anonymous identity will be
* populated with {@code anonymous@<realm>} by ClientModeImpl's handling of the
diff --git a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointProviderTest.java b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointProviderTest.java
index beddb2199..9391abb3f 100644
--- a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointProviderTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointProviderTest.java
@@ -19,6 +19,7 @@ package com.android.server.wifi.hotspot2;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;
@@ -32,13 +33,12 @@ import android.net.wifi.hotspot2.pps.HomeSp;
import android.net.wifi.hotspot2.pps.UpdateParameter;
import android.text.TextUtils;
import android.util.Base64;
+import android.util.Pair;
import androidx.test.filters.SmallTest;
import com.android.internal.util.ArrayUtils;
import com.android.server.wifi.FakeKeys;
-import com.android.server.wifi.IMSIParameter;
-import com.android.server.wifi.SIMAccessor;
import com.android.server.wifi.WifiBaseTest;
import com.android.server.wifi.WifiKeyStore;
import com.android.server.wifi.hotspot2.anqp.ANQPElement;
@@ -53,6 +53,7 @@ import com.android.server.wifi.hotspot2.anqp.eap.AuthParam;
import com.android.server.wifi.hotspot2.anqp.eap.EAPMethod;
import com.android.server.wifi.hotspot2.anqp.eap.NonEAPInnerAuth;
import com.android.server.wifi.util.InformationElementUtil.RoamingConsortium;
+import com.android.server.wifi.util.TelephonyUtil;
import org.junit.Before;
import org.junit.Test;
@@ -107,6 +108,7 @@ public class PasspointProviderTest extends WifiBaseTest {
private static final int TEST_EAP_TYPE = WifiEnterpriseConfig.Eap.SIM;
private static final int TEST_SIM_CREDENTIAL_TYPE = EAPConstants.EAP_SIM;
private static final String TEST_IMSI = "1234567890";
+ private static final int VALID_CARRIER_ID = 1;
private enum CredentialType {
USER,
@@ -115,7 +117,7 @@ public class PasspointProviderTest extends WifiBaseTest {
}
@Mock WifiKeyStore mKeyStore;
- @Mock SIMAccessor mSimAccessor;
+ @Mock TelephonyUtil mTelephonyUtil;
@Mock RoamingConsortium mRoamingConsortium;
PasspointProvider mProvider;
X509Certificate mRemediationCaCertificate;
@@ -149,7 +151,7 @@ public class PasspointProviderTest extends WifiBaseTest {
* @return {@link com.android.server.wifi.hotspot2.PasspointProvider}
*/
private PasspointProvider createProvider(PasspointConfiguration config) {
- return new PasspointProvider(config, mKeyStore, mSimAccessor, PROVIDER_ID, CREATOR_UID,
+ return new PasspointProvider(config, mKeyStore, mTelephonyUtil, PROVIDER_ID, CREATOR_UID,
CREATOR_PACKAGE, false);
}
@@ -691,8 +693,8 @@ public class PasspointProviderTest extends WifiBaseTest {
// Setup test provider.
PasspointConfiguration config = generateTestPasspointConfiguration(
CredentialType.SIM, false);
- when(mSimAccessor.getMatchingImsis(new IMSIParameter(TEST_IMSI, false)))
- .thenReturn(Arrays.asList(new String[] {TEST_IMSI}));
+ when(mTelephonyUtil.getMatchingImsiCarrierId(TEST_IMSI))
+ .thenReturn(new Pair<String, Integer>(TEST_IMSI, VALID_CARRIER_ID));
mProvider = createProvider(config);
// Setup Domain Name ANQP element.
@@ -716,8 +718,8 @@ public class PasspointProviderTest extends WifiBaseTest {
// Setup test provider.
PasspointConfiguration config = generateTestPasspointConfiguration(
CredentialType.SIM, false);
- when(mSimAccessor.getMatchingImsis(new IMSIParameter(TEST_IMSI, false)))
- .thenReturn(Arrays.asList(new String[] {TEST_IMSI}));
+ when(mTelephonyUtil.getMatchingImsiCarrierId(TEST_IMSI))
+ .thenReturn(new Pair<String, Integer>(TEST_IMSI, VALID_CARRIER_ID));
mProvider = createProvider(config);
// Setup ANQP elements.
@@ -745,6 +747,9 @@ public class PasspointProviderTest extends WifiBaseTest {
PasspointConfiguration config = generateTestPasspointConfiguration(
CredentialType.SIM, false);
mProvider = createProvider(config);
+ when(mTelephonyUtil.getMatchingImsiCarrierId(
+ eq(config.getCredential().getSimCredential().getImsi())))
+ .thenReturn(new Pair<String, Integer>(TEST_IMSI, VALID_CARRIER_ID));
// Setup Roaming Consortium ANQP element.
Map<ANQPElementType, ANQPElement> anqpElementMap = new HashMap<>();
@@ -919,8 +924,8 @@ public class PasspointProviderTest extends WifiBaseTest {
// Setup test provider.
PasspointConfiguration config = generateTestPasspointConfiguration(
CredentialType.SIM, false);
- when(mSimAccessor.getMatchingImsis(new IMSIParameter(TEST_IMSI, false)))
- .thenReturn(Arrays.asList(new String[] {TEST_IMSI}));
+ when(mTelephonyUtil.getMatchingImsiCarrierId(TEST_IMSI))
+ .thenReturn(new Pair<String, Integer>(TEST_IMSI, VALID_CARRIER_ID));
mProvider = createProvider(config);
// Setup 3GPP Network ANQP element.
@@ -949,8 +954,8 @@ public class PasspointProviderTest extends WifiBaseTest {
// Setup test provider.
PasspointConfiguration config = generateTestPasspointConfiguration(
CredentialType.SIM, false);
- when(mSimAccessor.getMatchingImsis(new IMSIParameter(TEST_IMSI, false)))
- .thenReturn(Arrays.asList(new String[] {TEST_IMSI}));
+ when(mTelephonyUtil.getMatchingImsiCarrierId(TEST_IMSI))
+ .thenReturn(new Pair<String, Integer>(TEST_IMSI, VALID_CARRIER_ID));
mProvider = createProvider(config);
// Setup 3GPP Network ANQP element.
@@ -964,6 +969,64 @@ public class PasspointProviderTest extends WifiBaseTest {
assertEquals(PasspointMatch.RoamingProvider,
mProvider.match(anqpElementMap, mRoamingConsortium));
+ assertEquals(VALID_CARRIER_ID, mProvider.getWifiConfig().carrierId);
+ }
+
+ /**
+ * Verify that when the SIM card matched by carrier ID of profile is absent, it shouldn't
+ * be matched even the profile and ANQP elements are matched.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void matchNothingIfSimMatchedByCarrierIdIsAbsent() throws Exception {
+ // Setup test provider.
+ PasspointConfiguration config = generateTestPasspointConfiguration(
+ CredentialType.SIM, false);
+ config.setCarrierId(VALID_CARRIER_ID);
+ when(mTelephonyUtil.getMatchingImsi(eq(VALID_CARRIER_ID)))
+ .thenReturn(null);
+ mProvider = createProvider(config);
+
+ // Setup 3GPP Network ANQP element.
+ Map<ANQPElementType, ANQPElement> anqpElementMap = new HashMap<>();
+ anqpElementMap.put(ANQPElementType.ANQP3GPPNetwork,
+ createThreeGPPNetworkElement(new String[] {"123456"}));
+
+ // Setup NAI Realm ANQP element with same realm.
+ anqpElementMap.put(ANQPElementType.ANQPNAIRealm,
+ createNAIRealmElement(TEST_REALM, EAPConstants.EAP_AKA, null));
+
+ assertEquals(PasspointMatch.None,
+ mProvider.match(anqpElementMap, mRoamingConsortium));
+ }
+
+ /**
+ * Verify that when the SIM card matched by IMSI of profile is absent, it shouldn't be
+ * matched even the profile and ANQP elements are matched.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void matchNothingIfSimMatchedByImsiIsAbsent() throws Exception {
+ // Setup test provider.
+ PasspointConfiguration config = generateTestPasspointConfiguration(
+ CredentialType.SIM, false);
+ when(mTelephonyUtil.getMatchingImsiCarrierId(eq(TEST_IMSI)))
+ .thenReturn(null);
+ mProvider = createProvider(config);
+
+ // Setup 3GPP Network ANQP element.
+ Map<ANQPElementType, ANQPElement> anqpElementMap = new HashMap<>();
+ anqpElementMap.put(ANQPElementType.ANQP3GPPNetwork,
+ createThreeGPPNetworkElement(new String[] {"123456"}));
+
+ // Setup NAI Realm ANQP element with same realm.
+ anqpElementMap.put(ANQPElementType.ANQPNAIRealm,
+ createNAIRealmElement(TEST_REALM, EAPConstants.EAP_AKA, null));
+
+ assertEquals(PasspointMatch.None,
+ mProvider.match(anqpElementMap, mRoamingConsortium));
}
/**
diff --git a/tests/wifitests/src/com/android/server/wifi/util/TelephonyUtilTest.java b/tests/wifitests/src/com/android/server/wifi/util/TelephonyUtilTest.java
index b31bb057e..7e24c8572 100644
--- a/tests/wifitests/src/com/android/server/wifi/util/TelephonyUtilTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/util/TelephonyUtilTest.java
@@ -24,6 +24,8 @@ import static org.mockito.Mockito.*;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiEnterpriseConfig;
+import android.net.wifi.hotspot2.PasspointConfiguration;
+import android.net.wifi.hotspot2.pps.Credential;
import android.telephony.ImsiEncryptionInfo;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
@@ -67,8 +69,18 @@ public class TelephonyUtilTest extends WifiBaseTest {
private static final int NON_DATA_SUBID = 2;
private static final int INVALID_SUBID = -1;
private static final int DATA_CARRIER_ID = 10;
+ private static final int PARENT_DATA_CARRIER_ID = 11;
private static final int NON_DATA_CARRIER_ID = 20;
+ private static final int PARENT_NON_DATA_CARRIER_ID = 21;
private static final int DEACTIVE_CARRIER_ID = 30;
+ private static final String MATCH_PREFIX_IMSI = "123456*";
+ private static final String DATA_FULL_IMSI = "123456789123456";
+ private static final String NON_DATA_FULL_IMSI = "123456987654321";
+ private static final String NO_MATCH_FULL_IMSI = "654321123456789";
+ private static final String NO_MATCH_PREFIX_IMSI = "654321*";
+ private static final String DATA_OPERATOR_NUMERIC = "123456";
+ private static final String NON_DATA_OPERATOR_NUMERIC = "123456";
+ private static final String NO_MATCH_OPERATOR_NUMERIC = "654321";
private List<SubscriptionInfo> mSubInfoList;
@@ -109,10 +121,21 @@ public class TelephonyUtilTest extends WifiBaseTest {
doReturn(true).when(
() -> SubscriptionManager.isValidSubscriptionId(NON_DATA_SUBID));
+ when(mTelephonyManager.getSubscriberId(eq(DATA_SUBID))).thenReturn(DATA_FULL_IMSI);
+ when(mTelephonyManager.getSubscriberId(eq(NON_DATA_SUBID))).thenReturn(NON_DATA_FULL_IMSI);
when(mDataSubscriptionInfo.getCarrierId()).thenReturn(DATA_CARRIER_ID);
when(mDataSubscriptionInfo.getSubscriptionId()).thenReturn(DATA_SUBID);
when(mNonDataSubscriptionInfo.getCarrierId()).thenReturn(NON_DATA_CARRIER_ID);
when(mNonDataSubscriptionInfo.getSubscriptionId()).thenReturn(NON_DATA_SUBID);
+ when(mDataTelephonyManager.getSubscriberId()).thenReturn(DATA_FULL_IMSI);
+ when(mNonDataTelephonyManager.getSubscriberId()).thenReturn(NON_DATA_FULL_IMSI);
+ when(mDataTelephonyManager.getSimOperatorNumeric()).thenReturn(DATA_OPERATOR_NUMERIC);
+ when(mNonDataTelephonyManager.getSimOperatorNumeric())
+ .thenReturn(NON_DATA_OPERATOR_NUMERIC);
+ when(mDataTelephonyManager.getSimState()).thenReturn(TelephonyManager.SIM_STATE_READY);
+ when(mNonDataTelephonyManager.getSimState()).thenReturn(TelephonyManager.SIM_STATE_READY);
+ when(mSubscriptionManager.getActiveSubscriptionIdList())
+ .thenReturn(new int[]{DATA_SUBID, NON_DATA_SUBID});
}
@After
@@ -689,6 +712,7 @@ public class TelephonyUtilTest extends WifiBaseTest {
WifiConfiguration config = WifiConfigurationTestUtil.createEapNetwork(
WifiEnterpriseConfig.Eap.AKA, WifiEnterpriseConfig.Phase2.NONE);
when(mSubscriptionManager.getActiveSubscriptionInfoList()).thenReturn(null);
+ when(mSubscriptionManager.getActiveSubscriptionIdList()).thenReturn(new int[0]);
assertEquals(INVALID_SUBID, mTelephonyUtil.getBestMatchSubscriptionId(config));
@@ -702,7 +726,7 @@ public class TelephonyUtilTest extends WifiBaseTest {
* The matched Subscription ID should be that of data SIM when carrier ID is not specified.
*/
@Test
- public void getBestMatchSubscriptionIdWithoutCarrierIdFieldForSimConfig() {
+ public void getBestMatchSubscriptionIdForEnterpriseWithoutCarrierIdFieldForSimConfig() {
WifiConfiguration config = WifiConfigurationTestUtil.createEapNetwork(
WifiEnterpriseConfig.Eap.AKA, WifiEnterpriseConfig.Phase2.NONE);
@@ -714,7 +738,7 @@ public class TelephonyUtilTest extends WifiBaseTest {
* SIM card and the carrier ID is not specified.
*/
@Test
- public void getBestMatchSubscriptionIdWithoutCarrierIdFieldForNonSimConfig() {
+ public void getBestMatchSubscriptionIdForEnterpriseWithoutCarrierIdFieldForNonSimConfig() {
WifiConfiguration config = new WifiConfiguration();
assertEquals(INVALID_SUBID, mTelephonyUtil.getBestMatchSubscriptionId(config));
@@ -725,7 +749,7 @@ public class TelephonyUtilTest extends WifiBaseTest {
* should be returned.
*/
@Test
- public void getBestMatchSubscriptionIdWithNonDataCarrierId() {
+ public void getBestMatchSubscriptionIdForEnterpriseWithNonDataCarrierId() {
WifiConfiguration config = WifiConfigurationTestUtil.createEapNetwork(
WifiEnterpriseConfig.Eap.AKA, WifiEnterpriseConfig.Phase2.NONE);
config.carrierId = NON_DATA_CARRIER_ID;
@@ -737,6 +761,33 @@ public class TelephonyUtilTest extends WifiBaseTest {
}
/**
+ * If the passpoint profile have valid carrier ID, the matching sub ID should be returned.
+ */
+ @Test
+ public void getBestMatchSubscriptionIdForPasspointWithValidCarrierId() {
+ WifiConfiguration config = WifiConfigurationTestUtil.createEapNetwork(
+ WifiEnterpriseConfig.Eap.AKA, WifiEnterpriseConfig.Phase2.NONE);
+ config.carrierId = DATA_CARRIER_ID;
+ WifiConfiguration spyConfig = spy(config);
+ doReturn(true).when(spyConfig).isPasspoint();
+
+ assertEquals(DATA_SUBID, mTelephonyUtil.getBestMatchSubscriptionId(spyConfig));
+ }
+
+ /**
+ * If there is no matching SIM card, the matching sub ID should be invalid.
+ */
+ @Test
+ public void getBestMatchSubscriptionIdForPasspointInvalidCarrierId() {
+ WifiConfiguration config = WifiConfigurationTestUtil.createEapNetwork(
+ WifiEnterpriseConfig.Eap.AKA, WifiEnterpriseConfig.Phase2.NONE);
+ WifiConfiguration spyConfig = spy(config);
+ doReturn(true).when(spyConfig).isPasspoint();
+
+ assertEquals(INVALID_SUBID, mTelephonyUtil.getBestMatchSubscriptionId(spyConfig));
+ }
+
+ /**
* The matched Subscription ID should be invalid if the SIM card for the specified carrier ID
* is absent.
*/
@@ -748,4 +799,256 @@ public class TelephonyUtilTest extends WifiBaseTest {
assertEquals(INVALID_SUBID, mTelephonyUtil.getBestMatchSubscriptionId(config));
}
+
+ /**
+ * Verify that the result is null if no active SIM is matched.
+ */
+ @Test
+ public void getMatchingImsiCarrierIdWithDeactiveCarrierId() {
+ when(mSubscriptionManager.getActiveSubscriptionInfoList())
+ .thenReturn(Collections.emptyList());
+
+ assertNull(mTelephonyUtil.getMatchingImsi(DEACTIVE_CARRIER_ID));
+ }
+
+ /**
+ * Verify that if there is SIM card whose carrier ID is the same as the input, the correct IMSI
+ * and carrier ID would be returned.
+ */
+ @Test
+ public void getMatchingImsiCarrierIdWithValidCarrierId() {
+ assertEquals(DATA_FULL_IMSI,
+ mTelephonyUtil.getMatchingImsi(DATA_CARRIER_ID));
+ }
+
+ /**
+ * Verify that if there is no SIM, it should match nothing.
+ */
+ @Test
+ public void getMatchingImsiCarrierIdWithEmptyActiveSubscriptionInfoList() {
+ when(mSubscriptionManager.getActiveSubscriptionInfoList()).thenReturn(null);
+
+ assertNull(mTelephonyUtil.getMatchingImsiCarrierId(MATCH_PREFIX_IMSI));
+
+ when(mSubscriptionManager.getActiveSubscriptionInfoList())
+ .thenReturn(Collections.emptyList());
+
+ assertNull(mTelephonyUtil.getMatchingImsiCarrierId(MATCH_PREFIX_IMSI));
+ }
+
+ /**
+ * Verify that if there is no matching SIM, it should match nothing.
+ */
+ @Test
+ public void getMatchingImsiCarrierIdWithNoMatchImsi() {
+ // data SIM is MNO.
+ when(mDataTelephonyManager.getCarrierIdFromSimMccMnc()).thenReturn(DATA_CARRIER_ID);
+ when(mDataTelephonyManager.getSimCarrierId()).thenReturn(DATA_CARRIER_ID);
+ // non data SIM is MNO.
+ when(mNonDataTelephonyManager.getCarrierIdFromSimMccMnc()).thenReturn(NON_DATA_CARRIER_ID);
+ when(mNonDataTelephonyManager.getSimCarrierId()).thenReturn(NON_DATA_CARRIER_ID);
+
+ assertNull(mTelephonyUtil.getMatchingImsiCarrierId(NO_MATCH_PREFIX_IMSI));
+ }
+
+ /**
+ * Verify that if the matched SIM is the default data SIM and a MNO SIM, the information of it
+ * should be returned.
+ */
+ @Test
+ public void getMatchingImsiCarrierIdForDataAndMnoSimMatch() {
+ // data SIM is MNO.
+ when(mDataTelephonyManager.getCarrierIdFromSimMccMnc()).thenReturn(DATA_CARRIER_ID);
+ when(mDataTelephonyManager.getSimCarrierId()).thenReturn(DATA_CARRIER_ID);
+ // non data SIM is MNO.
+ when(mNonDataTelephonyManager.getCarrierIdFromSimMccMnc()).thenReturn(NON_DATA_CARRIER_ID);
+ when(mNonDataTelephonyManager.getSimCarrierId()).thenReturn(NON_DATA_CARRIER_ID);
+
+ Pair<String, Integer> ic = mTelephonyUtil.getMatchingImsiCarrierId(MATCH_PREFIX_IMSI);
+
+ assertEquals(new Pair<>(DATA_FULL_IMSI, DATA_CARRIER_ID), ic);
+
+ // non data SIM is MVNO
+ when(mNonDataTelephonyManager.getCarrierIdFromSimMccMnc())
+ .thenReturn(PARENT_NON_DATA_CARRIER_ID);
+ when(mNonDataTelephonyManager.getSimCarrierId()).thenReturn(NON_DATA_CARRIER_ID);
+
+ assertEquals(new Pair<>(DATA_FULL_IMSI, DATA_CARRIER_ID),
+ mTelephonyUtil.getMatchingImsiCarrierId(MATCH_PREFIX_IMSI));
+
+ // non data SIM doesn't match.
+ when(mNonDataTelephonyManager.getCarrierIdFromSimMccMnc()).thenReturn(NON_DATA_CARRIER_ID);
+ when(mNonDataTelephonyManager.getSimCarrierId()).thenReturn(NON_DATA_CARRIER_ID);
+ when(mNonDataTelephonyManager.getSubscriberId()).thenReturn(NO_MATCH_FULL_IMSI);
+ when(mNonDataTelephonyManager.getSimOperatorNumeric())
+ .thenReturn(NO_MATCH_OPERATOR_NUMERIC);
+
+ assertEquals(new Pair<>(DATA_FULL_IMSI, DATA_CARRIER_ID),
+ mTelephonyUtil.getMatchingImsiCarrierId(MATCH_PREFIX_IMSI));
+ }
+
+ /**
+ * Verify that if the matched SIM is the default data SIM and a MVNO SIM, and no MNO SIM was
+ * matched, the information of it should be returned.
+ */
+ @Test
+ public void getMatchingImsiCarrierIdForDataAndMvnoSimMatch() {
+ // data SIM is MVNO.
+ when(mDataTelephonyManager.getCarrierIdFromSimMccMnc()).thenReturn(PARENT_DATA_CARRIER_ID);
+ when(mDataTelephonyManager.getSimCarrierId()).thenReturn(DATA_CARRIER_ID);
+ // non data SIM is MVNO.
+ when(mNonDataTelephonyManager.getCarrierIdFromSimMccMnc())
+ .thenReturn(PARENT_NON_DATA_CARRIER_ID);
+ when(mNonDataTelephonyManager.getSimCarrierId()).thenReturn(NON_DATA_CARRIER_ID);
+
+ Pair<String, Integer> ic = mTelephonyUtil.getMatchingImsiCarrierId(MATCH_PREFIX_IMSI);
+
+ assertEquals(new Pair<>(DATA_FULL_IMSI, DATA_CARRIER_ID), ic);
+
+ // non data SIM doesn't match.
+ when(mNonDataTelephonyManager.getCarrierIdFromSimMccMnc()).thenReturn(NON_DATA_CARRIER_ID);
+ when(mNonDataTelephonyManager.getSimCarrierId()).thenReturn(NON_DATA_CARRIER_ID);
+ when(mNonDataTelephonyManager.getSubscriberId()).thenReturn(NO_MATCH_FULL_IMSI);
+ when(mNonDataTelephonyManager.getSimOperatorNumeric())
+ .thenReturn(NO_MATCH_OPERATOR_NUMERIC);
+
+ assertEquals(new Pair<>(DATA_FULL_IMSI, DATA_CARRIER_ID),
+ mTelephonyUtil.getMatchingImsiCarrierId(MATCH_PREFIX_IMSI));
+ }
+
+ /**
+ * Verify that if the matched SIM is a MNO SIM, even the default data SIM is matched as a MVNO
+ * SIM, the information of MNO SIM still should be returned.
+ */
+ @Test
+ public void getMatchingImsiCarrierIdForNonDataAndMnoSimMatch() {
+ // data SIM is MVNO.
+ when(mDataTelephonyManager.getCarrierIdFromSimMccMnc()).thenReturn(PARENT_DATA_CARRIER_ID);
+ when(mDataTelephonyManager.getSimCarrierId()).thenReturn(DATA_CARRIER_ID);
+ // non data SIM is MNO.
+ when(mNonDataTelephonyManager.getCarrierIdFromSimMccMnc()).thenReturn(NON_DATA_CARRIER_ID);
+ when(mNonDataTelephonyManager.getSimCarrierId()).thenReturn(NON_DATA_CARRIER_ID);
+
+
+ Pair<String, Integer> ic = mTelephonyUtil.getMatchingImsiCarrierId(MATCH_PREFIX_IMSI);
+
+ assertEquals(new Pair<>(NON_DATA_FULL_IMSI, NON_DATA_CARRIER_ID), ic);
+
+ // data SIM doesn't match
+ when(mDataTelephonyManager.getCarrierIdFromSimMccMnc()).thenReturn(DATA_CARRIER_ID);
+ when(mDataTelephonyManager.getSimCarrierId()).thenReturn(DATA_CARRIER_ID);
+ when(mDataTelephonyManager.getSubscriberId()).thenReturn(NO_MATCH_FULL_IMSI);
+ when(mDataTelephonyManager.getSimOperatorNumeric()).thenReturn(NO_MATCH_OPERATOR_NUMERIC);
+
+ assertEquals(new Pair<>(NON_DATA_FULL_IMSI, NON_DATA_CARRIER_ID),
+ mTelephonyUtil.getMatchingImsiCarrierId(MATCH_PREFIX_IMSI));
+ }
+
+ /**
+ * Verify that if only a MVNO SIM is matched, the information of it should be returned.
+ */
+ @Test
+ public void getMatchingImsiCarrierIdForMvnoSimMatch() {
+ // data SIM is MNO, but IMSI doesn't match.
+ when(mDataTelephonyManager.getCarrierIdFromSimMccMnc()).thenReturn(DATA_CARRIER_ID);
+ when(mDataTelephonyManager.getSimCarrierId()).thenReturn(DATA_CARRIER_ID);
+ when(mDataTelephonyManager.getSubscriberId()).thenReturn(NO_MATCH_FULL_IMSI);
+ when(mDataTelephonyManager.getSimOperatorNumeric()).thenReturn(NO_MATCH_OPERATOR_NUMERIC);
+ // non data SIM is MVNO.
+ when(mNonDataTelephonyManager.getCarrierIdFromSimMccMnc())
+ .thenReturn(PARENT_NON_DATA_CARRIER_ID);
+ when(mNonDataTelephonyManager.getSimCarrierId()).thenReturn(NON_DATA_CARRIER_ID);
+
+ assertEquals(new Pair<>(NON_DATA_FULL_IMSI, NON_DATA_CARRIER_ID),
+ mTelephonyUtil.getMatchingImsiCarrierId(MATCH_PREFIX_IMSI));
+ }
+
+ /**
+ * Verify that if there is no any SIM card, the carrier ID should be updated.
+ */
+ @Test
+ public void tryUpdateCarrierIdForPasspointWithEmptyActiveSubscriptionList() {
+ PasspointConfiguration config = mock(PasspointConfiguration.class);
+ when(config.getCarrierId()).thenReturn(DATA_CARRIER_ID);
+ when(mSubscriptionManager.getActiveSubscriptionInfoList()).thenReturn(null);
+
+ assertFalse(mTelephonyUtil.tryUpdateCarrierIdForPasspoint(config));
+
+ when(mSubscriptionManager.getActiveSubscriptionInfoList())
+ .thenReturn(Collections.emptyList());
+
+ assertFalse(mTelephonyUtil.tryUpdateCarrierIdForPasspoint(config));
+ }
+
+ /**
+ * Verify that if the carrier ID has been assigned, it shouldn't be updated.
+ */
+ @Test
+ public void tryUpdateCarrierIdForPasspointWithValidCarrieId() {
+ PasspointConfiguration config = mock(PasspointConfiguration.class);
+ when(config.getCarrierId()).thenReturn(DATA_CARRIER_ID);
+
+ assertFalse(mTelephonyUtil.tryUpdateCarrierIdForPasspoint(config));
+ }
+
+ /**
+ * Verify that if the passpoint profile doesn't have SIM credential, it shouldn't be updated.
+ */
+ @Test
+ public void tryUpdateCarrierIdForPasspointWithNonSimCredential() {
+ Credential credential = mock(Credential.class);
+ PasspointConfiguration spyConfig = spy(new PasspointConfiguration());
+ doReturn(credential).when(spyConfig).getCredential();
+ when(credential.getSimCredential()).thenReturn(null);
+
+ assertFalse(mTelephonyUtil.tryUpdateCarrierIdForPasspoint(spyConfig));
+ }
+
+ /**
+ * Verify that if the passpoint profile only have IMSI prefix(mccmnc*) parameter,
+ * it shouldn't be updated.
+ */
+ @Test
+ public void tryUpdateCarrierIdForPasspointWithPrefixImsi() {
+ Credential credential = mock(Credential.class);
+ PasspointConfiguration spyConfig = spy(new PasspointConfiguration());
+ doReturn(credential).when(spyConfig).getCredential();
+ Credential.SimCredential simCredential = mock(Credential.SimCredential.class);
+ when(credential.getSimCredential()).thenReturn(simCredential);
+ when(simCredential.getImsi()).thenReturn(MATCH_PREFIX_IMSI);
+
+ assertFalse(mTelephonyUtil.tryUpdateCarrierIdForPasspoint(spyConfig));
+ }
+
+ /**
+ * Verify that if the passpoint profile has the full IMSI and wasn't assigned valid
+ * carrier ID, it should be updated.
+ */
+ @Test
+ public void tryUpdateCarrierIdForPasspointWithFullImsiAndActiveSim() {
+ Credential credential = mock(Credential.class);
+ PasspointConfiguration spyConfig = spy(new PasspointConfiguration());
+ doReturn(credential).when(spyConfig).getCredential();
+ Credential.SimCredential simCredential = mock(Credential.SimCredential.class);
+ when(credential.getSimCredential()).thenReturn(simCredential);
+ when(simCredential.getImsi()).thenReturn(DATA_FULL_IMSI);
+
+ assertTrue(mTelephonyUtil.tryUpdateCarrierIdForPasspoint(spyConfig));
+ assertEquals(DATA_CARRIER_ID, spyConfig.getCarrierId());
+ }
+
+ /**
+ * Verify that if there is no SIM card matching the given IMSI, it shouldn't be updated.
+ */
+ @Test
+ public void tryUpdateCarrierIdForPasspointWithFullImsiAndInactiveSim() {
+ Credential credential = mock(Credential.class);
+ PasspointConfiguration spyConfig = spy(new PasspointConfiguration());
+ doReturn(credential).when(spyConfig).getCredential();
+ Credential.SimCredential simCredential = mock(Credential.SimCredential.class);
+ when(credential.getSimCredential()).thenReturn(simCredential);
+ when(simCredential.getImsi()).thenReturn(NO_MATCH_PREFIX_IMSI);
+
+ assertFalse(mTelephonyUtil.tryUpdateCarrierIdForPasspoint(spyConfig));
+ }
}