diff options
author | David Su <dysu@google.com> | 2019-05-10 16:53:18 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2019-05-10 16:53:18 +0000 |
commit | 4c9a76bb81ed1be218f0b49a68f15f063a79f4bb (patch) | |
tree | 46bb30b53bb898643a73b628cbc3e080aed2b37f | |
parent | 60aa18213ca04fa8a08786a0fe9cb4951d7b4486 (diff) | |
parent | bfe8dc332f563cfb9569dacb69d689f05dc37ba8 (diff) |
Merge "Fix all Wifi calls to TelephonyManager to explicitly use default data subscription" into qt-dev
21 files changed, 368 insertions, 294 deletions
diff --git a/service/java/com/android/server/wifi/CarrierNetworkConfig.java b/service/java/com/android/server/wifi/CarrierNetworkConfig.java index 1814eecf4..6e754231f 100644 --- a/service/java/com/android/server/wifi/CarrierNetworkConfig.java +++ b/service/java/com/android/server/wifi/CarrierNetworkConfig.java @@ -179,6 +179,7 @@ public class CarrierNetworkConfig { * @return True if carrier IMSI encryption info is available, False otherwise. */ private boolean verifyCarrierImsiEncryptionInfoIsAvailable(Context context) { + // TODO(b/132188983): Inject this using WifiInjector TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); if (telephonyManager == null) { @@ -186,6 +187,7 @@ public class CarrierNetworkConfig { } try { mLastImsiEncryptionInfo = telephonyManager + .createForSubscriptionId(SubscriptionManager.getDefaultDataSubscriptionId()) .getCarrierInfoForImsiEncryption(TelephonyManager.KEY_TYPE_WLAN); if (mLastImsiEncryptionInfo == null) { return false; diff --git a/service/java/com/android/server/wifi/CellularLinkLayerStatsCollector.java b/service/java/com/android/server/wifi/CellularLinkLayerStatsCollector.java index 473ced3ea..81d219cce 100644 --- a/service/java/com/android/server/wifi/CellularLinkLayerStatsCollector.java +++ b/service/java/com/android/server/wifi/CellularLinkLayerStatsCollector.java @@ -123,6 +123,7 @@ public class CellularLinkLayerStatsCollector { if (defaultDataSubId != mCachedDefaultDataSubId || mCachedDefaultDataTelephonyManager == null) { mCachedDefaultDataSubId = defaultDataSubId; + // TODO(b/132188983): Inject this using WifiInjector TelephonyManager defaultSubTelephonyManager = (TelephonyManager) mContext .getSystemService(Context.TELEPHONY_SERVICE); if (defaultDataSubId == mSubManager.getDefaultSubscriptionId()) { diff --git a/service/java/com/android/server/wifi/ClientModeImpl.java b/service/java/com/android/server/wifi/ClientModeImpl.java index 2a35bd28a..dbbd385b4 100644 --- a/service/java/com/android/server/wifi/ClientModeImpl.java +++ b/service/java/com/android/server/wifi/ClientModeImpl.java @@ -87,6 +87,7 @@ import android.os.UserManager; import android.os.WorkSource; import android.provider.Settings; import android.system.OsConstants; +import android.telephony.SubscriptionManager; import android.telephony.TelephonyManager; import android.text.TextUtils; import android.util.Log; @@ -4715,7 +4716,10 @@ public class ClientModeImpl extends StateMachine { case WifiEnterpriseConfig.Eap.AKA: case WifiEnterpriseConfig.Eap.AKA_PRIME: if (errorCode == WifiNative.EAP_SIM_VENDOR_SPECIFIC_CERT_EXPIRED) { - getTelephonyManager().resetCarrierKeysForImsiEncryption(); + getTelephonyManager() + .createForSubscriptionId( + SubscriptionManager.getDefaultDataSubscriptionId()) + .resetCarrierKeysForImsiEncryption(); } break; diff --git a/service/java/com/android/server/wifi/SIMAccessor.java b/service/java/com/android/server/wifi/SIMAccessor.java index 21bfb9c51..efa303752 100644 --- a/service/java/com/android/server/wifi/SIMAccessor.java +++ b/service/java/com/android/server/wifi/SIMAccessor.java @@ -12,7 +12,9 @@ public class SIMAccessor { private final SubscriptionManager mSubscriptionManager; public SIMAccessor(Context context) { + // TODO(b/132188983): Inject this using WifiInjector mTelephonyManager = TelephonyManager.from(context); + // TODO(b/132188983): Inject this using WifiInjector mSubscriptionManager = SubscriptionManager.from(context); } diff --git a/service/java/com/android/server/wifi/WifiInjector.java b/service/java/com/android/server/wifi/WifiInjector.java index 02a835673..e5391839f 100644 --- a/service/java/com/android/server/wifi/WifiInjector.java +++ b/service/java/com/android/server/wifi/WifiInjector.java @@ -241,7 +241,7 @@ public class WifiInjector { WifiConfigStore.createSharedFile()); // Config Manager mWifiConfigManager = new WifiConfigManager(mContext, mClock, - UserManager.get(mContext), TelephonyManager.from(mContext), + UserManager.get(mContext), makeTelephonyManager(), mWifiKeyStore, mWifiConfigStore, mWifiPermissionsUtil, mWifiPermissionsWrapper, this, new NetworkListSharedStoreData(mContext), new NetworkListUserStoreData(mContext), @@ -278,7 +278,7 @@ public class WifiInjector { mPasspointManager = new PasspointManager(mContext, this, new Handler(mWifiCoreHandlerThread.getLooper()), mWifiNative, mWifiKeyStore, mClock, mSimAccessor, new PasspointObjectFactory(), mWifiConfigManager, mWifiConfigStore, - mWifiMetrics); + mWifiMetrics, makeTelephonyManager()); mPasspointNetworkEvaluator = new PasspointNetworkEvaluator( mPasspointManager, mWifiConfigManager, mConnectivityLocalLog, mCarrierNetworkConfig, this); @@ -502,7 +502,7 @@ public class WifiInjector { return mWifiScoreCard; } - /** Gets a TelephonyManager, which moy not be available early on. */ + /** Gets a TelephonyManager, which may not be available early on. */ public TelephonyManager makeTelephonyManager() { return (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE); } diff --git a/service/java/com/android/server/wifi/hotspot2/PasspointManager.java b/service/java/com/android/server/wifi/hotspot2/PasspointManager.java index 020beaed2..917093ac2 100644 --- a/service/java/com/android/server/wifi/hotspot2/PasspointManager.java +++ b/service/java/com/android/server/wifi/hotspot2/PasspointManager.java @@ -49,6 +49,7 @@ import android.os.Handler; import android.os.Looper; import android.os.Process; import android.os.UserHandle; +import android.telephony.SubscriptionManager; import android.telephony.TelephonyManager; import android.text.TextUtils; import android.util.Log; @@ -332,7 +333,7 @@ public class PasspointManager { WifiNative wifiNative, WifiKeyStore keyStore, Clock clock, SIMAccessor simAccessor, PasspointObjectFactory objectFactory, WifiConfigManager wifiConfigManager, WifiConfigStore wifiConfigStore, - WifiMetrics wifiMetrics) { + WifiMetrics wifiMetrics, TelephonyManager telephonyManager) { mPasspointEventHandler = objectFactory.makePasspointEventHandler(wifiNative, new CallbackHandler(context)); mWifiInjector = wifiInjector; @@ -347,7 +348,7 @@ public class PasspointManager { mWifiConfigManager = wifiConfigManager; mWifiMetrics = wifiMetrics; mProviderIndex = 0; - mTelephonyManager = TelephonyManager.from(context); + mTelephonyManager = telephonyManager; wifiConfigStore.registerStoreData(objectFactory.makePasspointConfigUserStoreData( mKeyStore, mSimAccessor, new UserDataSourceHandler())); wifiConfigStore.registerStoreData(objectFactory.makePasspointConfigSharedStoreData( @@ -454,7 +455,9 @@ public class PasspointManager { return -1; } - String mccMnc = mTelephonyManager.getSimOperator(); + String mccMnc = mTelephonyManager + .createForSubscriptionId(SubscriptionManager.getDefaultDataSubscriptionId()) + .getSimOperator(); if (mccMnc == null || mccMnc.length() < IMSIParameter.MCC_MNC_LENGTH - 1) { return -1; } @@ -515,7 +518,9 @@ public class PasspointManager { * {@code null} otherwise. */ public PasspointConfiguration createEphemeralPasspointConfigForCarrier(int eapMethod) { - String mccMnc = mTelephonyManager.getSimOperator(); + String mccMnc = mTelephonyManager + .createForSubscriptionId(SubscriptionManager.getDefaultDataSubscriptionId()) + .getSimOperator(); if (mccMnc == null || mccMnc.length() < IMSIParameter.MCC_MNC_LENGTH - 1) { Log.e(TAG, "invalid length of mccmnc"); return null; @@ -534,7 +539,10 @@ public class PasspointManager { PasspointConfiguration config = new PasspointConfiguration(); HomeSp homeSp = new HomeSp(); homeSp.setFqdn(domain); - homeSp.setFriendlyName(mTelephonyManager.getSimOperatorName()); + String friendlyName = mTelephonyManager + .createForSubscriptionId(SubscriptionManager.getDefaultDataSubscriptionId()) + .getSimOperatorName(); + homeSp.setFriendlyName(friendlyName); config.setHomeSp(homeSp); Credential credential = new Credential(); diff --git a/service/java/com/android/server/wifi/hotspot2/PasspointNetworkEvaluator.java b/service/java/com/android/server/wifi/hotspot2/PasspointNetworkEvaluator.java index f0ea8c55e..5e6fa8ca2 100644 --- a/service/java/com/android/server/wifi/hotspot2/PasspointNetworkEvaluator.java +++ b/service/java/com/android/server/wifi/hotspot2/PasspointNetworkEvaluator.java @@ -23,6 +23,7 @@ import android.net.wifi.ScanResult; import android.net.wifi.WifiConfiguration; import android.net.wifi.hotspot2.PasspointConfiguration; import android.os.Process; +import android.telephony.SubscriptionManager; import android.telephony.TelephonyManager; import android.text.TextUtils; import android.util.LocalLog; @@ -120,24 +121,7 @@ public class PasspointNetworkEvaluator implements WifiNetworkSelector.NetworkEva } }).collect(Collectors.toList()); - // Creates an ephemeral Passpoint profile if it finds a matching Passpoint AP for MCC/MNC - // of the current MNO carrier on the device. - if ((getTelephonyManager() != null) - && (TelephonyUtil.getCarrierType(mTelephonyManager) - == TelephonyUtil.CARRIER_MNO_TYPE) - && mCarrierNetworkConfig.isCarrierEncryptionInfoAvailable() - && !mPasspointManager.hasCarrierProvider(mTelephonyManager.getSimOperator())) { - int eapMethod = mPasspointManager.findEapMethodFromNAIRealmMatchedWithCarrier( - filteredScanDetails); - if (isCarrierEapMethod(eapMethod)) { - PasspointConfiguration carrierConfig = - mPasspointManager.createEphemeralPasspointConfigForCarrier( - eapMethod); - if (carrierConfig != null) { - mPasspointManager.installEphemeralPasspointConfigForCarrier(carrierConfig); - } - } - } + createEphemeralProfileForMatchingAp(filteredScanDetails); // Go through each ScanDetail and find the best provider for each ScanDetail. List<PasspointNetworkCandidate> candidateList = new ArrayList<>(); @@ -190,6 +174,41 @@ public class PasspointNetworkEvaluator implements WifiNetworkSelector.NetworkEva } /** + * Creates an ephemeral Passpoint profile if it finds a matching Passpoint AP for MCC/MNC + * of the current MNO carrier on the device. + */ + private void createEphemeralProfileForMatchingAp(List<ScanDetail> filteredScanDetails) { + TelephonyManager telephonyManager = getTelephonyManager(); + if (telephonyManager == null) { + return; + } + if (TelephonyUtil.getCarrierType(telephonyManager) != TelephonyUtil.CARRIER_MNO_TYPE) { + return; + } + if (!mCarrierNetworkConfig.isCarrierEncryptionInfoAvailable()) { + return; + } + String mccMnc = telephonyManager + .createForSubscriptionId(SubscriptionManager.getDefaultDataSubscriptionId()) + .getSimOperator(); + if (mPasspointManager.hasCarrierProvider(mccMnc)) { + return; + } + int eapMethod = + mPasspointManager.findEapMethodFromNAIRealmMatchedWithCarrier(filteredScanDetails); + if (!isCarrierEapMethod(eapMethod)) { + return; + } + PasspointConfiguration carrierConfig = + mPasspointManager.createEphemeralPasspointConfigForCarrier(eapMethod); + if (carrierConfig == null) { + return; + } + + mPasspointManager.installEphemeralPasspointConfigForCarrier(carrierConfig); + } + + /** * Create and return a WifiConfiguration for the given ScanDetail and PasspointProvider. * The newly created WifiConfiguration will also be added to WifiConfigManager. * diff --git a/service/java/com/android/server/wifi/hotspot2/SystemInfo.java b/service/java/com/android/server/wifi/hotspot2/SystemInfo.java index d6e37fd07..fe675c6f5 100644 --- a/service/java/com/android/server/wifi/hotspot2/SystemInfo.java +++ b/service/java/com/android/server/wifi/hotspot2/SystemInfo.java @@ -20,6 +20,7 @@ import android.annotation.NonNull; import android.content.Context; import android.os.Build; import android.os.SystemProperties; +import android.telephony.SubscriptionManager; import android.telephony.TelephonyManager; import android.text.TextUtils; @@ -42,6 +43,7 @@ public class SystemInfo { @VisibleForTesting SystemInfo(Context context, WifiNative wifiNative) { + // TODO(b/132188983): inject this using WifiInjector mTelephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); mWifiNative = wifiNative; } @@ -98,14 +100,16 @@ public class SystemInfo { * @return String representing device ID */ public String getDeviceId() { + TelephonyManager defaultDataTm = mTelephonyManager.createForSubscriptionId( + SubscriptionManager.getDefaultDataSubscriptionId()); // IMEI will be provided for GSM SIM. - String imei = mTelephonyManager.getImei(); + String imei = defaultDataTm.getImei(); if (!TextUtils.isEmpty(imei)) { return imei; } // MEID will be provided for CMDA SIM. - String meid = mTelephonyManager.getMeid(); + String meid = defaultDataTm.getMeid(); if (!TextUtils.isEmpty(meid)) { return meid; } diff --git a/service/java/com/android/server/wifi/hotspot2/omadm/DevDetailMo.java b/service/java/com/android/server/wifi/hotspot2/omadm/DevDetailMo.java index 6c93df4f2..4f0152d17 100644 --- a/service/java/com/android/server/wifi/hotspot2/omadm/DevDetailMo.java +++ b/service/java/com/android/server/wifi/hotspot2/omadm/DevDetailMo.java @@ -19,6 +19,7 @@ package com.android.server.wifi.hotspot2.omadm; import android.annotation.NonNull; import android.content.Context; import android.net.wifi.EAPConstants; +import android.telephony.SubscriptionManager; import android.telephony.TelephonyManager; import android.text.TextUtils; import android.util.Log; @@ -163,8 +164,6 @@ public class DevDetailMo { return null; } - TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService( - Context.TELEPHONY_SERVICE); // Create the XML document for DevInfoMo Document doc = moSerializer.createNewDocument(); Element rootElement = moSerializer.createMgmtTree(doc); @@ -207,7 +206,11 @@ public class DevDetailMo { redirectUri)); wifiNode.appendChild(moSerializer.createNodeForValue(doc, TAG_WIFI_MAC_ADDR, macAddress)); - String imsi = telephonyManager.getSubscriberId(); + // TODO(b/132188983): Inject this using WifiInjector + TelephonyManager telephonyManager = context.getSystemService(TelephonyManager.class); + String imsi = telephonyManager + .createForSubscriptionId(SubscriptionManager.getDefaultDataSubscriptionId()) + .getSubscriberId(); if (imsi != null && sAllowToSendImsiImeiInfo) { // Don't provide the IMSI to an SP that did not issue the IMSI wifiNode.appendChild(moSerializer.createNodeForValue(doc, TAG_IMSI, imsi)); diff --git a/service/java/com/android/server/wifi/util/TelephonyUtil.java b/service/java/com/android/server/wifi/util/TelephonyUtil.java index 80cadc0af..abaeabe44 100644 --- a/service/java/com/android/server/wifi/util/TelephonyUtil.java +++ b/service/java/com/android/server/wifi/util/TelephonyUtil.java @@ -24,6 +24,7 @@ import android.annotation.NonNull; import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiEnterpriseConfig; import android.telephony.ImsiEncryptionInfo; +import android.telephony.SubscriptionManager; import android.telephony.TelephonyManager; import android.util.Base64; import android.util.Log; @@ -46,6 +47,8 @@ import javax.crypto.NoSuchPaddingException; /** * Utilities for the Wifi Service to interact with telephony. + * TODO(b/132188983): Refactor into TelephonyFacade which owns all instances of + * TelephonyManager/SubscriptionManager in Wifi */ public class TelephonyUtil { public static final String TAG = "TelephonyUtil"; @@ -95,15 +98,17 @@ public class TelephonyUtil { Log.e(TAG, "No valid TelephonyManager"); return null; } + TelephonyManager defaultDataTm = tm.createForSubscriptionId( + SubscriptionManager.getDefaultDataSubscriptionId()); if (carrierNetworkConfig == null) { Log.e(TAG, "No valid CarrierNetworkConfig"); return null; } - String imsi = tm.getSubscriberId(); + String imsi = defaultDataTm.getSubscriberId(); String mccMnc = ""; - if (tm.getSimState() == TelephonyManager.SIM_STATE_READY) { - mccMnc = tm.getSimOperator(); + if (defaultDataTm.getSimState() == TelephonyManager.SIM_STATE_READY) { + mccMnc = defaultDataTm.getSimOperator(); } String identity = buildIdentity(getSimMethodForConfig(config), imsi, mccMnc, false); @@ -114,7 +119,8 @@ public class TelephonyUtil { ImsiEncryptionInfo imsiEncryptionInfo; try { - imsiEncryptionInfo = tm.getCarrierInfoForImsiEncryption(TelephonyManager.KEY_TYPE_WLAN); + imsiEncryptionInfo = defaultDataTm.getCarrierInfoForImsiEncryption( + TelephonyManager.KEY_TYPE_WLAN); } catch (RuntimeException e) { Log.e(TAG, "Failed to get imsi encryption info: " + e.getMessage()); return null; @@ -154,10 +160,15 @@ public class TelephonyUtil { * not ready or absent. */ public static String getAnonymousIdentityWith3GppRealm(@Nonnull TelephonyManager tm) { - if (tm == null || tm.getSimState() != TelephonyManager.SIM_STATE_READY) { + if (tm == null) { + return null; + } + TelephonyManager defaultDataTm = tm.createForSubscriptionId( + SubscriptionManager.getDefaultDataSubscriptionId()); + if (defaultDataTm.getSimState() != TelephonyManager.SIM_STATE_READY) { return null; } - String mccMnc = tm.getSimOperator(); + String mccMnc = defaultDataTm.getSimOperator(); if (mccMnc == null || mccMnc.isEmpty()) { return null; } @@ -518,6 +529,8 @@ public class TelephonyUtil { Log.e(TAG, "No valid TelephonyManager"); return null; } + TelephonyManager defaultDataTm = tm.createForSubscriptionId( + SubscriptionManager.getDefaultDataSubscriptionId()); StringBuilder sb = new StringBuilder(); for (String challenge : requestData) { if (challenge == null || challenge.isEmpty()) { @@ -535,8 +548,8 @@ public class TelephonyUtil { String base64Challenge = Base64.encodeToString(rand, Base64.NO_WRAP); - String tmResponse = tm.getIccAuthentication(appType, - TelephonyManager.AUTHTYPE_EAP_SIM, base64Challenge); + String tmResponse = defaultDataTm.getIccAuthentication( + appType, TelephonyManager.AUTHTYPE_EAP_SIM, base64Challenge); Log.v(TAG, "Raw Response - " + tmResponse); if (tmResponse == null || tmResponse.length() <= 4) { @@ -589,6 +602,8 @@ public class TelephonyUtil { Log.e(TAG, "No valid TelephonyManager"); return null; } + TelephonyManager defaultDataTm = tm.createForSubscriptionId( + SubscriptionManager.getDefaultDataSubscriptionId()); StringBuilder sb = new StringBuilder(); for (String challenge : requestData) { if (challenge == null || challenge.isEmpty()) { @@ -606,7 +621,7 @@ public class TelephonyUtil { String base64Challenge = Base64.encodeToString(rand, Base64.NO_WRAP); - String tmResponse = tm.getIccAuthentication(TelephonyManager.APPTYPE_SIM, + String tmResponse = defaultDataTm.getIccAuthentication(TelephonyManager.APPTYPE_SIM, TelephonyManager.AUTHTYPE_EAP_SIM, base64Challenge); Log.v(TAG, "Raw Response - " + tmResponse); @@ -685,8 +700,10 @@ public class TelephonyUtil { if (rand != null && authn != null) { String base64Challenge = Base64.encodeToString(concatHex(rand, authn), Base64.NO_WRAP); if (tm != null) { - tmResponse = tm.getIccAuthentication(TelephonyManager.APPTYPE_USIM, - TelephonyManager.AUTHTYPE_EAP_AKA, base64Challenge); + tmResponse = tm + .createForSubscriptionId(SubscriptionManager.getDefaultDataSubscriptionId()) + .getIccAuthentication(TelephonyManager.APPTYPE_USIM, + TelephonyManager.AUTHTYPE_EAP_AKA, base64Challenge); Log.v(TAG, "Raw Response - " + tmResponse); } else { Log.e(TAG, "No valid TelephonyManager"); @@ -741,12 +758,18 @@ public class TelephonyUtil { * ready or {@code tm} is {@code null} */ public static int getCarrierType(@NonNull TelephonyManager tm) { - if (tm == null || tm.getSimState() != TelephonyManager.SIM_STATE_READY) { + if (tm == null) { + return CARRIER_INVALID_TYPE; + } + TelephonyManager defaultDataTm = tm.createForSubscriptionId( + SubscriptionManager.getDefaultDataSubscriptionId()); + + if (defaultDataTm.getSimState() != TelephonyManager.SIM_STATE_READY) { return CARRIER_INVALID_TYPE; } // If two APIs return the same carrier ID, then is considered as MNO, otherwise MVNO - if (tm.getCarrierIdFromSimMccMnc() == tm.getSimCarrierId()) { + if (defaultDataTm.getCarrierIdFromSimMccMnc() == defaultDataTm.getSimCarrierId()) { return CARRIER_MNO_TYPE; } return CARRIER_MVNO_TYPE; diff --git a/tests/wifitests/src/com/android/server/wifi/CarrierNetworkConfigTest.java b/tests/wifitests/src/com/android/server/wifi/CarrierNetworkConfigTest.java index d0cdf2e83..082944e5d 100644 --- a/tests/wifitests/src/com/android/server/wifi/CarrierNetworkConfigTest.java +++ b/tests/wifitests/src/com/android/server/wifi/CarrierNetworkConfigTest.java @@ -65,6 +65,7 @@ public class CarrierNetworkConfigTest { @Mock CarrierConfigManager mCarrierConfigManager; @Mock SubscriptionManager mSubscriptionManager; @Mock TelephonyManager mTelephonyManager; + @Mock TelephonyManager mDataTelephonyManager; @Mock PublicKey mPublicKey; @Mock FrameworkFacade mFrameworkFacade; BroadcastReceiver mBroadcastReceiver; @@ -107,13 +108,14 @@ public class CarrierNetworkConfigTest { when(mContext.getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE)) .thenReturn(mSubscriptionManager); when(mContext.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn(mTelephonyManager); + when(mTelephonyManager.createForSubscriptionId(anyInt())).thenReturn(mDataTelephonyManager); when(mCarrierConfigManager.getConfigForSubId(TEST_SUBSCRIPTION_ID)) .thenReturn(generateTestConfig(TEST_SSID, TEST_STANDARD_EAP_TYPE, CarrierNetworkConfig.ENCODING_METHOD_RFC_2045, CarrierNetworkConfig.IDENTITY_SEQUENCE_IMSI_V1_0)); when(mSubscriptionManager.getActiveSubscriptionInfoList()) .thenReturn(Arrays.asList(new SubscriptionInfo[] {TEST_SUBSCRIPTION_INFO})); - when(mTelephonyManager.getCarrierInfoForImsiEncryption(TelephonyManager.KEY_TYPE_WLAN)) + when(mDataTelephonyManager.getCarrierInfoForImsiEncryption(TelephonyManager.KEY_TYPE_WLAN)) .thenReturn(mImsiEncryptionInfo); mLooper = new TestLooper(); mCarrierNetworkConfig = new CarrierNetworkConfig(mContext, mLooper.getLooper(), @@ -168,7 +170,7 @@ public class CarrierNetworkConfigTest { @Test public void verifyIsCarrierEncryptionInfoAvailableReturnsFalseWhenEncryptionInfoNotAvailable() throws Exception { - when(mTelephonyManager.getCarrierInfoForImsiEncryption(TelephonyManager.KEY_TYPE_WLAN)) + when(mDataTelephonyManager.getCarrierInfoForImsiEncryption(TelephonyManager.KEY_TYPE_WLAN)) .thenReturn(null); mBroadcastReceiver.onReceive(mContext, new Intent(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED)); @@ -248,14 +250,14 @@ public class CarrierNetworkConfigTest { */ @Test public void onFeatureDisable_setWifiNetworksAvailableNotificationSettingDisabled() { - when(mTelephonyManager.getCarrierInfoForImsiEncryption(TelephonyManager.KEY_TYPE_WLAN)) + when(mDataTelephonyManager.getCarrierInfoForImsiEncryption(TelephonyManager.KEY_TYPE_WLAN)) .thenReturn(null); mBroadcastReceiver.onReceive(mContext, new Intent(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED)); // make sure the initial value is false assertFalse(mCarrierNetworkConfig.isCarrierEncryptionInfoAvailable()); - when(mTelephonyManager.getCarrierInfoForImsiEncryption(TelephonyManager.KEY_TYPE_WLAN)) + when(mDataTelephonyManager.getCarrierInfoForImsiEncryption(TelephonyManager.KEY_TYPE_WLAN)) .thenReturn(mImsiEncryptionInfo); mContentObserver.onChange(false); assertTrue(mCarrierNetworkConfig.isCarrierEncryptionInfoAvailable()); diff --git a/tests/wifitests/src/com/android/server/wifi/CarrierNetworkEvaluatorTest.java b/tests/wifitests/src/com/android/server/wifi/CarrierNetworkEvaluatorTest.java index 4c9d82df1..650b9ee8b 100644 --- a/tests/wifitests/src/com/android/server/wifi/CarrierNetworkEvaluatorTest.java +++ b/tests/wifitests/src/com/android/server/wifi/CarrierNetworkEvaluatorTest.java @@ -80,6 +80,7 @@ public class CarrierNetworkEvaluatorTest { @Mock private WifiNetworkSelector.NetworkEvaluator.OnConnectableListener mConnectableListener; @Mock private WifiInjector mWifiInjector; @Mock private TelephonyManager mTelephonyManager; + @Mock private TelephonyManager mDataTelephonyManager; private ArgumentCaptor<ScanDetail> mScanDetailCaptor = ArgumentCaptor.forClass( ScanDetail.class); @@ -155,8 +156,9 @@ public class CarrierNetworkEvaluatorTest { mWifiInjector); when(mWifiInjector.makeTelephonyManager()).thenReturn(mTelephonyManager); - when(mTelephonyManager.getSimOperator()).thenReturn(TEST_MCC_MNC); - when(mTelephonyManager.getSimState()).thenReturn(TelephonyManager.SIM_STATE_READY); + when(mTelephonyManager.createForSubscriptionId(anyInt())).thenReturn(mDataTelephonyManager); + when(mDataTelephonyManager.getSimOperator()).thenReturn(TEST_MCC_MNC); + when(mDataTelephonyManager.getSimState()).thenReturn(TelephonyManager.SIM_STATE_READY); when(mCarrierNetworkConfig.isCarrierEncryptionInfoAvailable()).thenReturn(true); when(mCarrierNetworkConfig.getEapIdentitySequence()).thenReturn( CarrierNetworkConfig.IDENTITY_SEQUENCE_IMSI_V1_0); diff --git a/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java b/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java index 4fb6456d5..f0e0daefc 100644 --- a/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java +++ b/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java @@ -363,6 +363,7 @@ public class ClientModeImplTest { @Mock WifiPermissionsUtil mWifiPermissionsUtil; @Mock IIpClient mIpClient; @Mock TelephonyManager mTelephonyManager; + @Mock TelephonyManager mDataTelephonyManager; @Mock WrongPasswordNotifier mWrongPasswordNotifier; @Mock Clock mClock; @Mock ScanDetailCache mScanDetailCache; @@ -421,6 +422,7 @@ public class ClientModeImplTest { when(mWifiInjector.getSelfRecovery()).thenReturn(mSelfRecovery); when(mWifiInjector.getWifiPermissionsUtil()).thenReturn(mWifiPermissionsUtil); when(mWifiInjector.makeTelephonyManager()).thenReturn(mTelephonyManager); + when(mTelephonyManager.createForSubscriptionId(anyInt())).thenReturn(mDataTelephonyManager); when(mWifiInjector.getClock()).thenReturn(mClock); when(mWifiServiceHandlerThread.getLooper()).thenReturn(mLooper.getLooper()); when(mWifiInjector.getWifiServiceHandlerThread()).thenReturn(mWifiServiceHandlerThread); @@ -482,7 +484,7 @@ public class ClientModeImplTest { throws Exception { mPhoneStateListener = phoneStateListener; } - }).when(mTelephonyManager).listen(any(PhoneStateListener.class), anyInt()); + }).when(mDataTelephonyManager).listen(any(PhoneStateListener.class), anyInt()); when(mWifiPermissionsUtil.checkNetworkSettingsPermission(anyInt())).thenReturn(true); when(mWifiPermissionsWrapper.getLocalMacAddressPermission(anyInt())) @@ -1018,8 +1020,8 @@ public class ClientModeImplTest { public void testSetAnonymousIdentityWhenConnectionIsEstablished() throws Exception { mConnectedNetwork = spy(WifiConfigurationTestUtil.createEapNetwork( WifiEnterpriseConfig.Eap.SIM, WifiEnterpriseConfig.Phase2.NONE)); - when(mTelephonyManager.getSimOperator()).thenReturn("123456"); - when(mTelephonyManager.getSimState()).thenReturn(TelephonyManager.SIM_STATE_READY); + when(mDataTelephonyManager.getSimOperator()).thenReturn("123456"); + when(mDataTelephonyManager.getSimState()).thenReturn(TelephonyManager.SIM_STATE_READY); String expectedAnonymousIdentity = TelephonyUtil.getAnonymousIdentityWith3GppRealm( mTelephonyManager); triggerConnect(); @@ -1448,7 +1450,7 @@ public class ClientModeImplTest { WifiNative.EAP_SIM_VENDOR_SPECIFIC_CERT_EXPIRED); mLooper.dispatchAll(); - verify(mTelephonyManager).resetCarrierKeysForImsiEncryption(); + verify(mDataTelephonyManager).resetCarrierKeysForImsiEncryption(); } /** @@ -1476,7 +1478,7 @@ public class ClientModeImplTest { WifiNative.EAP_SIM_VENDOR_SPECIFIC_CERT_EXPIRED); mLooper.dispatchAll(); - verify(mTelephonyManager, never()).resetCarrierKeysForImsiEncryption(); + verify(mDataTelephonyManager, never()).resetCarrierKeysForImsiEncryption(); } /** diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java index a2d0e46b8..b8f6c57fc 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java @@ -115,6 +115,7 @@ public class WifiConfigManagerTest { @Mock private Clock mClock; @Mock private UserManager mUserManager; @Mock private TelephonyManager mTelephonyManager; + @Mock private TelephonyManager mDataTelephonyManager; @Mock private WifiKeyStore mWifiKeyStore; @Mock private WifiConfigStore mWifiConfigStore; @Mock private PackageManager mPackageManager; @@ -227,6 +228,7 @@ public class WifiConfigManagerTest { .mockStatic(WifiConfigStore.class, withSettings().lenient()) .startMocking(); when(WifiConfigStore.createUserFiles(anyInt())).thenReturn(mock(List.class)); + when(mTelephonyManager.createForSubscriptionId(anyInt())).thenReturn(mDataTelephonyManager); } /** @@ -4286,10 +4288,10 @@ public class WifiConfigManagerTest { @Test public void testResetSimNetworks() { String expectedIdentity = "13214561234567890@wlan.mnc456.mcc321.3gppnetwork.org"; - when(mTelephonyManager.getSubscriberId()).thenReturn("3214561234567890"); - when(mTelephonyManager.getSimState()).thenReturn(TelephonyManager.SIM_STATE_READY); - when(mTelephonyManager.getSimOperator()).thenReturn("321456"); - when(mTelephonyManager.getCarrierInfoForImsiEncryption(anyInt())).thenReturn(null); + when(mDataTelephonyManager.getSubscriberId()).thenReturn("3214561234567890"); + when(mDataTelephonyManager.getSimState()).thenReturn(TelephonyManager.SIM_STATE_READY); + when(mDataTelephonyManager.getSimOperator()).thenReturn("321456"); + when(mDataTelephonyManager.getCarrierInfoForImsiEncryption(anyInt())).thenReturn(null); WifiConfiguration network = WifiConfigurationTestUtil.createEapNetwork(); WifiConfiguration simNetwork = WifiConfigurationTestUtil.createEapNetwork( @@ -4327,7 +4329,7 @@ public class WifiConfigManagerTest { assertFalse(retrievedPeapSimNetwork.enterpriseConfig.getAnonymousIdentity().isEmpty()); // Call resetSimNetworks with false(SIM is not present). - when(mTelephonyManager.getSubscriberId()).thenReturn("3214561234567891"); + when(mDataTelephonyManager.getSubscriberId()).thenReturn("3214561234567891"); retrievedSimNetwork.enterpriseConfig.setAnonymousIdentity("anonymous_identity22"); verifyUpdateNetworkToWifiConfigManagerWithoutIpChange(retrievedSimNetwork); mWifiConfigManager.resetSimNetworks(false); @@ -4371,10 +4373,10 @@ public class WifiConfigManagerTest { @Test public void testResetSimNetworksIsCalledAgainAfterLoadFromStore() { String expectedIdentity = "13214561234567890@wlan.mnc456.mcc321.3gppnetwork.org"; - when(mTelephonyManager.getSubscriberId()).thenReturn("3214561234567890"); - when(mTelephonyManager.getSimState()).thenReturn(TelephonyManager.SIM_STATE_READY); - when(mTelephonyManager.getSimOperator()).thenReturn("321456"); - when(mTelephonyManager.getCarrierInfoForImsiEncryption(anyInt())).thenReturn(null); + when(mDataTelephonyManager.getSubscriberId()).thenReturn("3214561234567890"); + when(mDataTelephonyManager.getSimState()).thenReturn(TelephonyManager.SIM_STATE_READY); + when(mDataTelephonyManager.getSimOperator()).thenReturn("321456"); + when(mDataTelephonyManager.getCarrierInfoForImsiEncryption(anyInt())).thenReturn(null); WifiConfiguration simNetwork = WifiConfigurationTestUtil.createEapNetwork( WifiEnterpriseConfig.Eap.SIM, WifiEnterpriseConfig.Phase2.NONE); 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 e7535b2fa..bf71b927e 100644 --- a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java @@ -184,6 +184,8 @@ public class PasspointManagerTest { @Mock AppOpsManager mAppOpsManager; @Mock WifiInjector mWifiInjector; @Mock ClientModeImpl mClientModeImpl; + @Mock TelephonyManager mTelephonyManager; + @Mock TelephonyManager mDataTelephonyManager; Handler mHandler; TestLooper mLooper; @@ -214,7 +216,7 @@ public class PasspointManagerTest { mHandler = new Handler(mLooper.getLooper()); mManager = new PasspointManager(mContext, mWifiInjector, mHandler, mWifiNative, mWifiKeyStore, mClock, mSimAccessor, mObjectFactory, mWifiConfigManager, - mWifiConfigStore, mWifiMetrics); + mWifiConfigStore, mWifiMetrics, mTelephonyManager); ArgumentCaptor<PasspointEventHandler.Callbacks> callbacks = ArgumentCaptor.forClass(PasspointEventHandler.Callbacks.class); verify(mObjectFactory).makePasspointEventHandler(any(WifiNative.class), @@ -1620,22 +1622,14 @@ public class PasspointManagerTest { */ @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.getSimOperator()).thenReturn("123456"); - PasspointManager passpointManager = new PasspointManager(mContext, mWifiInjector, - mHandler, mWifiNative, mWifiKeyStore, mClock, mSimAccessor, mObjectFactory, - mWifiConfigManager, mWifiConfigStore, mWifiMetrics); + when(mTelephonyManager.createForSubscriptionId(anyInt())).thenReturn(mDataTelephonyManager); + when(mDataTelephonyManager.getSimOperator()).thenReturn("123456"); + PasspointManager passpointManager = new PasspointManager(mContext, mWifiInjector, + mHandler, mWifiNative, mWifiKeyStore, mClock, mSimAccessor, mObjectFactory, + mWifiConfigManager, mWifiConfigStore, mWifiMetrics, mTelephonyManager); - assertNull(passpointManager.createEphemeralPasspointConfigForCarrier( - EAPConstants.EAP_TLS)); - } finally { - session.finishMocking(); - } + assertNull(passpointManager.createEphemeralPasspointConfigForCarrier( + EAPConstants.EAP_TLS)); } /** @@ -1643,30 +1637,22 @@ public class PasspointManagerTest { */ @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.getSimOperator()).thenReturn(mccmnc); - when(telephonyManager.getSimOperatorName()).thenReturn("test"); - PasspointManager passpointManager = new PasspointManager(mContext, mWifiInjector, - mHandler, mWifiNative, mWifiKeyStore, mClock, mSimAccessor, mObjectFactory, - mWifiConfigManager, mWifiConfigStore, mWifiMetrics); + String mccmnc = "123456"; + when(mTelephonyManager.createForSubscriptionId(anyInt())).thenReturn(mDataTelephonyManager); + when(mDataTelephonyManager.getSimOperator()).thenReturn(mccmnc); + when(mDataTelephonyManager.getSimOperatorName()).thenReturn("test"); + PasspointManager passpointManager = new PasspointManager(mContext, mWifiInjector, + mHandler, mWifiNative, mWifiKeyStore, mClock, mSimAccessor, mObjectFactory, + mWifiConfigManager, mWifiConfigStore, mWifiMetrics, mTelephonyManager); - PasspointConfiguration result = - passpointManager.createEphemeralPasspointConfigForCarrier( - EAPConstants.EAP_AKA); + 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(); - } + assertNotNull(result); + assertTrue(result.validate()); + assertEquals(Utils.getRealmForMccMnc(mccmnc), result.getHomeSp().getFqdn()); + assertEquals(mccmnc + "*", result.getCredential().getSimCredential().getImsi()); } /** @@ -1726,13 +1712,13 @@ public class PasspointManagerTest { @Test public void verifyFindEapMethodFromNAIRealmMatchedWithCarrierWithMatch() { // static mocking - MockitoSession session = ExtendedMockito.mockitoSession().mockStatic( - TelephonyManager.class).mockStatic( - InformationElementUtil.class).startMocking(); + MockitoSession session = ExtendedMockito.mockitoSession() + .mockStatic(InformationElementUtil.class) + .startMocking(); try { - TelephonyManager telephonyManager = mock(TelephonyManager.class); - when(TelephonyManager.from(any(Context.class))).thenReturn(telephonyManager); - when(telephonyManager.getSimOperator()).thenReturn(TEST_MCC_MNC); + when(mTelephonyManager.createForSubscriptionId(anyInt())) + .thenReturn(mDataTelephonyManager); + when(mDataTelephonyManager.getSimOperator()).thenReturn(TEST_MCC_MNC); when(mWifiConfigManager.isSimPresent()).thenReturn(true); List<ScanDetail> scanDetails = new ArrayList<>(); scanDetails.add(generateScanDetail(TEST_SSID, TEST_BSSID_STRING, TEST_HESSID, @@ -1754,7 +1740,7 @@ public class PasspointManagerTest { PasspointManager passpointManager = new PasspointManager(mContext, mWifiInjector, mHandler, mWifiNative, mWifiKeyStore, mClock, mSimAccessor, mObjectFactory, - mWifiConfigManager, mWifiConfigStore, mWifiMetrics); + mWifiConfigManager, mWifiConfigStore, mWifiMetrics, mTelephonyManager); assertEquals(EAPConstants.EAP_AKA, passpointManager.findEapMethodFromNAIRealmMatchedWithCarrier(scanDetails)); } finally { @@ -1768,20 +1754,20 @@ public class PasspointManagerTest { @Test public void verifyFindEapMethodFromNAIRealmMatchedWithCarrierWithNoMatch() { // static mocking - MockitoSession session = ExtendedMockito.mockitoSession().mockStatic( - TelephonyManager.class).mockStatic( - InformationElementUtil.class).startMocking(); + MockitoSession session = ExtendedMockito.mockitoSession() + .mockStatic(InformationElementUtil.class) + .startMocking(); try { - TelephonyManager telephonyManager = mock(TelephonyManager.class); - when(TelephonyManager.from(any(Context.class))).thenReturn(telephonyManager); - when(telephonyManager.getSimOperator()).thenReturn(TEST_MCC_MNC); + when(mTelephonyManager.createForSubscriptionId(anyInt())) + .thenReturn(mDataTelephonyManager); + when(mDataTelephonyManager.getSimOperator()).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, mWifiInjector, mHandler, mWifiNative, mWifiKeyStore, mClock, mSimAccessor, mObjectFactory, - mWifiConfigManager, mWifiConfigStore, mWifiMetrics); + mWifiConfigManager, mWifiConfigStore, mWifiMetrics, mTelephonyManager); assertEquals(-1, passpointManager.findEapMethodFromNAIRealmMatchedWithCarrier(scanDetails)); 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 38a222f4d..f9d6a1c8d 100644 --- a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointNetworkEvaluatorTest.java +++ b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointNetworkEvaluatorTest.java @@ -83,6 +83,7 @@ public class PasspointNetworkEvaluatorTest { @Mock WifiConfigManager mWifiConfigManager; @Mock OnConnectableListener mOnConnectableListener; @Mock TelephonyManager mTelephonyManager; + @Mock TelephonyManager mDataTelephonyManager; @Mock CarrierNetworkConfig mCarrierNetworkConfig; @Mock WifiInjector mWifiInjector; LocalLog mLocalLog; @@ -150,9 +151,10 @@ public class PasspointNetworkEvaluatorTest { mEvaluator = new PasspointNetworkEvaluator(mPasspointManager, mWifiConfigManager, mLocalLog, mCarrierNetworkConfig, mWifiInjector); when(mWifiInjector.makeTelephonyManager()).thenReturn(mTelephonyManager); + when(mTelephonyManager.createForSubscriptionId(anyInt())).thenReturn(mDataTelephonyManager); when(mWifiConfigManager.isSimPresent()).thenReturn(true); - when(mTelephonyManager.getSimOperator()).thenReturn("123456"); - when(mTelephonyManager.getSimState()).thenReturn(TelephonyManager.SIM_STATE_READY); + when(mDataTelephonyManager.getSimOperator()).thenReturn("123456"); + when(mDataTelephonyManager.getSimState()).thenReturn(TelephonyManager.SIM_STATE_READY); } /** @@ -408,7 +410,7 @@ public class PasspointNetworkEvaluatorTest { Pair<PasspointProvider, PasspointMatch> homeProvider = Pair.create( testProvider, PasspointMatch.HomeProvider); String expectedAnonymousIdentity = TelephonyUtil.getAnonymousIdentityWith3GppRealm( - mTelephonyManager); + mTelephonyManager); when(mPasspointManager.matchProvider(any(ScanResult.class))).thenReturn(homeProvider); when(testProvider.isSimCredential()).thenReturn(true); when(mWifiConfigManager.isSimPresent()).thenReturn(true); @@ -470,11 +472,11 @@ public class PasspointNetworkEvaluatorTest { // Setup ScanDetail and match providers. List<ScanDetail> scanDetails = Arrays.asList(new ScanDetail[]{ generateScanDetail(TEST_SSID1, TEST_BSSID1)}); - when(mTelephonyManager.getSimState()).thenReturn(TelephonyManager.SIM_STATE_READY); + when(mDataTelephonyManager.getSimState()).thenReturn(TelephonyManager.SIM_STATE_READY); // MVNO carrier is enabled. - when(mTelephonyManager.getCarrierIdFromSimMccMnc()).thenReturn(1); - when(mTelephonyManager.getSimCarrierId()).thenReturn(20); + when(mDataTelephonyManager.getCarrierIdFromSimMccMnc()).thenReturn(1); + when(mDataTelephonyManager.getSimCarrierId()).thenReturn(20); when(mCarrierNetworkConfig.isCarrierEncryptionInfoAvailable()).thenReturn(true); when(mPasspointManager.hasCarrierProvider(anyString())).thenReturn(false); when(mPasspointManager.findEapMethodFromNAIRealmMatchedWithCarrier( @@ -495,8 +497,8 @@ public class PasspointNetworkEvaluatorTest { // Setup ScanDetail and match providers. List<ScanDetail> scanDetails = Arrays.asList(new ScanDetail[]{ generateScanDetail(TEST_SSID1, TEST_BSSID1)}); - when(mTelephonyManager.getSimState()).thenReturn(TelephonyManager.SIM_STATE_READY); - when(mTelephonyManager.getSimCarrierId()).thenReturn(20); + when(mDataTelephonyManager.getSimState()).thenReturn(TelephonyManager.SIM_STATE_READY); + when(mDataTelephonyManager.getSimCarrierId()).thenReturn(20); when(mCarrierNetworkConfig.isCarrierEncryptionInfoAvailable()).thenReturn(true); when(mPasspointManager.hasCarrierProvider(anyString())).thenReturn(false); when(mPasspointManager.findEapMethodFromNAIRealmMatchedWithCarrier( @@ -536,11 +538,11 @@ public class PasspointNetworkEvaluatorTest { // Setup ScanDetail List<ScanDetail> scanDetails = Arrays.asList(new ScanDetail[]{ generateScanDetail(TEST_SSID1, TEST_BSSID1)}); - when(mTelephonyManager.getSimState()).thenReturn(TelephonyManager.SIM_STATE_READY); + when(mDataTelephonyManager.getSimState()).thenReturn(TelephonyManager.SIM_STATE_READY); // MNO carrier is enabled. - when(mTelephonyManager.getCarrierIdFromSimMccMnc()).thenReturn(1); - when(mTelephonyManager.getSimCarrierId()).thenReturn(1); + when(mDataTelephonyManager.getCarrierIdFromSimMccMnc()).thenReturn(1); + when(mDataTelephonyManager.getSimCarrierId()).thenReturn(1); when(mCarrierNetworkConfig.isCarrierEncryptionInfoAvailable()).thenReturn(true); when(mPasspointManager.hasCarrierProvider(anyString())).thenReturn(false); when(mPasspointManager.findEapMethodFromNAIRealmMatchedWithCarrier( @@ -563,11 +565,11 @@ public class PasspointNetworkEvaluatorTest { // Setup ScanDetail List<ScanDetail> scanDetails = Arrays.asList(new ScanDetail[]{ generateScanDetail(TEST_SSID1, TEST_BSSID1)}); - when(mTelephonyManager.getSimState()).thenReturn(TelephonyManager.SIM_STATE_READY); + when(mDataTelephonyManager.getSimState()).thenReturn(TelephonyManager.SIM_STATE_READY); // MNO carrier is enabled. - when(mTelephonyManager.getCarrierIdFromSimMccMnc()).thenReturn(1); - when(mTelephonyManager.getSimCarrierId()).thenReturn(1); + when(mDataTelephonyManager.getCarrierIdFromSimMccMnc()).thenReturn(1); + when(mDataTelephonyManager.getSimCarrierId()).thenReturn(1); when(mCarrierNetworkConfig.isCarrierEncryptionInfoAvailable()).thenReturn(true); when(mPasspointManager.hasCarrierProvider(anyString())).thenReturn(false); when(mPasspointManager.findEapMethodFromNAIRealmMatchedWithCarrier( diff --git a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointProvisionerTest.java b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointProvisionerTest.java index 7be5344a3..10ce65067 100644 --- a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointProvisionerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointProvisionerTest.java @@ -185,6 +185,7 @@ public class PasspointProvisionerTest { @Mock ExchangeCompleteMessage mExchangeCompleteMessage; @Mock SystemInfo mSystemInfo; @Mock TelephonyManager mTelephonyManager; + @Mock TelephonyManager mDataTelephonyManager; @Mock SppCommand mSppCommand; @Mock BrowserUri mBrowserUri; @Mock PpsMoData mPpsMoData; @@ -230,7 +231,8 @@ public class PasspointProvisionerTest { mOsuProvider = PasspointProvisioningTestUtil.generateOsuProvider(true); mDelegate = new TrustManagerImpl(PasspointProvisioningTestUtil.createFakeKeyStore()); when(mObjectFactory.getTrustManagerImpl(any(KeyStore.class))).thenReturn(mDelegate); - when(mContext.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn(mTelephonyManager); + when(mContext.getSystemService(TelephonyManager.class)).thenReturn(mTelephonyManager); + when(mTelephonyManager.createForSubscriptionId(anyInt())).thenReturn(mDataTelephonyManager); when(mSystemInfo.getDeviceModel()).thenReturn(TEST_MODEL); when(mSystemInfo.getLanguage()).thenReturn(TEST_LANGUAGE); when(mSystemInfo.getDeviceId()).thenReturn(TEST_DEV_ID); @@ -239,7 +241,7 @@ public class PasspointProvisionerTest { when(mSystemInfo.getMacAddress(any(String.class))).thenReturn(TEST_MAC_ADDR); when(mSystemInfo.getSoftwareVersion()).thenReturn(TEST_SW_VERSION); when(mSystemInfo.getFirmwareVersion()).thenReturn(TEST_FW_VERSION); - when(mTelephonyManager.getSubscriberId()).thenReturn(TEST_IMSI); + when(mDataTelephonyManager.getSubscriberId()).thenReturn(TEST_IMSI); when(mExchangeCompleteMessage.getMessageType()).thenReturn( SppResponseMessage.MessageType.EXCHANGE_COMPLETE); diff --git a/tests/wifitests/src/com/android/server/wifi/hotspot2/SystemInfoTest.java b/tests/wifitests/src/com/android/server/wifi/hotspot2/SystemInfoTest.java index 2de746e57..62d7b503f 100644 --- a/tests/wifitests/src/com/android/server/wifi/hotspot2/SystemInfoTest.java +++ b/tests/wifitests/src/com/android/server/wifi/hotspot2/SystemInfoTest.java @@ -18,6 +18,7 @@ package com.android.server.wifi.hotspot2; import static org.junit.Assert.assertEquals; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; @@ -39,6 +40,7 @@ import org.mockito.Mock; public class SystemInfoTest { @Mock Context mContext; @Mock TelephonyManager mTelephonyManager; + @Mock TelephonyManager mDataTelephonyManager; @Mock WifiNative mWifiNative; SystemInfo mSystemInfo; @@ -49,6 +51,7 @@ public class SystemInfoTest { public void setUp() throws Exception { initMocks(this); when(mContext.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn(mTelephonyManager); + when(mTelephonyManager.createForSubscriptionId(anyInt())).thenReturn(mDataTelephonyManager); mSystemInfo = new SystemInfo(mContext, mWifiNative); } @@ -58,7 +61,7 @@ public class SystemInfoTest { @Test public void getDeviceIdWithImei() { String imei = "123456"; - when(mTelephonyManager.getImei()).thenReturn(imei); + when(mDataTelephonyManager.getImei()).thenReturn(imei); assertEquals(imei, mSystemInfo.getDeviceId()); } @@ -68,8 +71,8 @@ public class SystemInfoTest { @Test public void getDeviceIdWithMeid() { String meid = "098763"; - when(mTelephonyManager.getImei()).thenReturn(null); - when(mTelephonyManager.getMeid()).thenReturn(meid); + when(mDataTelephonyManager.getImei()).thenReturn(null); + when(mDataTelephonyManager.getMeid()).thenReturn(meid); assertEquals(meid, mSystemInfo.getDeviceId()); } @@ -79,8 +82,8 @@ public class SystemInfoTest { */ @Test public void getDeviceIdWithoutSim() { - when(mTelephonyManager.getImei()).thenReturn(null); - when(mTelephonyManager.getMeid()).thenReturn(null); + when(mDataTelephonyManager.getImei()).thenReturn(null); + when(mDataTelephonyManager.getMeid()).thenReturn(null); assertEquals(SystemInfo.UNKNOWN_INFO, mSystemInfo.getDeviceId()); } diff --git a/tests/wifitests/src/com/android/server/wifi/hotspot2/omadm/DevDetailMoTest.java b/tests/wifitests/src/com/android/server/wifi/hotspot2/omadm/DevDetailMoTest.java index 44abf7fa6..f54e360d0 100644 --- a/tests/wifitests/src/com/android/server/wifi/hotspot2/omadm/DevDetailMoTest.java +++ b/tests/wifitests/src/com/android/server/wifi/hotspot2/omadm/DevDetailMoTest.java @@ -20,6 +20,7 @@ import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertNull; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; @@ -56,20 +57,23 @@ public class DevDetailMoTest { private Context mContext; @Mock private TelephonyManager mTelephonyManager; + @Mock + private TelephonyManager mDataTelephonyManager; /** * Sets up test. */ @Before public void setUp() throws Exception { initMocks(this); - when(mContext.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn(mTelephonyManager); + when(mContext.getSystemService(TelephonyManager.class)).thenReturn(mTelephonyManager); + when(mTelephonyManager.createForSubscriptionId(anyInt())).thenReturn(mDataTelephonyManager); when(mSystemInfo.getDeviceId()).thenReturn(TEST_DEV_ID); when(mSystemInfo.getDeviceManufacturer()).thenReturn(TEST_MANUFACTURER); when(mSystemInfo.getHwVersion()).thenReturn(TEST_HW_VERSION); when(mSystemInfo.getMacAddress(any(String.class))).thenReturn(TEST_MAC_ADDR); when(mSystemInfo.getSoftwareVersion()).thenReturn(TEST_SW_VERSION); when(mSystemInfo.getFirmwareVersion()).thenReturn(TEST_FW_VERSION); - when(mTelephonyManager.getSubscriberId()).thenReturn(TEST_IMSI); + when(mDataTelephonyManager.getSubscriberId()).thenReturn(TEST_IMSI); DevDetailMo.setAllowToSendImsiImeiInfo(false); } @@ -230,7 +234,7 @@ public class DevDetailMoTest { @Test public void serializeDevDetailMoWithoutSim() { DevDetailMo.setAllowToSendImsiImeiInfo(true); - when(mTelephonyManager.getSubscriberId()).thenReturn(null); + when(mDataTelephonyManager.getSubscriberId()).thenReturn(null); String expected = String.format("<MgmtTree>" + "<VerDTD>%s</VerDTD>" + "<Node><NodeName>DevDetail</NodeName>" diff --git a/tests/wifitests/src/com/android/server/wifi/hotspot2/soap/PostDevDataMessageTest.java b/tests/wifitests/src/com/android/server/wifi/hotspot2/soap/PostDevDataMessageTest.java index 2f1afd7dd..7fe03e124 100644 --- a/tests/wifitests/src/com/android/server/wifi/hotspot2/soap/PostDevDataMessageTest.java +++ b/tests/wifitests/src/com/android/server/wifi/hotspot2/soap/PostDevDataMessageTest.java @@ -21,6 +21,7 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; @@ -68,6 +69,8 @@ public class PostDevDataMessageTest { private Context mContext; @Mock private TelephonyManager mTelephonyManager; + @Mock + private TelephonyManager mDataTelephonyManager; /** * Sets up test. @@ -75,7 +78,8 @@ public class PostDevDataMessageTest { @Before public void setUp() throws Exception { initMocks(this); - when(mContext.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn(mTelephonyManager); + when(mContext.getSystemService(TelephonyManager.class)).thenReturn(mTelephonyManager); + when(mTelephonyManager.createForSubscriptionId(anyInt())).thenReturn(mDataTelephonyManager); when(mSystemInfo.getDeviceModel()).thenReturn(TEST_MODEL); when(mSystemInfo.getLanguage()).thenReturn(TEST_LANGUAGE); @@ -85,7 +89,7 @@ public class PostDevDataMessageTest { when(mSystemInfo.getMacAddress(any(String.class))).thenReturn(TEST_MAC_ADDR); when(mSystemInfo.getSoftwareVersion()).thenReturn(TEST_SW_VERSION); when(mSystemInfo.getFirmwareVersion()).thenReturn(TEST_FW_VERSION); - when(mTelephonyManager.getSubscriberId()).thenReturn(TEST_IMSI); + when(mDataTelephonyManager.getSubscriberId()).thenReturn(TEST_IMSI); } /** @@ -152,4 +156,4 @@ public class PostDevDataMessageTest { request.getAttribute(SppConstants.ATTRIBUTE_REQUEST_REASON)); assertEquals(TEST_REDIRECT_URL, request.getAttribute(SppConstants.ATTRIBUTE_REDIRECT_URI)); } -}
\ No newline at end of file +} 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 0c0b76fa3..490cdfef2 100644 --- a/tests/wifitests/src/com/android/server/wifi/util/TelephonyUtilTest.java +++ b/tests/wifitests/src/com/android/server/wifi/util/TelephonyUtilTest.java @@ -56,6 +56,10 @@ public class TelephonyUtilTest { @Mock CarrierNetworkConfig mCarrierNetworkConfig; + @Mock + TelephonyManager mTelephonyManager; + @Mock + TelephonyManager mDataTelephonyManager; @Before public void setUp() throws Exception { @@ -64,64 +68,68 @@ public class TelephonyUtilTest { when(mCarrierNetworkConfig.getEapIdentitySequence()).thenReturn( IDENTITY_SEQUENCE_IMSI_V1_0); mTelephonyUtil = new TelephonyUtil(); + when(mTelephonyManager.createForSubscriptionId(anyInt())).thenReturn(mDataTelephonyManager); } @Test public void getSimIdentityEapSim() { - TelephonyManager tm = mock(TelephonyManager.class); final Pair<String, String> expectedIdentity = Pair.create( "13214561234567890@wlan.mnc456.mcc321.3gppnetwork.org", ""); - when(tm.getSubscriberId()).thenReturn("3214561234567890"); - when(tm.getSimState()).thenReturn(TelephonyManager.SIM_STATE_READY); - when(tm.getSimOperator()).thenReturn("321456"); - when(tm.getCarrierInfoForImsiEncryption(anyInt())).thenReturn(null); + when(mDataTelephonyManager.getSubscriberId()).thenReturn("3214561234567890"); + when(mDataTelephonyManager.getSimState()).thenReturn(TelephonyManager.SIM_STATE_READY); + when(mDataTelephonyManager.getSimOperator()).thenReturn("321456"); + when(mDataTelephonyManager.getCarrierInfoForImsiEncryption(anyInt())).thenReturn(null); - assertEquals(expectedIdentity, TelephonyUtil.getSimIdentity(tm, mTelephonyUtil, + assertEquals(expectedIdentity, TelephonyUtil.getSimIdentity(mTelephonyManager, + mTelephonyUtil, WifiConfigurationTestUtil.createEapNetwork(WifiEnterpriseConfig.Eap.SIM, WifiEnterpriseConfig.Phase2.NONE), mCarrierNetworkConfig)); - assertEquals(expectedIdentity, TelephonyUtil.getSimIdentity(tm, mTelephonyUtil, - WifiConfigurationTestUtil.createEapNetwork(WifiEnterpriseConfig.Eap.PEAP, - WifiEnterpriseConfig.Phase2.SIM), mCarrierNetworkConfig)); + assertEquals(expectedIdentity, + TelephonyUtil.getSimIdentity(mTelephonyManager, mTelephonyUtil, + WifiConfigurationTestUtil.createEapNetwork(WifiEnterpriseConfig.Eap.PEAP, + WifiEnterpriseConfig.Phase2.SIM), mCarrierNetworkConfig)); } @Test public void getSimIdentityEapAka() { - TelephonyManager tm = mock(TelephonyManager.class); final Pair<String, String> expectedIdentity = Pair.create( "03214561234567890@wlan.mnc456.mcc321.3gppnetwork.org", ""); - when(tm.getSubscriberId()).thenReturn("3214561234567890"); + when(mDataTelephonyManager.getSubscriberId()).thenReturn("3214561234567890"); - when(tm.getSimState()).thenReturn(TelephonyManager.SIM_STATE_READY); - when(tm.getSimOperator()).thenReturn("321456"); - when(tm.getCarrierInfoForImsiEncryption(anyInt())).thenReturn(null); + when(mDataTelephonyManager.getSimState()).thenReturn(TelephonyManager.SIM_STATE_READY); + when(mDataTelephonyManager.getSimOperator()).thenReturn("321456"); + when(mDataTelephonyManager.getCarrierInfoForImsiEncryption(anyInt())).thenReturn(null); - assertEquals(expectedIdentity, TelephonyUtil.getSimIdentity(tm, mTelephonyUtil, - WifiConfigurationTestUtil.createEapNetwork(WifiEnterpriseConfig.Eap.AKA, - WifiEnterpriseConfig.Phase2.NONE), mCarrierNetworkConfig)); - assertEquals(expectedIdentity, TelephonyUtil.getSimIdentity(tm, mTelephonyUtil, - WifiConfigurationTestUtil.createEapNetwork(WifiEnterpriseConfig.Eap.PEAP, - WifiEnterpriseConfig.Phase2.AKA), mCarrierNetworkConfig)); + assertEquals(expectedIdentity, + TelephonyUtil.getSimIdentity(mTelephonyManager, mTelephonyUtil, + WifiConfigurationTestUtil.createEapNetwork(WifiEnterpriseConfig.Eap.AKA, + WifiEnterpriseConfig.Phase2.NONE), mCarrierNetworkConfig)); + assertEquals(expectedIdentity, + TelephonyUtil.getSimIdentity(mTelephonyManager, mTelephonyUtil, + WifiConfigurationTestUtil.createEapNetwork(WifiEnterpriseConfig.Eap.PEAP, + WifiEnterpriseConfig.Phase2.AKA), mCarrierNetworkConfig)); } @Test public void getSimIdentityEapAkaPrime() { - TelephonyManager tm = mock(TelephonyManager.class); final Pair<String, String> expectedIdentity = Pair.create( "63214561234567890@wlan.mnc456.mcc321.3gppnetwork.org", ""); - when(tm.getSubscriberId()).thenReturn("3214561234567890"); - when(tm.getSimState()).thenReturn(TelephonyManager.SIM_STATE_READY); - when(tm.getSimOperator()).thenReturn("321456"); - when(tm.getCarrierInfoForImsiEncryption(anyInt())).thenReturn(null); + when(mDataTelephonyManager.getSubscriberId()).thenReturn("3214561234567890"); + when(mDataTelephonyManager.getSimState()).thenReturn(TelephonyManager.SIM_STATE_READY); + when(mDataTelephonyManager.getSimOperator()).thenReturn("321456"); + when(mDataTelephonyManager.getCarrierInfoForImsiEncryption(anyInt())).thenReturn(null); - assertEquals(expectedIdentity, TelephonyUtil.getSimIdentity(tm, mTelephonyUtil, - WifiConfigurationTestUtil.createEapNetwork( - WifiEnterpriseConfig.Eap.AKA_PRIME, - WifiEnterpriseConfig.Phase2.NONE), mCarrierNetworkConfig)); - assertEquals(expectedIdentity, TelephonyUtil.getSimIdentity(tm, mTelephonyUtil, - WifiConfigurationTestUtil.createEapNetwork(WifiEnterpriseConfig.Eap.PEAP, - WifiEnterpriseConfig.Phase2.AKA_PRIME), mCarrierNetworkConfig)); + assertEquals(expectedIdentity, + TelephonyUtil.getSimIdentity(mTelephonyManager, mTelephonyUtil, + WifiConfigurationTestUtil.createEapNetwork( + WifiEnterpriseConfig.Eap.AKA_PRIME, + WifiEnterpriseConfig.Phase2.NONE), mCarrierNetworkConfig)); + assertEquals(expectedIdentity, + TelephonyUtil.getSimIdentity(mTelephonyManager, mTelephonyUtil, + WifiConfigurationTestUtil.createEapNetwork(WifiEnterpriseConfig.Eap.PEAP, + WifiEnterpriseConfig.Phase2.AKA_PRIME), mCarrierNetworkConfig)); } /** @@ -130,7 +138,6 @@ public class TelephonyUtilTest { */ @Test public void getEncryptedIdentity_V_1_0_WithRfc4648() throws Exception { - TelephonyManager tm = mock(TelephonyManager.class); Cipher cipher = mock(Cipher.class); PublicKey key = null; int flag = Base64.NO_WRAP; @@ -147,18 +154,20 @@ public class TelephonyUtilTest { try { when(Cipher.getInstance(anyString())).thenReturn(cipher); when(cipher.doFinal(any(byte[].class))).thenReturn(imsi.getBytes()); - when(tm.getSubscriberId()).thenReturn(imsi); - when(tm.getSimState()).thenReturn(TelephonyManager.SIM_STATE_READY); - when(tm.getSimOperator()).thenReturn("321456"); + when(mDataTelephonyManager.getSubscriberId()).thenReturn(imsi); + when(mDataTelephonyManager.getSimState()).thenReturn(TelephonyManager.SIM_STATE_READY); + when(mDataTelephonyManager.getSimOperator()).thenReturn("321456"); ImsiEncryptionInfo info = new ImsiEncryptionInfo("321", "456", TelephonyManager.KEY_TYPE_WLAN, null, key, null); - when(tm.getCarrierInfoForImsiEncryption(eq(TelephonyManager.KEY_TYPE_WLAN))) + when(mDataTelephonyManager.getCarrierInfoForImsiEncryption( + eq(TelephonyManager.KEY_TYPE_WLAN))) .thenReturn(info); when(mCarrierNetworkConfig.getBase64EncodingFlag()).thenReturn(flag); - assertEquals(expectedIdentity, TelephonyUtil.getSimIdentity(tm, mTelephonyUtil, - WifiConfigurationTestUtil.createEapNetwork(WifiEnterpriseConfig.Eap.AKA, - WifiEnterpriseConfig.Phase2.NONE), mCarrierNetworkConfig)); + assertEquals(expectedIdentity, + TelephonyUtil.getSimIdentity(mTelephonyManager, mTelephonyUtil, + WifiConfigurationTestUtil.createEapNetwork(WifiEnterpriseConfig.Eap.AKA, + WifiEnterpriseConfig.Phase2.NONE), mCarrierNetworkConfig)); } finally { session.finishMocking(); } @@ -170,7 +179,6 @@ public class TelephonyUtilTest { */ @Test public void getEncryptedIdentity_V_1_6_WithRfc4648() throws Exception { - TelephonyManager tm = mock(TelephonyManager.class); Cipher cipher = mock(Cipher.class); PublicKey key = null; int flag = Base64.NO_WRAP; @@ -188,20 +196,22 @@ public class TelephonyUtilTest { try { when(Cipher.getInstance(anyString())).thenReturn(cipher); when(cipher.doFinal(any(byte[].class))).thenReturn(permanentIdentity.getBytes()); - when(tm.getSubscriberId()).thenReturn(imsi); - when(tm.getSimState()).thenReturn(TelephonyManager.SIM_STATE_READY); - when(tm.getSimOperator()).thenReturn("321456"); + when(mDataTelephonyManager.getSubscriberId()).thenReturn(imsi); + when(mDataTelephonyManager.getSimState()).thenReturn(TelephonyManager.SIM_STATE_READY); + when(mDataTelephonyManager.getSimOperator()).thenReturn("321456"); ImsiEncryptionInfo info = new ImsiEncryptionInfo("321", "456", TelephonyManager.KEY_TYPE_WLAN, null, key, null); - when(tm.getCarrierInfoForImsiEncryption(eq(TelephonyManager.KEY_TYPE_WLAN))) + when(mDataTelephonyManager.getCarrierInfoForImsiEncryption( + eq(TelephonyManager.KEY_TYPE_WLAN))) .thenReturn(info); when(mCarrierNetworkConfig.getBase64EncodingFlag()).thenReturn(flag); when(mCarrierNetworkConfig.getEapIdentitySequence()).thenReturn( CarrierNetworkConfig.IDENTITY_SEQUENCE_ANONYMOUS_THEN_IMSI_V1_6); - assertEquals(expectedIdentity, TelephonyUtil.getSimIdentity(tm, mTelephonyUtil, - WifiConfigurationTestUtil.createEapNetwork(WifiEnterpriseConfig.Eap.AKA, - WifiEnterpriseConfig.Phase2.NONE), mCarrierNetworkConfig)); + assertEquals(expectedIdentity, + TelephonyUtil.getSimIdentity(mTelephonyManager, mTelephonyUtil, + WifiConfigurationTestUtil.createEapNetwork(WifiEnterpriseConfig.Eap.AKA, + WifiEnterpriseConfig.Phase2.NONE), mCarrierNetworkConfig)); } finally { session.finishMocking(); } @@ -213,7 +223,6 @@ public class TelephonyUtilTest { */ @Test public void getEncryptedIdentityKeyIdentifierWithRfc2045() throws Exception { - TelephonyManager tm = mock(TelephonyManager.class); Cipher cipher = mock(Cipher.class); int flag = Base64.DEFAULT; PublicKey key = null; @@ -232,18 +241,20 @@ public class TelephonyUtilTest { try { when(Cipher.getInstance(anyString())).thenReturn(cipher); when(cipher.doFinal(any(byte[].class))).thenReturn(imsi.getBytes()); - when(tm.getSubscriberId()).thenReturn(imsi); - when(tm.getSimState()).thenReturn(TelephonyManager.SIM_STATE_READY); - when(tm.getSimOperator()).thenReturn("321456"); + when(mDataTelephonyManager.getSubscriberId()).thenReturn(imsi); + when(mDataTelephonyManager.getSimState()).thenReturn(TelephonyManager.SIM_STATE_READY); + when(mDataTelephonyManager.getSimOperator()).thenReturn("321456"); ImsiEncryptionInfo info = new ImsiEncryptionInfo("321", "456", TelephonyManager.KEY_TYPE_WLAN, keyIdentifier, key, null); - when(tm.getCarrierInfoForImsiEncryption(eq(TelephonyManager.KEY_TYPE_WLAN))) + when(mDataTelephonyManager.getCarrierInfoForImsiEncryption( + eq(TelephonyManager.KEY_TYPE_WLAN))) .thenReturn(info); when(mCarrierNetworkConfig.getBase64EncodingFlag()).thenReturn(flag); - assertEquals(expectedIdentity, TelephonyUtil.getSimIdentity(tm, mTelephonyUtil, - WifiConfigurationTestUtil.createEapNetwork(WifiEnterpriseConfig.Eap.AKA, - WifiEnterpriseConfig.Phase2.NONE), mCarrierNetworkConfig)); + assertEquals(expectedIdentity, + TelephonyUtil.getSimIdentity(mTelephonyManager, mTelephonyUtil, + WifiConfigurationTestUtil.createEapNetwork(WifiEnterpriseConfig.Eap.AKA, + WifiEnterpriseConfig.Phase2.NONE), mCarrierNetworkConfig)); } finally { session.finishMocking(); } @@ -256,7 +267,6 @@ public class TelephonyUtilTest { */ @Test public void getEncryptedIdentityFailed() throws Exception { - TelephonyManager tm = mock(TelephonyManager.class); Cipher cipher = mock(Cipher.class); String keyIdentifier = "key=testKey"; String imsi = "3214561234567890"; @@ -266,15 +276,16 @@ public class TelephonyUtilTest { try { when(Cipher.getInstance(anyString())).thenReturn(cipher); when(cipher.doFinal(any(byte[].class))).thenThrow(BadPaddingException.class); - when(tm.getSubscriberId()).thenReturn(imsi); - when(tm.getSimState()).thenReturn(TelephonyManager.SIM_STATE_READY); - when(tm.getSimOperator()).thenReturn("321456"); + when(mDataTelephonyManager.getSubscriberId()).thenReturn(imsi); + when(mDataTelephonyManager.getSimState()).thenReturn(TelephonyManager.SIM_STATE_READY); + when(mDataTelephonyManager.getSimOperator()).thenReturn("321456"); ImsiEncryptionInfo info = new ImsiEncryptionInfo("321", "456", TelephonyManager.KEY_TYPE_WLAN, keyIdentifier, (PublicKey) null, null); - when(tm.getCarrierInfoForImsiEncryption(eq(TelephonyManager.KEY_TYPE_WLAN))) + when(mDataTelephonyManager.getCarrierInfoForImsiEncryption( + eq(TelephonyManager.KEY_TYPE_WLAN))) .thenReturn(info); - assertNull(TelephonyUtil.getSimIdentity(tm, mTelephonyUtil, + assertNull(TelephonyUtil.getSimIdentity(mTelephonyManager, mTelephonyUtil, WifiConfigurationTestUtil.createEapNetwork(WifiEnterpriseConfig.Eap.AKA, WifiEnterpriseConfig.Phase2.NONE), mCarrierNetworkConfig)); } finally { @@ -288,54 +299,54 @@ public class TelephonyUtilTest { */ @Test public void getEncryptedIdentityFailedWithInvalidEapIdentitySequence() throws Exception { - TelephonyManager tm = mock(TelephonyManager.class); final Pair<String, String> expectedIdentity = Pair.create( "03214561234567890@wlan.mnc456.mcc321.3gppnetwork.org", ""); - when(tm.getSubscriberId()).thenReturn("3214561234567890"); - when(tm.getSimState()).thenReturn(TelephonyManager.SIM_STATE_READY); - when(tm.getSimOperator()).thenReturn("321456"); + when(mDataTelephonyManager.getSubscriberId()).thenReturn("3214561234567890"); + when(mDataTelephonyManager.getSimState()).thenReturn(TelephonyManager.SIM_STATE_READY); + when(mDataTelephonyManager.getSimOperator()).thenReturn("321456"); ImsiEncryptionInfo info = new ImsiEncryptionInfo("321", "456", TelephonyManager.KEY_TYPE_WLAN, null, (PublicKey) null, null); - when(tm.getCarrierInfoForImsiEncryption(eq(TelephonyManager.KEY_TYPE_WLAN))) + when(mDataTelephonyManager.getCarrierInfoForImsiEncryption( + eq(TelephonyManager.KEY_TYPE_WLAN))) .thenReturn(info); when(mCarrierNetworkConfig.getEapIdentitySequence()).thenReturn(-1); - assertNull(TelephonyUtil.getSimIdentity(tm, mTelephonyUtil, + assertNull(TelephonyUtil.getSimIdentity(mTelephonyManager, mTelephonyUtil, WifiConfigurationTestUtil.createEapNetwork(WifiEnterpriseConfig.Eap.AKA, WifiEnterpriseConfig.Phase2.NONE), mCarrierNetworkConfig)); } @Test public void getSimIdentity2DigitMnc() { - TelephonyManager tm = mock(TelephonyManager.class); final Pair<String, String> expectedIdentity = Pair.create( "1321560123456789@wlan.mnc056.mcc321.3gppnetwork.org", ""); - when(tm.getSubscriberId()).thenReturn("321560123456789"); - when(tm.getSimState()).thenReturn(TelephonyManager.SIM_STATE_READY); - when(tm.getSimOperator()).thenReturn("32156"); - when(tm.getCarrierInfoForImsiEncryption(anyInt())).thenReturn(null); + when(mDataTelephonyManager.getSubscriberId()).thenReturn("321560123456789"); + when(mDataTelephonyManager.getSimState()).thenReturn(TelephonyManager.SIM_STATE_READY); + when(mDataTelephonyManager.getSimOperator()).thenReturn("32156"); + when(mDataTelephonyManager.getCarrierInfoForImsiEncryption(anyInt())).thenReturn(null); - assertEquals(expectedIdentity, TelephonyUtil.getSimIdentity(tm, mTelephonyUtil, - WifiConfigurationTestUtil.createEapNetwork(WifiEnterpriseConfig.Eap.SIM, - WifiEnterpriseConfig.Phase2.NONE), mCarrierNetworkConfig)); + assertEquals(expectedIdentity, + TelephonyUtil.getSimIdentity(mTelephonyManager, mTelephonyUtil, + WifiConfigurationTestUtil.createEapNetwork(WifiEnterpriseConfig.Eap.SIM, + WifiEnterpriseConfig.Phase2.NONE), mCarrierNetworkConfig)); } @Test public void getSimIdentityUnknownMccMnc() { - TelephonyManager tm = mock(TelephonyManager.class); final Pair<String, String> expectedIdentity = Pair.create( "13214560123456789@wlan.mnc456.mcc321.3gppnetwork.org", ""); - when(tm.getSubscriberId()).thenReturn("3214560123456789"); - when(tm.getSimState()).thenReturn(TelephonyManager.SIM_STATE_UNKNOWN); - when(tm.getSimOperator()).thenReturn(null); - when(tm.getCarrierInfoForImsiEncryption(anyInt())).thenReturn(null); + when(mDataTelephonyManager.getSubscriberId()).thenReturn("3214560123456789"); + when(mDataTelephonyManager.getSimState()).thenReturn(TelephonyManager.SIM_STATE_UNKNOWN); + when(mDataTelephonyManager.getSimOperator()).thenReturn(null); + when(mDataTelephonyManager.getCarrierInfoForImsiEncryption(anyInt())).thenReturn(null); - assertEquals(expectedIdentity, TelephonyUtil.getSimIdentity(tm, mTelephonyUtil, - WifiConfigurationTestUtil.createEapNetwork(WifiEnterpriseConfig.Eap.SIM, - WifiEnterpriseConfig.Phase2.NONE), mCarrierNetworkConfig)); + assertEquals(expectedIdentity, + TelephonyUtil.getSimIdentity(mTelephonyManager, mTelephonyUtil, + WifiConfigurationTestUtil.createEapNetwork(WifiEnterpriseConfig.Eap.SIM, + WifiEnterpriseConfig.Phase2.NONE), mCarrierNetworkConfig)); } @Test @@ -348,24 +359,23 @@ public class TelephonyUtilTest { @Test public void getSimIdentityNonTelephonyConfig() { - TelephonyManager tm = mock(TelephonyManager.class); - when(tm.getSubscriberId()).thenReturn("321560123456789"); - when(tm.getSimState()).thenReturn(TelephonyManager.SIM_STATE_READY); - when(tm.getSimOperator()).thenReturn("32156"); - assertEquals(null, TelephonyUtil.getSimIdentity(tm, mTelephonyUtil, + when(mDataTelephonyManager.getSubscriberId()).thenReturn("321560123456789"); + when(mDataTelephonyManager.getSimState()).thenReturn(TelephonyManager.SIM_STATE_READY); + when(mDataTelephonyManager.getSimOperator()).thenReturn("32156"); + assertEquals(null, TelephonyUtil.getSimIdentity(mTelephonyManager, mTelephonyUtil, WifiConfigurationTestUtil.createEapNetwork( WifiEnterpriseConfig.Eap.TTLS, WifiEnterpriseConfig.Phase2.SIM), mCarrierNetworkConfig)); - assertEquals(null, TelephonyUtil.getSimIdentity(tm, mTelephonyUtil, + assertEquals(null, TelephonyUtil.getSimIdentity(mTelephonyManager, mTelephonyUtil, WifiConfigurationTestUtil.createEapNetwork( WifiEnterpriseConfig.Eap.PEAP, WifiEnterpriseConfig.Phase2.MSCHAPV2), mCarrierNetworkConfig)); - assertEquals(null, TelephonyUtil.getSimIdentity(tm, mTelephonyUtil, + assertEquals(null, TelephonyUtil.getSimIdentity(mTelephonyManager, mTelephonyUtil, WifiConfigurationTestUtil.createEapNetwork( WifiEnterpriseConfig.Eap.TLS, WifiEnterpriseConfig.Phase2.NONE), mCarrierNetworkConfig)); assertEquals(null, TelephonyUtil.getSimIdentity( - tm, mTelephonyUtil, new WifiConfiguration(), mCarrierNetworkConfig)); + mTelephonyManager, mTelephonyUtil, new WifiConfiguration(), mCarrierNetworkConfig)); } @Test @@ -450,100 +460,95 @@ public class TelephonyUtilTest { @Test public void getGsmSimAuthResponseInvalidRequest() { - TelephonyManager tm = mock(TelephonyManager.class); final String[] invalidRequests = { null, "", "XXXX" }; - assertEquals("", TelephonyUtil.getGsmSimAuthResponse(invalidRequests, tm)); + assertEquals("", TelephonyUtil.getGsmSimAuthResponse(invalidRequests, mTelephonyManager)); } @Test public void getGsmSimAuthResponseFailedSimResponse() { - TelephonyManager tm = mock(TelephonyManager.class); final String[] failedRequests = { "5E5F" }; - when(tm.getIccAuthentication(anyInt(), anyInt(), + when(mDataTelephonyManager.getIccAuthentication(anyInt(), anyInt(), eq(createSimChallengeRequest(new byte[] { 0x5e, 0x5f })))).thenReturn(null); - assertEquals(null, TelephonyUtil.getGsmSimAuthResponse(failedRequests, tm)); + assertEquals(null, TelephonyUtil.getGsmSimAuthResponse(failedRequests, mTelephonyManager)); } @Test public void getGsmSimAuthResponseUsim() { - TelephonyManager tm = mock(TelephonyManager.class); - when(tm.getIccAuthentication(TelephonyManager.APPTYPE_USIM, + when(mDataTelephonyManager.getIccAuthentication(TelephonyManager.APPTYPE_USIM, TelephonyManager.AUTHTYPE_EAP_SIM, createSimChallengeRequest(new byte[] { 0x1b, 0x2b }))) .thenReturn(createGsmSimAuthResponse(new byte[] { 0x1D, 0x2C }, new byte[] { 0x3B, 0x4A })); - when(tm.getIccAuthentication(TelephonyManager.APPTYPE_USIM, + when(mDataTelephonyManager.getIccAuthentication(TelephonyManager.APPTYPE_USIM, TelephonyManager.AUTHTYPE_EAP_SIM, createSimChallengeRequest(new byte[] { 0x01, 0x22 }))) .thenReturn(createGsmSimAuthResponse(new byte[] { 0x11, 0x11 }, new byte[] { 0x12, 0x34 })); assertEquals(":3b4a:1d2c:1234:1111", TelephonyUtil.getGsmSimAuthResponse( - new String[] { "1B2B", "0122" }, tm)); + new String[] { "1B2B", "0122" }, mTelephonyManager)); } @Test public void getGsmSimpleSimAuthResponseInvalidRequest() { - TelephonyManager tm = mock(TelephonyManager.class); final String[] invalidRequests = { null, "", "XXXX" }; - assertEquals("", TelephonyUtil.getGsmSimpleSimAuthResponse(invalidRequests, tm)); + assertEquals("", + TelephonyUtil.getGsmSimpleSimAuthResponse(invalidRequests, mTelephonyManager)); } @Test public void getGsmSimpleSimAuthResponseFailedSimResponse() { - TelephonyManager tm = mock(TelephonyManager.class); final String[] failedRequests = { "5E5F" }; - when(tm.getIccAuthentication(anyInt(), anyInt(), + when(mDataTelephonyManager.getIccAuthentication(anyInt(), anyInt(), eq(createSimChallengeRequest(new byte[] { 0x5e, 0x5f })))).thenReturn(null); - assertEquals(null, TelephonyUtil.getGsmSimpleSimAuthResponse(failedRequests, tm)); + assertEquals(null, + TelephonyUtil.getGsmSimpleSimAuthResponse(failedRequests, mTelephonyManager)); } @Test public void getGsmSimpleSimAuthResponse() { - TelephonyManager tm = mock(TelephonyManager.class); - when(tm.getIccAuthentication(TelephonyManager.APPTYPE_SIM, + when(mDataTelephonyManager.getIccAuthentication(TelephonyManager.APPTYPE_SIM, TelephonyManager.AUTHTYPE_EAP_SIM, createSimChallengeRequest(new byte[] { 0x1a, 0x2b }))) .thenReturn(createGsmSimAuthResponse(new byte[] { 0x1D, 0x2C }, new byte[] { 0x3B, 0x4A })); - when(tm.getIccAuthentication(TelephonyManager.APPTYPE_SIM, + when(mDataTelephonyManager.getIccAuthentication(TelephonyManager.APPTYPE_SIM, TelephonyManager.AUTHTYPE_EAP_SIM, createSimChallengeRequest(new byte[] { 0x01, 0x23 }))) .thenReturn(createGsmSimAuthResponse(new byte[] { 0x33, 0x22 }, new byte[] { 0x11, 0x00 })); assertEquals(":3b4a:1d2c:1100:3322", TelephonyUtil.getGsmSimpleSimAuthResponse( - new String[] { "1A2B", "0123" }, tm)); + new String[] { "1A2B", "0123" }, mTelephonyManager)); } @Test public void getGsmSimpleSimNoLengthAuthResponseInvalidRequest() { - TelephonyManager tm = mock(TelephonyManager.class); final String[] invalidRequests = { null, "", "XXXX" }; - assertEquals("", TelephonyUtil.getGsmSimpleSimNoLengthAuthResponse(invalidRequests, tm)); + assertEquals("", TelephonyUtil.getGsmSimpleSimNoLengthAuthResponse(invalidRequests, + mTelephonyManager)); } @Test public void getGsmSimpleSimNoLengthAuthResponseFailedSimResponse() { - TelephonyManager tm = mock(TelephonyManager.class); final String[] failedRequests = { "5E5F" }; - when(tm.getIccAuthentication(anyInt(), anyInt(), + when(mDataTelephonyManager.getIccAuthentication(anyInt(), anyInt(), eq(create2gUsimChallengeRequest(new byte[] { 0x5e, 0x5f })))).thenReturn(null); - assertEquals(null, TelephonyUtil.getGsmSimpleSimNoLengthAuthResponse(failedRequests, tm)); + assertEquals(null, TelephonyUtil.getGsmSimpleSimNoLengthAuthResponse(failedRequests, + mTelephonyManager)); } @Test public void getGsmSimpleSimNoLengthAuthResponse() { - TelephonyManager tm = mock(TelephonyManager.class); - when(tm.getIccAuthentication(TelephonyManager.APPTYPE_SIM, + when(mDataTelephonyManager.getIccAuthentication(TelephonyManager.APPTYPE_SIM, TelephonyManager.AUTHTYPE_EAP_SIM, create2gUsimChallengeRequest(new byte[] { 0x1a, 0x2b }))) .thenReturn(create2gUsimAuthResponse(new byte[] { 0x1a, 0x2b, 0x3c, 0x4d }, new byte[] { 0x1a, 0x2b, 0x3c, 0x4d, 0x5e, 0x6f, 0x7a, 0x1a })); - when(tm.getIccAuthentication(TelephonyManager.APPTYPE_SIM, + when(mDataTelephonyManager.getIccAuthentication(TelephonyManager.APPTYPE_SIM, TelephonyManager.AUTHTYPE_EAP_SIM, create2gUsimChallengeRequest(new byte[] { 0x01, 0x23 }))) .thenReturn(create2gUsimAuthResponse(new byte[] { 0x12, 0x34, 0x56, 0x78 }, @@ -551,7 +556,7 @@ public class TelephonyUtilTest { assertEquals(":1a2b3c4d5e6f7a1a:1a2b3c4d:1234567812345678:12345678", TelephonyUtil.getGsmSimpleSimNoLengthAuthResponse( - new String[] { "1A2B", "0123" }, tm)); + new String[] { "1A2B", "0123" }, mTelephonyManager)); } /** @@ -590,64 +595,60 @@ public class TelephonyUtilTest { @Test public void get3GAuthResponseInvalidRequest() { - TelephonyManager tm = mock(TelephonyManager.class); assertEquals(null, TelephonyUtil.get3GAuthResponse( - new SimAuthRequestData(0, 0, "SSID", new String[] {"0123"}), tm)); + new SimAuthRequestData(0, 0, "SSID", new String[]{"0123"}), mTelephonyManager)); assertEquals(null, TelephonyUtil.get3GAuthResponse( - new SimAuthRequestData(0, 0, "SSID", new String[] {"xyz2", "1234"}), tm)); - verifyNoMoreInteractions(tm); + new SimAuthRequestData(0, 0, "SSID", new String[]{"xyz2", "1234"}), + mTelephonyManager)); + verifyNoMoreInteractions(mDataTelephonyManager); } @Test public void get3GAuthResponseNullIccAuthentication() { - TelephonyManager tm = mock(TelephonyManager.class); - - when(tm.getIccAuthentication(TelephonyManager.APPTYPE_USIM, + when(mDataTelephonyManager.getIccAuthentication(TelephonyManager.APPTYPE_USIM, TelephonyManager.AUTHTYPE_EAP_AKA, "AgEjAkVn")).thenReturn(null); SimAuthResponseData response = TelephonyUtil.get3GAuthResponse( - new SimAuthRequestData(0, 0, "SSID", new String[] {"0123", "4567"}), tm); + new SimAuthRequestData(0, 0, "SSID", new String[]{"0123", "4567"}), + mTelephonyManager); assertNull(response); } @Test public void get3GAuthResponseIccAuthenticationTooShort() { - TelephonyManager tm = mock(TelephonyManager.class); - - when(tm.getIccAuthentication(TelephonyManager.APPTYPE_USIM, + when(mDataTelephonyManager.getIccAuthentication(TelephonyManager.APPTYPE_USIM, TelephonyManager.AUTHTYPE_EAP_AKA, "AgEjAkVn")) .thenReturn(Base64.encodeToString(new byte[] {(byte) 0xdc}, Base64.NO_WRAP)); SimAuthResponseData response = TelephonyUtil.get3GAuthResponse( - new SimAuthRequestData(0, 0, "SSID", new String[] {"0123", "4567"}), tm); + new SimAuthRequestData(0, 0, "SSID", new String[]{"0123", "4567"}), + mTelephonyManager); assertNull(response); } @Test public void get3GAuthResponseBadTag() { - TelephonyManager tm = mock(TelephonyManager.class); - - when(tm.getIccAuthentication(TelephonyManager.APPTYPE_USIM, + when(mDataTelephonyManager.getIccAuthentication(TelephonyManager.APPTYPE_USIM, TelephonyManager.AUTHTYPE_EAP_AKA, "AgEjAkVn")) .thenReturn(Base64.encodeToString(new byte[] {0x31, 0x1, 0x2, 0x3, 0x4}, Base64.NO_WRAP)); SimAuthResponseData response = TelephonyUtil.get3GAuthResponse( - new SimAuthRequestData(0, 0, "SSID", new String[] {"0123", "4567"}), tm); + new SimAuthRequestData(0, 0, "SSID", new String[]{"0123", "4567"}), + mTelephonyManager); assertNull(response); } @Test public void get3GAuthResponseUmtsAuth() { - TelephonyManager tm = mock(TelephonyManager.class); - - when(tm.getIccAuthentication(TelephonyManager.APPTYPE_USIM, + when(mDataTelephonyManager.getIccAuthentication(TelephonyManager.APPTYPE_USIM, TelephonyManager.AUTHTYPE_EAP_AKA, "AgEjAkVn")) .thenReturn(create3GSimAuthUmtsAuthResponse(new byte[] {0x11, 0x12}, new byte[] {0x21, 0x22, 0x23}, new byte[] {0x31})); SimAuthResponseData response = TelephonyUtil.get3GAuthResponse( - new SimAuthRequestData(0, 0, "SSID", new String[] {"0123", "4567"}), tm); + new SimAuthRequestData(0, 0, "SSID", new String[]{"0123", "4567"}), + mTelephonyManager); assertNotNull(response); assertEquals("UMTS-AUTH", response.type); assertEquals(":31:212223:1112", response.response); @@ -655,14 +656,13 @@ public class TelephonyUtilTest { @Test public void get3GAuthResponseUmtsAuts() { - TelephonyManager tm = mock(TelephonyManager.class); - - when(tm.getIccAuthentication(TelephonyManager.APPTYPE_USIM, + when(mDataTelephonyManager.getIccAuthentication(TelephonyManager.APPTYPE_USIM, TelephonyManager.AUTHTYPE_EAP_AKA, "AgEjAkVn")) .thenReturn(create3GSimAuthUmtsAutsResponse(new byte[] {0x22, 0x33})); SimAuthResponseData response = TelephonyUtil.get3GAuthResponse( - new SimAuthRequestData(0, 0, "SSID", new String[] {"0123", "4567"}), tm); + new SimAuthRequestData(0, 0, "SSID", new String[]{"0123", "4567"}), + mTelephonyManager); assertNotNull(response); assertEquals("UMTS-AUTS", response.type); assertEquals(":2233", response.response); @@ -673,13 +673,13 @@ public class TelephonyUtilTest { */ @Test public void getAnonymousIdentityWithSim() { - TelephonyManager tm = mock(TelephonyManager.class); String mccmnc = "123456"; String expectedIdentity = "anonymous@wlan.mnc456.mcc123.3gppnetwork.org"; - when(tm.getSimState()).thenReturn(TelephonyManager.SIM_STATE_READY); - when(tm.getSimOperator()).thenReturn(mccmnc); + when(mDataTelephonyManager.getSimState()).thenReturn(TelephonyManager.SIM_STATE_READY); + when(mDataTelephonyManager.getSimOperator()).thenReturn(mccmnc); - assertEquals(expectedIdentity, TelephonyUtil.getAnonymousIdentityWith3GppRealm(tm)); + assertEquals(expectedIdentity, + TelephonyUtil.getAnonymousIdentityWith3GppRealm(mTelephonyManager)); } /** @@ -687,9 +687,8 @@ public class TelephonyUtilTest { */ @Test public void getAnonymousIdentityWithoutSim() { - TelephonyManager tm = mock(TelephonyManager.class); - when(tm.getSimState()).thenReturn(TelephonyManager.SIM_STATE_ABSENT); + when(mDataTelephonyManager.getSimState()).thenReturn(TelephonyManager.SIM_STATE_ABSENT); - assertNull(TelephonyUtil.getAnonymousIdentityWith3GppRealm(tm)); + assertNull(TelephonyUtil.getAnonymousIdentityWith3GppRealm(mTelephonyManager)); } } |