diff options
author | David Su <dysu@google.com> | 2019-05-10 14:46:34 -0700 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2019-05-10 14:46:34 -0700 |
commit | cb6dc9732d0e7242adc476cd1276cecfab7aaaf2 (patch) | |
tree | 85391007149aaba69e55b59765ff9130631eb2fe | |
parent | 0138c94d7a1068bb79ba7dec94aabdf7ba1cc143 (diff) | |
parent | 8b5cc8afd5b23d70681f0880a7136f0a0646cdb0 (diff) |
Merge "Get isSimPresent() directly from Telephony" into qt-dev
am: 8b5cc8afd5
Change-Id: I23012050d977f304f1f32b20b1b81a6af770173b
12 files changed, 166 insertions, 139 deletions
diff --git a/service/java/com/android/server/wifi/ClientModeImpl.java b/service/java/com/android/server/wifi/ClientModeImpl.java index dbbd385b4..f9b7eba59 100644 --- a/service/java/com/android/server/wifi/ClientModeImpl.java +++ b/service/java/com/android/server/wifi/ClientModeImpl.java @@ -4540,8 +4540,8 @@ public class ClientModeImpl extends StateMachine { boolean simPresent = message.arg1 == 1; if (!simPresent) { mPasspointManager.removeEphemeralProviders(); + mWifiConfigManager.resetSimNetworks(); } - mWifiConfigManager.resetSimNetworks(simPresent); break; case CMD_BLUETOOTH_ADAPTER_STATE_CHANGE: mBluetoothConnectionActive = (message.arg1 @@ -5185,6 +5185,8 @@ public class ClientModeImpl extends StateMachine { if (TelephonyUtil.isSimConfig(config)) { mWifiMetrics.logStaEvent(StaEvent.TYPE_FRAMEWORK_DISCONNECT, StaEvent.DISCONNECT_RESET_SIM_NETWORKS); + // TODO(b/132385576): STA may immediately connect back to the network + // that we just disconnected from mWifiNative.disconnect(mInterfaceName); transitionTo(mDisconnectingState); } diff --git a/service/java/com/android/server/wifi/SavedNetworkEvaluator.java b/service/java/com/android/server/wifi/SavedNetworkEvaluator.java index d02256a74..f77403b80 100644 --- a/service/java/com/android/server/wifi/SavedNetworkEvaluator.java +++ b/service/java/com/android/server/wifi/SavedNetworkEvaluator.java @@ -21,6 +21,7 @@ import android.content.Context; import android.net.wifi.ScanResult; import android.net.wifi.WifiConfiguration; import android.os.Process; +import android.telephony.SubscriptionManager; import android.util.LocalLog; import com.android.internal.R; @@ -39,6 +40,7 @@ public class SavedNetworkEvaluator implements WifiNetworkSelector.NetworkEvaluat private final Clock mClock; private final LocalLog mLocalLog; private final WifiConnectivityHelper mConnectivityHelper; + private final SubscriptionManager mSubscriptionManager; private final int mRssiScoreSlope; private final int mRssiScoreOffset; private final int mSameBssidAward; @@ -57,12 +59,14 @@ public class SavedNetworkEvaluator implements WifiNetworkSelector.NetworkEvaluat SavedNetworkEvaluator(final Context context, ScoringParams scoringParams, WifiConfigManager configManager, Clock clock, - LocalLog localLog, WifiConnectivityHelper connectivityHelper) { + LocalLog localLog, WifiConnectivityHelper connectivityHelper, + SubscriptionManager subscriptionManager) { mScoringParams = scoringParams; mWifiConfigManager = configManager; mClock = clock; mLocalLog = localLog; mConnectivityHelper = connectivityHelper; + mSubscriptionManager = subscriptionManager; mRssiScoreSlope = context.getResources().getInteger( R.integer.config_wifi_framework_RSSI_SCORE_SLOPE); @@ -290,7 +294,7 @@ public class SavedNetworkEvaluator implements WifiNetworkSelector.NetworkEvaluat + scanResult.BSSID); continue; } else if (TelephonyUtil.isSimConfig(network) - && !mWifiConfigManager.isSimPresent()) { + && !TelephonyUtil.isSimPresent(mSubscriptionManager)) { // Don't select if security type is EAP SIM/AKA/AKA' when SIM is not present. continue; } diff --git a/service/java/com/android/server/wifi/WifiConfigManager.java b/service/java/com/android/server/wifi/WifiConfigManager.java index 310117ac5..c48601010 100644 --- a/service/java/com/android/server/wifi/WifiConfigManager.java +++ b/service/java/com/android/server/wifi/WifiConfigManager.java @@ -339,10 +339,6 @@ public class WifiConfigManager { */ private boolean mDeferredUserUnlockRead = false; /** - * Flag to indicate if SIM is present. - */ - private boolean mSimPresent = false; - /** * This is keeping track of the next network ID to be assigned. Any new networks will be * assigned |mNextNetworkId| as network ID. */ @@ -2786,46 +2782,33 @@ public class WifiConfigManager { /** * Resets all sim networks state. */ - public void resetSimNetworks(boolean simPresent) { + public void resetSimNetworks() { if (mVerboseLoggingEnabled) localLog("resetSimNetworks"); - if (simPresent) { - for (WifiConfiguration config : getInternalConfiguredNetworks()) { - if (TelephonyUtil.isSimConfig(config)) { - Pair<String, String> currentIdentity = - TelephonyUtil.getSimIdentity(mTelephonyManager, - new TelephonyUtil(), config, - mWifiInjector.getCarrierNetworkConfig()); - if (mVerboseLoggingEnabled) { - Log.d(TAG, "New identity for config " + config + ": " + currentIdentity); - } - - // Update the loaded config - if (currentIdentity == null) { - Log.d(TAG, "Identity is null"); - break; - } - if (config.enterpriseConfig.getEapMethod() == WifiEnterpriseConfig.Eap.PEAP) { - config.enterpriseConfig.setIdentity(currentIdentity.first); - // do not reset anonymous identity since it may be dependent on user-entry - // (i.e. cannot re-request on every reboot/SIM re-entry) - } else { - // reset identity as well: supplicant will ask us for it - config.enterpriseConfig.setIdentity(""); - config.enterpriseConfig.setAnonymousIdentity(""); - } + for (WifiConfiguration config : getInternalConfiguredNetworks()) { + if (!TelephonyUtil.isSimConfig(config)) { + continue; + } + if (config.enterpriseConfig.getEapMethod() == WifiEnterpriseConfig.Eap.PEAP) { + Pair<String, String> currentIdentity = TelephonyUtil.getSimIdentity( + mTelephonyManager, new TelephonyUtil(), config, + mWifiInjector.getCarrierNetworkConfig()); + if (mVerboseLoggingEnabled) { + Log.d(TAG, "New identity for config " + config + ": " + currentIdentity); } + // Update the loaded config + if (currentIdentity == null) { + Log.d(TAG, "Identity is null"); + } else { + config.enterpriseConfig.setIdentity(currentIdentity.first); + } + // do not reset anonymous identity since it may be dependent on user-entry + // (i.e. cannot re-request on every reboot/SIM re-entry) + } else { + // reset identity as well: supplicant will ask us for it + config.enterpriseConfig.setIdentity(""); + config.enterpriseConfig.setAnonymousIdentity(""); } } - mSimPresent = simPresent; - } - - /** - * Check if SIM is present. - * - * @return True if SIM is present, otherwise false. - */ - public boolean isSimPresent() { - return mSimPresent; } /** @@ -3077,8 +3060,10 @@ public class WifiConfigManager { if (mConfiguredNetworks.sizeForAllUsers() == 0) { Log.w(TAG, "No stored networks found."); } - // resetSimNetworks may already have been called. Call it again to reset loaded SIM configs. - resetSimNetworks(mSimPresent); + // reset identity & anonymous identity for networks using SIM-based authentication + // on load (i.e. boot) so that if the user changed SIMs while the device was powered off, + // we do not reuse stale credentials that would lead to authentication failure. + resetSimNetworks(); sendConfiguredNetworksChangedBroadcast(); mPendingStoreRead = false; } diff --git a/service/java/com/android/server/wifi/WifiInjector.java b/service/java/com/android/server/wifi/WifiInjector.java index e5391839f..8e88ca559 100644 --- a/service/java/com/android/server/wifi/WifiInjector.java +++ b/service/java/com/android/server/wifi/WifiInjector.java @@ -43,6 +43,7 @@ import android.os.SystemProperties; import android.os.UserManager; import android.provider.Settings.Secure; import android.security.KeyStore; +import android.telephony.SubscriptionManager; import android.telephony.TelephonyManager; import android.util.LocalLog; @@ -239,6 +240,8 @@ public class WifiInjector { mWifiConfigStore = new WifiConfigStore( mContext, clientModeImplLooper, mClock, mWifiMetrics, WifiConfigStore.createSharedFile()); + SubscriptionManager subscriptionManager = + mContext.getSystemService(SubscriptionManager.class); // Config Manager mWifiConfigManager = new WifiConfigManager(mContext, mClock, UserManager.get(mContext), makeTelephonyManager(), @@ -263,7 +266,8 @@ public class WifiInjector { mWifiNetworkSelector.registerCandidateScorer(bubbleFunScorer); mWifiMetrics.setWifiNetworkSelector(mWifiNetworkSelector); mSavedNetworkEvaluator = new SavedNetworkEvaluator(mContext, mScoringParams, - mWifiConfigManager, mClock, mConnectivityLocalLog, mWifiConnectivityHelper); + mWifiConfigManager, mClock, mConnectivityLocalLog, mWifiConnectivityHelper, + subscriptionManager); mWifiNetworkSuggestionsManager = new WifiNetworkSuggestionsManager(mContext, new Handler(mWifiCoreHandlerThread.getLooper()), this, mWifiPermissionsUtil, mWifiConfigManager, mWifiConfigStore, mWifiMetrics); @@ -278,10 +282,10 @@ public class WifiInjector { mPasspointManager = new PasspointManager(mContext, this, new Handler(mWifiCoreHandlerThread.getLooper()), mWifiNative, mWifiKeyStore, mClock, mSimAccessor, new PasspointObjectFactory(), mWifiConfigManager, mWifiConfigStore, - mWifiMetrics, makeTelephonyManager()); + mWifiMetrics, makeTelephonyManager(), subscriptionManager); mPasspointNetworkEvaluator = new PasspointNetworkEvaluator( mPasspointManager, mWifiConfigManager, mConnectivityLocalLog, - mCarrierNetworkConfig, this); + mCarrierNetworkConfig, this, subscriptionManager); mWifiMetrics.setPasspointManager(mPasspointManager); mScanRequestProxy = new ScanRequestProxy(mContext, (AppOpsManager) mContext.getSystemService(Context.APP_OPS_SERVICE), @@ -502,7 +506,6 @@ public class WifiInjector { return mWifiScoreCard; } - /** 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 917093ac2..75596b548 100644 --- a/service/java/com/android/server/wifi/hotspot2/PasspointManager.java +++ b/service/java/com/android/server/wifi/hotspot2/PasspointManager.java @@ -71,6 +71,7 @@ import com.android.server.wifi.hotspot2.anqp.HSOsuProvidersElement; import com.android.server.wifi.hotspot2.anqp.NAIRealmElement; import com.android.server.wifi.hotspot2.anqp.OsuProviderInfo; import com.android.server.wifi.util.InformationElementUtil; +import com.android.server.wifi.util.TelephonyUtil; import java.io.PrintWriter; import java.security.cert.X509Certificate; @@ -128,6 +129,7 @@ public class PasspointManager { private final PasspointProvisioner mPasspointProvisioner; private final TelephonyManager mTelephonyManager; private final AppOpsManager mAppOps; + private final SubscriptionManager mSubscriptionManager; /** * Map of package name of an app to the app ops changed listener for the app. @@ -333,7 +335,8 @@ public class PasspointManager { WifiNative wifiNative, WifiKeyStore keyStore, Clock clock, SIMAccessor simAccessor, PasspointObjectFactory objectFactory, WifiConfigManager wifiConfigManager, WifiConfigStore wifiConfigStore, - WifiMetrics wifiMetrics, TelephonyManager telephonyManager) { + WifiMetrics wifiMetrics, + TelephonyManager telephonyManager, SubscriptionManager subscriptionManager) { mPasspointEventHandler = objectFactory.makePasspointEventHandler(wifiNative, new CallbackHandler(context)); mWifiInjector = wifiInjector; @@ -349,6 +352,7 @@ public class PasspointManager { mWifiMetrics = wifiMetrics; mProviderIndex = 0; mTelephonyManager = telephonyManager; + mSubscriptionManager = subscriptionManager; wifiConfigStore.registerStoreData(objectFactory.makePasspointConfigUserStoreData( mKeyStore, mSimAccessor, new UserDataSourceHandler())); wifiConfigStore.registerStoreData(objectFactory.makePasspointConfigSharedStoreData( @@ -448,7 +452,7 @@ public class PasspointManager { * realm is found, {@code -1} otherwise. */ public int findEapMethodFromNAIRealmMatchedWithCarrier(List<ScanDetail> scanDetails) { - if (!mWifiConfigManager.isSimPresent()) { + if (!TelephonyUtil.isSimPresent(mSubscriptionManager)) { return -1; } if (scanDetails == null || scanDetails.isEmpty()) { @@ -611,7 +615,7 @@ public class PasspointManager { Log.e(TAG, "PasspointConfiguration for carrier is null"); return false; } - if (!mWifiConfigManager.isSimPresent()) { + if (!TelephonyUtil.isSimPresent(mSubscriptionManager)) { Log.e(TAG, "Sim is not presented on the device"); return false; } @@ -683,13 +687,14 @@ public class PasspointManager { * Remove the ephemeral providers that are created temporarily for a carrier. */ public void removeEphemeralProviders() { - for (Map.Entry<String, PasspointProvider> entry : mProviders.entrySet()) { + mProviders.entrySet().removeIf(entry -> { PasspointProvider provider = entry.getValue(); if (provider != null && provider.isEphemeral()) { - mProviders.remove(entry.getKey()); mWifiConfigManager.removePasspointConfiguredNetwork(entry.getKey()); + return true; } - } + return false; + }); } /** diff --git a/service/java/com/android/server/wifi/hotspot2/PasspointNetworkEvaluator.java b/service/java/com/android/server/wifi/hotspot2/PasspointNetworkEvaluator.java index 5e6fa8ca2..5629ec573 100644 --- a/service/java/com/android/server/wifi/hotspot2/PasspointNetworkEvaluator.java +++ b/service/java/com/android/server/wifi/hotspot2/PasspointNetworkEvaluator.java @@ -55,6 +55,7 @@ public class PasspointNetworkEvaluator implements WifiNetworkSelector.NetworkEva private final CarrierNetworkConfig mCarrierNetworkConfig; private final WifiInjector mWifiInjector; private TelephonyManager mTelephonyManager; + private SubscriptionManager mSubscriptionManager; /** * Contained information for a Passpoint network candidate. */ @@ -72,12 +73,14 @@ public class PasspointNetworkEvaluator implements WifiNetworkSelector.NetworkEva public PasspointNetworkEvaluator(PasspointManager passpointManager, WifiConfigManager wifiConfigManager, LocalLog localLog, - CarrierNetworkConfig carrierNetworkConfig, WifiInjector wifiInjector) { + CarrierNetworkConfig carrierNetworkConfig, WifiInjector wifiInjector, + SubscriptionManager subscriptionManager) { mPasspointManager = passpointManager; mWifiConfigManager = wifiConfigManager; mLocalLog = localLog; mCarrierNetworkConfig = carrierNetworkConfig; mWifiInjector = wifiInjector; + mSubscriptionManager = subscriptionManager; } private TelephonyManager getTelephonyManager() { @@ -132,7 +135,8 @@ public class PasspointNetworkEvaluator implements WifiNetworkSelector.NetworkEva Pair<PasspointProvider, PasspointMatch> bestProvider = mPasspointManager.matchProvider(scanResult); if (bestProvider != null) { - if (bestProvider.first.isSimCredential() && !mWifiConfigManager.isSimPresent()) { + if (bestProvider.first.isSimCredential() + && !TelephonyUtil.isSimPresent(mSubscriptionManager)) { // Skip providers backed by SIM credential when SIM is not present. continue; } diff --git a/service/java/com/android/server/wifi/util/TelephonyUtil.java b/service/java/com/android/server/wifi/util/TelephonyUtil.java index abaeabe44..1d19c9f5e 100644 --- a/service/java/com/android/server/wifi/util/TelephonyUtil.java +++ b/service/java/com/android/server/wifi/util/TelephonyUtil.java @@ -774,4 +774,11 @@ public class TelephonyUtil { } return CARRIER_MVNO_TYPE; } + + /** + * Returns true if at least one SIM is present on the device, false otherwise. + */ + public static boolean isSimPresent(@Nonnull SubscriptionManager sm) { + return sm.getActiveSubscriptionIdList().length > 0; + } } diff --git a/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java b/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java index f0e0daefc..0fd040c7e 100644 --- a/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java +++ b/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java @@ -3413,7 +3413,7 @@ public class ClientModeImplTest { mLooper.dispatchAll(); verify(mPasspointManager).removeEphemeralProviders(); - verify(mWifiConfigManager).resetSimNetworks(eq(false)); + verify(mWifiConfigManager).resetSimNetworks(); } /** diff --git a/tests/wifitests/src/com/android/server/wifi/SavedNetworkEvaluatorTest.java b/tests/wifitests/src/com/android/server/wifi/SavedNetworkEvaluatorTest.java index 15b64c4df..ff8c8250a 100644 --- a/tests/wifitests/src/com/android/server/wifi/SavedNetworkEvaluatorTest.java +++ b/tests/wifitests/src/com/android/server/wifi/SavedNetworkEvaluatorTest.java @@ -27,6 +27,7 @@ import android.content.res.Resources; import android.net.wifi.ScanResult; import android.net.wifi.WifiConfiguration; import android.os.SystemClock; +import android.telephony.SubscriptionManager; import android.util.LocalLog; import androidx.test.filters.SmallTest; @@ -76,7 +77,9 @@ public class SavedNetworkEvaluatorTest { mSavedNetworkEvaluator = new SavedNetworkEvaluator(mContext, new ScoringParams(mContext), mWifiConfigManager, - mClock, mLocalLog, mWifiConnectivityHelper); + mClock, mLocalLog, mWifiConnectivityHelper, mSubscriptionManager); + // SIM is absent + when(mSubscriptionManager.getActiveSubscriptionIdList()).thenReturn(new int[0]); } /** Cleans up test. */ @@ -92,6 +95,7 @@ public class SavedNetworkEvaluatorTest { @Mock private Resources mResource; @Mock private Clock mClock; @Mock private OnConnectableListener mOnConnectableListener; + @Mock private SubscriptionManager mSubscriptionManager; private LocalLog mLocalLog; private int mThresholdMinimumRssi2G; private int mThresholdMinimumRssi5G; diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java index b8f6c57fc..3b86be887 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java @@ -51,6 +51,7 @@ import androidx.test.filters.SmallTest; import com.android.dx.mockito.inline.extended.ExtendedMockito; import com.android.internal.R; +import com.android.server.wifi.util.TelephonyUtil; import com.android.server.wifi.util.WifiPermissionsUtil; import com.android.server.wifi.util.WifiPermissionsWrapper; @@ -4308,71 +4309,79 @@ public class WifiConfigManagerTest { verifyAddNetworkToWifiConfigManager(simNetwork); verifyAddNetworkToWifiConfigManager(peapSimNetwork); - // Verify SIM is not present initially. - assertFalse(mWifiConfigManager.isSimPresent()); + // SIM was removed, resetting SIM Networks + mWifiConfigManager.resetSimNetworks(); - // Call resetSimNetworks with true(SIM is present). - mWifiConfigManager.resetSimNetworks(true); - - // Verify SIM is present, SIM configs are reset and non-SIM configs are not changed. - assertTrue(mWifiConfigManager.isSimPresent()); + // Verify SIM configs are reset and non-SIM configs are not changed. WifiConfigurationTestUtil.assertConfigurationEqualForConfigManagerAddOrUpdate( network, mWifiConfigManager.getConfiguredNetworkWithPassword(network.networkId)); WifiConfiguration retrievedSimNetwork = mWifiConfigManager.getConfiguredNetwork(simNetwork.networkId); - assertTrue(retrievedSimNetwork.enterpriseConfig.getAnonymousIdentity().isEmpty()); - assertTrue(retrievedSimNetwork.enterpriseConfig.getIdentity().isEmpty()); + assertEquals("", retrievedSimNetwork.enterpriseConfig.getAnonymousIdentity()); + assertEquals("", retrievedSimNetwork.enterpriseConfig.getIdentity()); WifiConfiguration retrievedPeapSimNetwork = mWifiConfigManager.getConfiguredNetwork(peapSimNetwork.networkId); assertEquals(expectedIdentity, retrievedPeapSimNetwork.enterpriseConfig.getIdentity()); - assertFalse(retrievedPeapSimNetwork.enterpriseConfig.getAnonymousIdentity().isEmpty()); - - // Call resetSimNetworks with false(SIM is not present). - when(mDataTelephonyManager.getSubscriberId()).thenReturn("3214561234567891"); - retrievedSimNetwork.enterpriseConfig.setAnonymousIdentity("anonymous_identity22"); - verifyUpdateNetworkToWifiConfigManagerWithoutIpChange(retrievedSimNetwork); - mWifiConfigManager.resetSimNetworks(false); - - // Verify SIM is not present and all configs are not changed. - assertFalse(mWifiConfigManager.isSimPresent()); - WifiConfigurationTestUtil.assertConfigurationEqualForConfigManagerAddOrUpdate( - network, - mWifiConfigManager.getConfiguredNetworkWithPassword(network.networkId)); - WifiConfigurationTestUtil.assertConfigurationEqualForConfigManagerAddOrUpdate( - retrievedSimNetwork, - mWifiConfigManager.getConfiguredNetworkWithPassword(simNetwork.networkId)); - WifiConfigurationTestUtil.assertConfigurationEqualForConfigManagerAddOrUpdate( - retrievedPeapSimNetwork, - mWifiConfigManager.getConfiguredNetworkWithPassword(peapSimNetwork.networkId)); + assertNotEquals("", retrievedPeapSimNetwork.enterpriseConfig.getAnonymousIdentity()); } /** - * Verifies that the method resetSimNetworks updates SIM presence status if - * getSimIdentity returns null. + * {@link WifiConfigManager#resetSimNetworks()} should reset all non-PEAP SIM networks, no + * matter if {@link com.android.server.wifi.util.TelephonyUtil#getSimIdentity(TelephonyManager, + * TelephonyUtil, WifiConfiguration, CarrierNetworkConfig) TelephonyUtil#getSimIdentity} + * returns null or not. */ @Test - public void testResetSimNetworksWithNullIdentity() { + public void testResetSimNetworks_getSimIdentityNull_shouldResetAllNonPeapSimIdentities() { + when(mDataTelephonyManager.getSubscriberId()).thenReturn("3214561234567890"); + when(mDataTelephonyManager.getSimState()).thenReturn(TelephonyManager.SIM_STATE_READY); + when(mDataTelephonyManager.getSimOperator()).thenReturn("321456"); + when(mDataTelephonyManager.getCarrierInfoForImsiEncryption(anyInt())).thenReturn(null); + // null CarrierNetworkConfig => getSimIdentity returns null => PEAP identity unchanged + when(mWifiInjector.getCarrierNetworkConfig()).thenReturn(null); + + WifiConfiguration peapSimNetwork = WifiConfigurationTestUtil.createEapNetwork( + WifiEnterpriseConfig.Eap.PEAP, WifiEnterpriseConfig.Phase2.SIM); + peapSimNetwork.enterpriseConfig.setIdentity("identity_peap"); + peapSimNetwork.enterpriseConfig.setAnonymousIdentity("anonymous_identity_peap"); + verifyAddNetworkToWifiConfigManager(peapSimNetwork); + + WifiConfiguration network = WifiConfigurationTestUtil.createEapNetwork(); + network.enterpriseConfig.setIdentity("identity"); + network.enterpriseConfig.setAnonymousIdentity("anonymous_identity"); + verifyAddNetworkToWifiConfigManager(network); + WifiConfiguration simNetwork = WifiConfigurationTestUtil.createEapNetwork( WifiEnterpriseConfig.Eap.SIM, WifiEnterpriseConfig.Phase2.NONE); + simNetwork.enterpriseConfig.setIdentity("identity_eap_sim"); + simNetwork.enterpriseConfig.setAnonymousIdentity("anonymous_identity_eap_sim"); verifyAddNetworkToWifiConfigManager(simNetwork); - assertFalse(mWifiConfigManager.isSimPresent()); - - mWifiConfigManager.resetSimNetworks(true); - assertTrue(mWifiConfigManager.isSimPresent()); + // SIM was removed, resetting SIM Networks + mWifiConfigManager.resetSimNetworks(); - mWifiConfigManager.resetSimNetworks(false); - assertFalse(mWifiConfigManager.isSimPresent()); + // EAP non-SIM network should be unchanged + WifiConfigurationTestUtil.assertConfigurationEqualForConfigManagerAddOrUpdate( + network, mWifiConfigManager.getConfiguredNetworkWithPassword(network.networkId)); + // EAP-SIM network should have identity & anonymous identity reset + WifiConfiguration retrievedSimNetwork = + mWifiConfigManager.getConfiguredNetwork(simNetwork.networkId); + assertEquals("", retrievedSimNetwork.enterpriseConfig.getAnonymousIdentity()); + assertEquals("", retrievedSimNetwork.enterpriseConfig.getIdentity()); + // PEAP network should have unchanged identity & anonymous identity + WifiConfiguration retrievedPeapSimNetwork = + mWifiConfigManager.getConfiguredNetwork(peapSimNetwork.networkId); + assertEquals("identity_peap", retrievedPeapSimNetwork.enterpriseConfig.getIdentity()); + assertEquals("anonymous_identity_peap", + retrievedPeapSimNetwork.enterpriseConfig.getAnonymousIdentity()); } /** - * Verifies that SIM config is reset if store is read after the method resetSimNetworks - * is called. + * Verifies that SIM configs are reset on {@link WifiConfigManager#loadFromStore()}. */ @Test - public void testResetSimNetworksIsCalledAgainAfterLoadFromStore() { - String expectedIdentity = "13214561234567890@wlan.mnc456.mcc321.3gppnetwork.org"; + public void testLoadFromStoreResetsSimIdentity() { when(mDataTelephonyManager.getSubscriberId()).thenReturn("3214561234567890"); when(mDataTelephonyManager.getSimState()).thenReturn(TelephonyManager.SIM_STATE_READY); when(mDataTelephonyManager.getSimOperator()).thenReturn("321456"); @@ -4397,27 +4406,20 @@ public class WifiConfigManagerTest { }; setupStoreDataForRead(sharedNetworks, new ArrayList<>(), new HashMap<>()); - // 1. Call resetSimNetworks with true(SIM is present). - mWifiConfigManager.resetSimNetworks(true); - - // Verify SIM is present. - assertTrue(mWifiConfigManager.isSimPresent()); - - // 2. Read from store now. + // read from store now assertTrue(mWifiConfigManager.loadFromStore()); - // Verify SIM is present just in case and SIM config is reset. - assertTrue(mWifiConfigManager.isSimPresent()); - + // assert that the expected identities are reset WifiConfiguration retrievedSimNetwork = mWifiConfigManager.getConfiguredNetwork(simNetwork.networkId); - assertTrue(retrievedSimNetwork.enterpriseConfig.getIdentity().isEmpty()); - assertTrue(retrievedSimNetwork.enterpriseConfig.getAnonymousIdentity().isEmpty()); + assertEquals("", retrievedSimNetwork.enterpriseConfig.getIdentity()); + assertEquals("", retrievedSimNetwork.enterpriseConfig.getAnonymousIdentity()); WifiConfiguration retrievedPeapNetwork = mWifiConfigManager.getConfiguredNetwork(peapSimNetwork.networkId); - assertEquals(retrievedPeapNetwork.enterpriseConfig.getIdentity(), "identity"); - assertFalse(retrievedPeapNetwork.enterpriseConfig.getAnonymousIdentity().isEmpty()); + assertEquals("identity", retrievedPeapNetwork.enterpriseConfig.getIdentity()); + assertEquals("anonymous_identity", + retrievedPeapNetwork.enterpriseConfig.getAnonymousIdentity()); } /** @@ -4631,14 +4633,6 @@ public class WifiConfigManagerTest { WifiConfigManager.createDebugTimeStampString(TEST_WALLCLOCK_UPDATE_TIME_MILLIS); } - private void assertNotEquals(Object expected, Object actual) { - if (actual != null) { - assertFalse(actual.equals(expected)); - } else { - assertNotNull(expected); - } - } - /** * Modifies the provided WifiConfiguration with the specified bssid value. Also, asserts that * the existing |BSSID| field is not the same value as the one being set 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 bf71b927e..338f7bc40 100644 --- a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java @@ -72,6 +72,7 @@ import android.os.Handler; import android.os.Looper; import android.os.UserHandle; import android.os.test.TestLooper; +import android.telephony.SubscriptionManager; import android.telephony.TelephonyManager; import android.util.Base64; import android.util.Pair; @@ -186,6 +187,7 @@ public class PasspointManagerTest { @Mock ClientModeImpl mClientModeImpl; @Mock TelephonyManager mTelephonyManager; @Mock TelephonyManager mDataTelephonyManager; + @Mock SubscriptionManager mSubscriptionManager; Handler mHandler; TestLooper mLooper; @@ -216,7 +218,7 @@ public class PasspointManagerTest { mHandler = new Handler(mLooper.getLooper()); mManager = new PasspointManager(mContext, mWifiInjector, mHandler, mWifiNative, mWifiKeyStore, mClock, mSimAccessor, mObjectFactory, mWifiConfigManager, - mWifiConfigStore, mWifiMetrics, mTelephonyManager); + mWifiConfigStore, mWifiMetrics, mTelephonyManager, mSubscriptionManager); ArgumentCaptor<PasspointEventHandler.Callbacks> callbacks = ArgumentCaptor.forClass(PasspointEventHandler.Callbacks.class); verify(mObjectFactory).makePasspointEventHandler(any(WifiNative.class), @@ -231,6 +233,8 @@ public class PasspointManagerTest { mCallbacks = callbacks.getValue(); mSharedDataSource = sharedDataSource.getValue(); mUserDataSource = userDataSource.getValue(); + // SIM is absent + when(mSubscriptionManager.getActiveSubscriptionIdList()).thenReturn(new int[0]); } /** @@ -1626,7 +1630,8 @@ public class PasspointManagerTest { when(mDataTelephonyManager.getSimOperator()).thenReturn("123456"); PasspointManager passpointManager = new PasspointManager(mContext, mWifiInjector, mHandler, mWifiNative, mWifiKeyStore, mClock, mSimAccessor, mObjectFactory, - mWifiConfigManager, mWifiConfigStore, mWifiMetrics, mTelephonyManager); + mWifiConfigManager, mWifiConfigStore, mWifiMetrics, mTelephonyManager, + mSubscriptionManager); assertNull(passpointManager.createEphemeralPasspointConfigForCarrier( EAPConstants.EAP_TLS)); @@ -1643,7 +1648,8 @@ public class PasspointManagerTest { when(mDataTelephonyManager.getSimOperatorName()).thenReturn("test"); PasspointManager passpointManager = new PasspointManager(mContext, mWifiInjector, mHandler, mWifiNative, mWifiKeyStore, mClock, mSimAccessor, mObjectFactory, - mWifiConfigManager, mWifiConfigStore, mWifiMetrics, mTelephonyManager); + mWifiConfigManager, mWifiConfigStore, mWifiMetrics, mTelephonyManager, + mSubscriptionManager); PasspointConfiguration result = passpointManager.createEphemeralPasspointConfigForCarrier( @@ -1660,7 +1666,8 @@ public class PasspointManagerTest { */ @Test public void verifyInstallEphemeralPasspointConfigurationWithNonCarrierEapMethod() { - when(mWifiConfigManager.isSimPresent()).thenReturn(true); + // SIM is present + when(mSubscriptionManager.getActiveSubscriptionIdList()).thenReturn(new int[1]); PasspointConfiguration config = createTestConfigWithUserCredential("abc.com", "test"); PasspointProvider provider = createMockProvider(config); when(mObjectFactory.makePasspointProvider(eq(config), eq(mWifiKeyStore), @@ -1674,7 +1681,8 @@ public class PasspointManagerTest { */ @Test public void verifyInstallEphemeralPasspointConfiguration() { - when(mWifiConfigManager.isSimPresent()).thenReturn(true); + // SIM is present + when(mSubscriptionManager.getActiveSubscriptionIdList()).thenReturn(new int[1]); PasspointConfiguration config = createTestConfigWithSimCredential(TEST_FQDN, TEST_IMSI, TEST_REALM); PasspointProvider provider = createMockProvider(config); @@ -1719,7 +1727,8 @@ public class PasspointManagerTest { when(mTelephonyManager.createForSubscriptionId(anyInt())) .thenReturn(mDataTelephonyManager); when(mDataTelephonyManager.getSimOperator()).thenReturn(TEST_MCC_MNC); - when(mWifiConfigManager.isSimPresent()).thenReturn(true); + // SIM is present + when(mSubscriptionManager.getActiveSubscriptionIdList()).thenReturn(new int[1]); List<ScanDetail> scanDetails = new ArrayList<>(); scanDetails.add(generateScanDetail(TEST_SSID, TEST_BSSID_STRING, TEST_HESSID, TEST_ANQP_DOMAIN_ID, true)); @@ -1740,7 +1749,8 @@ public class PasspointManagerTest { PasspointManager passpointManager = new PasspointManager(mContext, mWifiInjector, mHandler, mWifiNative, mWifiKeyStore, mClock, mSimAccessor, mObjectFactory, - mWifiConfigManager, mWifiConfigStore, mWifiMetrics, mTelephonyManager); + mWifiConfigManager, mWifiConfigStore, mWifiMetrics, mTelephonyManager, + mSubscriptionManager); assertEquals(EAPConstants.EAP_AKA, passpointManager.findEapMethodFromNAIRealmMatchedWithCarrier(scanDetails)); } finally { @@ -1761,13 +1771,15 @@ public class PasspointManagerTest { when(mTelephonyManager.createForSubscriptionId(anyInt())) .thenReturn(mDataTelephonyManager); when(mDataTelephonyManager.getSimOperator()).thenReturn(TEST_MCC_MNC); - when(mWifiConfigManager.isSimPresent()).thenReturn(true); + // SIM is present + when(mSubscriptionManager.getActiveSubscriptionIdList()).thenReturn(new int[1]); 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, mTelephonyManager); + mWifiConfigManager, mWifiConfigStore, mWifiMetrics, mTelephonyManager, + mSubscriptionManager); 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 f9d6a1c8d..3048abae0 100644 --- a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointNetworkEvaluatorTest.java +++ b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointNetworkEvaluatorTest.java @@ -37,6 +37,7 @@ import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiEnterpriseConfig; import android.net.wifi.hotspot2.PasspointConfiguration; import android.net.wifi.hotspot2.pps.HomeSp; +import android.telephony.SubscriptionManager; import android.telephony.TelephonyManager; import android.util.LocalLog; import android.util.Pair; @@ -59,6 +60,7 @@ import org.mockito.ArgumentCaptor; import org.mockito.Mock; import java.util.Arrays; +import java.util.Collections; import java.util.List; /** @@ -84,6 +86,7 @@ public class PasspointNetworkEvaluatorTest { @Mock OnConnectableListener mOnConnectableListener; @Mock TelephonyManager mTelephonyManager; @Mock TelephonyManager mDataTelephonyManager; + @Mock SubscriptionManager mSubscriptionManager; @Mock CarrierNetworkConfig mCarrierNetworkConfig; @Mock WifiInjector mWifiInjector; LocalLog mLocalLog; @@ -149,10 +152,11 @@ public class PasspointNetworkEvaluatorTest { initMocks(this); mLocalLog = new LocalLog(512); mEvaluator = new PasspointNetworkEvaluator(mPasspointManager, mWifiConfigManager, mLocalLog, - mCarrierNetworkConfig, mWifiInjector); + mCarrierNetworkConfig, mWifiInjector, mSubscriptionManager); when(mWifiInjector.makeTelephonyManager()).thenReturn(mTelephonyManager); when(mTelephonyManager.createForSubscriptionId(anyInt())).thenReturn(mDataTelephonyManager); - when(mWifiConfigManager.isSimPresent()).thenReturn(true); + // SIM is present + when(mSubscriptionManager.getActiveSubscriptionIdList()).thenReturn(new int[1]); when(mDataTelephonyManager.getSimOperator()).thenReturn("123456"); when(mDataTelephonyManager.getSimState()).thenReturn(TelephonyManager.SIM_STATE_READY); } @@ -382,7 +386,8 @@ public class PasspointNetworkEvaluatorTest { when(mPasspointManager.matchProvider(any(ScanResult.class))).thenReturn(homeProvider); when(testProvider.isSimCredential()).thenReturn(true); - when(mWifiConfigManager.isSimPresent()).thenReturn(false); + // SIM is absent + when(mSubscriptionManager.getActiveSubscriptionIdList()).thenReturn(new int[0]); assertEquals(null, mEvaluator.evaluateNetworks( scanDetails, null, null, false, false, mOnConnectableListener)); @@ -413,7 +418,8 @@ public class PasspointNetworkEvaluatorTest { mTelephonyManager); when(mPasspointManager.matchProvider(any(ScanResult.class))).thenReturn(homeProvider); when(testProvider.isSimCredential()).thenReturn(true); - when(mWifiConfigManager.isSimPresent()).thenReturn(true); + // SIM is present + when(mSubscriptionManager.getActiveSubscriptionIdList()).thenReturn(new int[1]); when(mCarrierNetworkConfig.isCarrierEncryptionInfoAvailable()).thenReturn(true); when(mCarrierNetworkConfig.isSupportAnonymousIdentity()).thenReturn(true); when(mWifiConfigManager.addOrUpdateNetwork(any(WifiConfiguration.class), anyInt())) @@ -452,13 +458,14 @@ public class PasspointNetworkEvaluatorTest { @Test public void skipCreateEphemeralPasspointConfigurationWithoutSIMCard() { // Setup ScanDetail and match providers. - List<ScanDetail> scanDetails = Arrays.asList(new ScanDetail[] { - generateScanDetail(TEST_SSID1, TEST_BSSID1)}); - when(mWifiConfigManager.isSimPresent()).thenReturn(false); + List<ScanDetail> scanDetails = Collections.singletonList( + generateScanDetail(TEST_SSID1, TEST_BSSID1)); + // SIM is absent + when(mSubscriptionManager.getActiveSubscriptionIdList()).thenReturn(new int[0]); when(mPasspointManager.hasCarrierProvider(anyString())).thenReturn(false); when(mCarrierNetworkConfig.isCarrierEncryptionInfoAvailable()).thenReturn(true); - assertEquals(null, mEvaluator.evaluateNetworks( + assertNull(mEvaluator.evaluateNetworks( scanDetails, null, null, false, false, mOnConnectableListener)); verify(mPasspointManager, never()).createEphemeralPasspointConfigForCarrier(anyInt()); } |