diff options
author | David Su <dysu@google.com> | 2019-05-10 22:12:34 -0700 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2019-05-10 22:12:34 -0700 |
commit | 4f903b97a70768acb6a079f5f11cde185663d65a (patch) | |
tree | 1c569ab120d63cf276b3dfd798e40be88f3c2eb0 /service | |
parent | e221a42743afdf654d7e57a0ea42d14da6aab3ea (diff) | |
parent | cb6dc9732d0e7242adc476cd1276cecfab7aaaf2 (diff) |
Merge "Get isSimPresent() directly from Telephony" into qt-dev am: 8b5cc8afd5
am: cb6dc9732d
Change-Id: Ib281e045f887262b24cc4e3b7363715a82148032
Diffstat (limited to 'service')
7 files changed, 67 insertions, 57 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; + } } |