diff options
author | David Su <dysu@google.com> | 2019-05-07 15:36:06 -0700 |
---|---|---|
committer | David Su <dysu@google.com> | 2019-05-07 22:38:11 -0700 |
commit | bfe8dc332f563cfb9569dacb69d689f05dc37ba8 (patch) | |
tree | 3d3e4ba34d4b41b99dbe654d0bd7e761cddae048 /tests | |
parent | 353e8733c58131f4f78e63f2adb6a4f6379a1d59 (diff) |
Fix all Wifi calls to TelephonyManager to explicitly use default data subscription
Previously, calls to TelephonyManager APIs did not
specify which subscription to use, and different
Telephony APIs have different default subscriptions to
use, leading to inconsistent data being retrieved. Fix
these API calls to consistently use the default data
subscription.
Bug: 112741663
Test: frameworks/opt/net/wifi/tests/wifitests/runtests.sh
Test: Connect to EAP-SIM network with one SIM for voice and one SIM for data.
Change-Id: Id352372a21fc2dca60b9df88ced1bc3fb47f28d8
Diffstat (limited to 'tests')
11 files changed, 257 insertions, 249 deletions
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)); } } |