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 /service | |
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 'service')
10 files changed, 111 insertions, 45 deletions
diff --git a/service/java/com/android/server/wifi/CarrierNetworkConfig.java b/service/java/com/android/server/wifi/CarrierNetworkConfig.java index 1814eecf4..6e754231f 100644 --- a/service/java/com/android/server/wifi/CarrierNetworkConfig.java +++ b/service/java/com/android/server/wifi/CarrierNetworkConfig.java @@ -179,6 +179,7 @@ public class CarrierNetworkConfig { * @return True if carrier IMSI encryption info is available, False otherwise. */ private boolean verifyCarrierImsiEncryptionInfoIsAvailable(Context context) { + // TODO(b/132188983): Inject this using WifiInjector TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); if (telephonyManager == null) { @@ -186,6 +187,7 @@ public class CarrierNetworkConfig { } try { mLastImsiEncryptionInfo = telephonyManager + .createForSubscriptionId(SubscriptionManager.getDefaultDataSubscriptionId()) .getCarrierInfoForImsiEncryption(TelephonyManager.KEY_TYPE_WLAN); if (mLastImsiEncryptionInfo == null) { return false; diff --git a/service/java/com/android/server/wifi/CellularLinkLayerStatsCollector.java b/service/java/com/android/server/wifi/CellularLinkLayerStatsCollector.java index 473ced3ea..81d219cce 100644 --- a/service/java/com/android/server/wifi/CellularLinkLayerStatsCollector.java +++ b/service/java/com/android/server/wifi/CellularLinkLayerStatsCollector.java @@ -123,6 +123,7 @@ public class CellularLinkLayerStatsCollector { if (defaultDataSubId != mCachedDefaultDataSubId || mCachedDefaultDataTelephonyManager == null) { mCachedDefaultDataSubId = defaultDataSubId; + // TODO(b/132188983): Inject this using WifiInjector TelephonyManager defaultSubTelephonyManager = (TelephonyManager) mContext .getSystemService(Context.TELEPHONY_SERVICE); if (defaultDataSubId == mSubManager.getDefaultSubscriptionId()) { diff --git a/service/java/com/android/server/wifi/ClientModeImpl.java b/service/java/com/android/server/wifi/ClientModeImpl.java index c0ff441a7..08f5720d8 100644 --- a/service/java/com/android/server/wifi/ClientModeImpl.java +++ b/service/java/com/android/server/wifi/ClientModeImpl.java @@ -87,6 +87,7 @@ import android.os.UserManager; import android.os.WorkSource; import android.provider.Settings; import android.system.OsConstants; +import android.telephony.SubscriptionManager; import android.telephony.TelephonyManager; import android.text.TextUtils; import android.util.Log; @@ -4740,7 +4741,10 @@ public class ClientModeImpl extends StateMachine { case WifiEnterpriseConfig.Eap.AKA: case WifiEnterpriseConfig.Eap.AKA_PRIME: if (errorCode == WifiNative.EAP_SIM_VENDOR_SPECIFIC_CERT_EXPIRED) { - getTelephonyManager().resetCarrierKeysForImsiEncryption(); + getTelephonyManager() + .createForSubscriptionId( + SubscriptionManager.getDefaultDataSubscriptionId()) + .resetCarrierKeysForImsiEncryption(); } break; diff --git a/service/java/com/android/server/wifi/SIMAccessor.java b/service/java/com/android/server/wifi/SIMAccessor.java index 21bfb9c51..efa303752 100644 --- a/service/java/com/android/server/wifi/SIMAccessor.java +++ b/service/java/com/android/server/wifi/SIMAccessor.java @@ -12,7 +12,9 @@ public class SIMAccessor { private final SubscriptionManager mSubscriptionManager; public SIMAccessor(Context context) { + // TODO(b/132188983): Inject this using WifiInjector mTelephonyManager = TelephonyManager.from(context); + // TODO(b/132188983): Inject this using WifiInjector mSubscriptionManager = SubscriptionManager.from(context); } diff --git a/service/java/com/android/server/wifi/WifiInjector.java b/service/java/com/android/server/wifi/WifiInjector.java index 02a835673..e5391839f 100644 --- a/service/java/com/android/server/wifi/WifiInjector.java +++ b/service/java/com/android/server/wifi/WifiInjector.java @@ -241,7 +241,7 @@ public class WifiInjector { WifiConfigStore.createSharedFile()); // Config Manager mWifiConfigManager = new WifiConfigManager(mContext, mClock, - UserManager.get(mContext), TelephonyManager.from(mContext), + UserManager.get(mContext), makeTelephonyManager(), mWifiKeyStore, mWifiConfigStore, mWifiPermissionsUtil, mWifiPermissionsWrapper, this, new NetworkListSharedStoreData(mContext), new NetworkListUserStoreData(mContext), @@ -278,7 +278,7 @@ public class WifiInjector { mPasspointManager = new PasspointManager(mContext, this, new Handler(mWifiCoreHandlerThread.getLooper()), mWifiNative, mWifiKeyStore, mClock, mSimAccessor, new PasspointObjectFactory(), mWifiConfigManager, mWifiConfigStore, - mWifiMetrics); + mWifiMetrics, makeTelephonyManager()); mPasspointNetworkEvaluator = new PasspointNetworkEvaluator( mPasspointManager, mWifiConfigManager, mConnectivityLocalLog, mCarrierNetworkConfig, this); @@ -502,7 +502,7 @@ public class WifiInjector { return mWifiScoreCard; } - /** Gets a TelephonyManager, which moy not be available early on. */ + /** Gets a TelephonyManager, which may not be available early on. */ public TelephonyManager makeTelephonyManager() { return (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE); } diff --git a/service/java/com/android/server/wifi/hotspot2/PasspointManager.java b/service/java/com/android/server/wifi/hotspot2/PasspointManager.java index 020beaed2..917093ac2 100644 --- a/service/java/com/android/server/wifi/hotspot2/PasspointManager.java +++ b/service/java/com/android/server/wifi/hotspot2/PasspointManager.java @@ -49,6 +49,7 @@ import android.os.Handler; import android.os.Looper; import android.os.Process; import android.os.UserHandle; +import android.telephony.SubscriptionManager; import android.telephony.TelephonyManager; import android.text.TextUtils; import android.util.Log; @@ -332,7 +333,7 @@ public class PasspointManager { WifiNative wifiNative, WifiKeyStore keyStore, Clock clock, SIMAccessor simAccessor, PasspointObjectFactory objectFactory, WifiConfigManager wifiConfigManager, WifiConfigStore wifiConfigStore, - WifiMetrics wifiMetrics) { + WifiMetrics wifiMetrics, TelephonyManager telephonyManager) { mPasspointEventHandler = objectFactory.makePasspointEventHandler(wifiNative, new CallbackHandler(context)); mWifiInjector = wifiInjector; @@ -347,7 +348,7 @@ public class PasspointManager { mWifiConfigManager = wifiConfigManager; mWifiMetrics = wifiMetrics; mProviderIndex = 0; - mTelephonyManager = TelephonyManager.from(context); + mTelephonyManager = telephonyManager; wifiConfigStore.registerStoreData(objectFactory.makePasspointConfigUserStoreData( mKeyStore, mSimAccessor, new UserDataSourceHandler())); wifiConfigStore.registerStoreData(objectFactory.makePasspointConfigSharedStoreData( @@ -454,7 +455,9 @@ public class PasspointManager { return -1; } - String mccMnc = mTelephonyManager.getSimOperator(); + String mccMnc = mTelephonyManager + .createForSubscriptionId(SubscriptionManager.getDefaultDataSubscriptionId()) + .getSimOperator(); if (mccMnc == null || mccMnc.length() < IMSIParameter.MCC_MNC_LENGTH - 1) { return -1; } @@ -515,7 +518,9 @@ public class PasspointManager { * {@code null} otherwise. */ public PasspointConfiguration createEphemeralPasspointConfigForCarrier(int eapMethod) { - String mccMnc = mTelephonyManager.getSimOperator(); + String mccMnc = mTelephonyManager + .createForSubscriptionId(SubscriptionManager.getDefaultDataSubscriptionId()) + .getSimOperator(); if (mccMnc == null || mccMnc.length() < IMSIParameter.MCC_MNC_LENGTH - 1) { Log.e(TAG, "invalid length of mccmnc"); return null; @@ -534,7 +539,10 @@ public class PasspointManager { PasspointConfiguration config = new PasspointConfiguration(); HomeSp homeSp = new HomeSp(); homeSp.setFqdn(domain); - homeSp.setFriendlyName(mTelephonyManager.getSimOperatorName()); + String friendlyName = mTelephonyManager + .createForSubscriptionId(SubscriptionManager.getDefaultDataSubscriptionId()) + .getSimOperatorName(); + homeSp.setFriendlyName(friendlyName); config.setHomeSp(homeSp); Credential credential = new Credential(); diff --git a/service/java/com/android/server/wifi/hotspot2/PasspointNetworkEvaluator.java b/service/java/com/android/server/wifi/hotspot2/PasspointNetworkEvaluator.java index f0ea8c55e..5e6fa8ca2 100644 --- a/service/java/com/android/server/wifi/hotspot2/PasspointNetworkEvaluator.java +++ b/service/java/com/android/server/wifi/hotspot2/PasspointNetworkEvaluator.java @@ -23,6 +23,7 @@ import android.net.wifi.ScanResult; import android.net.wifi.WifiConfiguration; import android.net.wifi.hotspot2.PasspointConfiguration; import android.os.Process; +import android.telephony.SubscriptionManager; import android.telephony.TelephonyManager; import android.text.TextUtils; import android.util.LocalLog; @@ -120,24 +121,7 @@ public class PasspointNetworkEvaluator implements WifiNetworkSelector.NetworkEva } }).collect(Collectors.toList()); - // Creates an ephemeral Passpoint profile if it finds a matching Passpoint AP for MCC/MNC - // of the current MNO carrier on the device. - if ((getTelephonyManager() != null) - && (TelephonyUtil.getCarrierType(mTelephonyManager) - == TelephonyUtil.CARRIER_MNO_TYPE) - && mCarrierNetworkConfig.isCarrierEncryptionInfoAvailable() - && !mPasspointManager.hasCarrierProvider(mTelephonyManager.getSimOperator())) { - int eapMethod = mPasspointManager.findEapMethodFromNAIRealmMatchedWithCarrier( - filteredScanDetails); - if (isCarrierEapMethod(eapMethod)) { - PasspointConfiguration carrierConfig = - mPasspointManager.createEphemeralPasspointConfigForCarrier( - eapMethod); - if (carrierConfig != null) { - mPasspointManager.installEphemeralPasspointConfigForCarrier(carrierConfig); - } - } - } + createEphemeralProfileForMatchingAp(filteredScanDetails); // Go through each ScanDetail and find the best provider for each ScanDetail. List<PasspointNetworkCandidate> candidateList = new ArrayList<>(); @@ -190,6 +174,41 @@ public class PasspointNetworkEvaluator implements WifiNetworkSelector.NetworkEva } /** + * Creates an ephemeral Passpoint profile if it finds a matching Passpoint AP for MCC/MNC + * of the current MNO carrier on the device. + */ + private void createEphemeralProfileForMatchingAp(List<ScanDetail> filteredScanDetails) { + TelephonyManager telephonyManager = getTelephonyManager(); + if (telephonyManager == null) { + return; + } + if (TelephonyUtil.getCarrierType(telephonyManager) != TelephonyUtil.CARRIER_MNO_TYPE) { + return; + } + if (!mCarrierNetworkConfig.isCarrierEncryptionInfoAvailable()) { + return; + } + String mccMnc = telephonyManager + .createForSubscriptionId(SubscriptionManager.getDefaultDataSubscriptionId()) + .getSimOperator(); + if (mPasspointManager.hasCarrierProvider(mccMnc)) { + return; + } + int eapMethod = + mPasspointManager.findEapMethodFromNAIRealmMatchedWithCarrier(filteredScanDetails); + if (!isCarrierEapMethod(eapMethod)) { + return; + } + PasspointConfiguration carrierConfig = + mPasspointManager.createEphemeralPasspointConfigForCarrier(eapMethod); + if (carrierConfig == null) { + return; + } + + mPasspointManager.installEphemeralPasspointConfigForCarrier(carrierConfig); + } + + /** * Create and return a WifiConfiguration for the given ScanDetail and PasspointProvider. * The newly created WifiConfiguration will also be added to WifiConfigManager. * diff --git a/service/java/com/android/server/wifi/hotspot2/SystemInfo.java b/service/java/com/android/server/wifi/hotspot2/SystemInfo.java index d6e37fd07..fe675c6f5 100644 --- a/service/java/com/android/server/wifi/hotspot2/SystemInfo.java +++ b/service/java/com/android/server/wifi/hotspot2/SystemInfo.java @@ -20,6 +20,7 @@ import android.annotation.NonNull; import android.content.Context; import android.os.Build; import android.os.SystemProperties; +import android.telephony.SubscriptionManager; import android.telephony.TelephonyManager; import android.text.TextUtils; @@ -42,6 +43,7 @@ public class SystemInfo { @VisibleForTesting SystemInfo(Context context, WifiNative wifiNative) { + // TODO(b/132188983): inject this using WifiInjector mTelephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); mWifiNative = wifiNative; } @@ -98,14 +100,16 @@ public class SystemInfo { * @return String representing device ID */ public String getDeviceId() { + TelephonyManager defaultDataTm = mTelephonyManager.createForSubscriptionId( + SubscriptionManager.getDefaultDataSubscriptionId()); // IMEI will be provided for GSM SIM. - String imei = mTelephonyManager.getImei(); + String imei = defaultDataTm.getImei(); if (!TextUtils.isEmpty(imei)) { return imei; } // MEID will be provided for CMDA SIM. - String meid = mTelephonyManager.getMeid(); + String meid = defaultDataTm.getMeid(); if (!TextUtils.isEmpty(meid)) { return meid; } diff --git a/service/java/com/android/server/wifi/hotspot2/omadm/DevDetailMo.java b/service/java/com/android/server/wifi/hotspot2/omadm/DevDetailMo.java index 6c93df4f2..4f0152d17 100644 --- a/service/java/com/android/server/wifi/hotspot2/omadm/DevDetailMo.java +++ b/service/java/com/android/server/wifi/hotspot2/omadm/DevDetailMo.java @@ -19,6 +19,7 @@ package com.android.server.wifi.hotspot2.omadm; import android.annotation.NonNull; import android.content.Context; import android.net.wifi.EAPConstants; +import android.telephony.SubscriptionManager; import android.telephony.TelephonyManager; import android.text.TextUtils; import android.util.Log; @@ -163,8 +164,6 @@ public class DevDetailMo { return null; } - TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService( - Context.TELEPHONY_SERVICE); // Create the XML document for DevInfoMo Document doc = moSerializer.createNewDocument(); Element rootElement = moSerializer.createMgmtTree(doc); @@ -207,7 +206,11 @@ public class DevDetailMo { redirectUri)); wifiNode.appendChild(moSerializer.createNodeForValue(doc, TAG_WIFI_MAC_ADDR, macAddress)); - String imsi = telephonyManager.getSubscriberId(); + // TODO(b/132188983): Inject this using WifiInjector + TelephonyManager telephonyManager = context.getSystemService(TelephonyManager.class); + String imsi = telephonyManager + .createForSubscriptionId(SubscriptionManager.getDefaultDataSubscriptionId()) + .getSubscriberId(); if (imsi != null && sAllowToSendImsiImeiInfo) { // Don't provide the IMSI to an SP that did not issue the IMSI wifiNode.appendChild(moSerializer.createNodeForValue(doc, TAG_IMSI, imsi)); diff --git a/service/java/com/android/server/wifi/util/TelephonyUtil.java b/service/java/com/android/server/wifi/util/TelephonyUtil.java index 80cadc0af..abaeabe44 100644 --- a/service/java/com/android/server/wifi/util/TelephonyUtil.java +++ b/service/java/com/android/server/wifi/util/TelephonyUtil.java @@ -24,6 +24,7 @@ import android.annotation.NonNull; import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiEnterpriseConfig; import android.telephony.ImsiEncryptionInfo; +import android.telephony.SubscriptionManager; import android.telephony.TelephonyManager; import android.util.Base64; import android.util.Log; @@ -46,6 +47,8 @@ import javax.crypto.NoSuchPaddingException; /** * Utilities for the Wifi Service to interact with telephony. + * TODO(b/132188983): Refactor into TelephonyFacade which owns all instances of + * TelephonyManager/SubscriptionManager in Wifi */ public class TelephonyUtil { public static final String TAG = "TelephonyUtil"; @@ -95,15 +98,17 @@ public class TelephonyUtil { Log.e(TAG, "No valid TelephonyManager"); return null; } + TelephonyManager defaultDataTm = tm.createForSubscriptionId( + SubscriptionManager.getDefaultDataSubscriptionId()); if (carrierNetworkConfig == null) { Log.e(TAG, "No valid CarrierNetworkConfig"); return null; } - String imsi = tm.getSubscriberId(); + String imsi = defaultDataTm.getSubscriberId(); String mccMnc = ""; - if (tm.getSimState() == TelephonyManager.SIM_STATE_READY) { - mccMnc = tm.getSimOperator(); + if (defaultDataTm.getSimState() == TelephonyManager.SIM_STATE_READY) { + mccMnc = defaultDataTm.getSimOperator(); } String identity = buildIdentity(getSimMethodForConfig(config), imsi, mccMnc, false); @@ -114,7 +119,8 @@ public class TelephonyUtil { ImsiEncryptionInfo imsiEncryptionInfo; try { - imsiEncryptionInfo = tm.getCarrierInfoForImsiEncryption(TelephonyManager.KEY_TYPE_WLAN); + imsiEncryptionInfo = defaultDataTm.getCarrierInfoForImsiEncryption( + TelephonyManager.KEY_TYPE_WLAN); } catch (RuntimeException e) { Log.e(TAG, "Failed to get imsi encryption info: " + e.getMessage()); return null; @@ -154,10 +160,15 @@ public class TelephonyUtil { * not ready or absent. */ public static String getAnonymousIdentityWith3GppRealm(@Nonnull TelephonyManager tm) { - if (tm == null || tm.getSimState() != TelephonyManager.SIM_STATE_READY) { + if (tm == null) { + return null; + } + TelephonyManager defaultDataTm = tm.createForSubscriptionId( + SubscriptionManager.getDefaultDataSubscriptionId()); + if (defaultDataTm.getSimState() != TelephonyManager.SIM_STATE_READY) { return null; } - String mccMnc = tm.getSimOperator(); + String mccMnc = defaultDataTm.getSimOperator(); if (mccMnc == null || mccMnc.isEmpty()) { return null; } @@ -518,6 +529,8 @@ public class TelephonyUtil { Log.e(TAG, "No valid TelephonyManager"); return null; } + TelephonyManager defaultDataTm = tm.createForSubscriptionId( + SubscriptionManager.getDefaultDataSubscriptionId()); StringBuilder sb = new StringBuilder(); for (String challenge : requestData) { if (challenge == null || challenge.isEmpty()) { @@ -535,8 +548,8 @@ public class TelephonyUtil { String base64Challenge = Base64.encodeToString(rand, Base64.NO_WRAP); - String tmResponse = tm.getIccAuthentication(appType, - TelephonyManager.AUTHTYPE_EAP_SIM, base64Challenge); + String tmResponse = defaultDataTm.getIccAuthentication( + appType, TelephonyManager.AUTHTYPE_EAP_SIM, base64Challenge); Log.v(TAG, "Raw Response - " + tmResponse); if (tmResponse == null || tmResponse.length() <= 4) { @@ -589,6 +602,8 @@ public class TelephonyUtil { Log.e(TAG, "No valid TelephonyManager"); return null; } + TelephonyManager defaultDataTm = tm.createForSubscriptionId( + SubscriptionManager.getDefaultDataSubscriptionId()); StringBuilder sb = new StringBuilder(); for (String challenge : requestData) { if (challenge == null || challenge.isEmpty()) { @@ -606,7 +621,7 @@ public class TelephonyUtil { String base64Challenge = Base64.encodeToString(rand, Base64.NO_WRAP); - String tmResponse = tm.getIccAuthentication(TelephonyManager.APPTYPE_SIM, + String tmResponse = defaultDataTm.getIccAuthentication(TelephonyManager.APPTYPE_SIM, TelephonyManager.AUTHTYPE_EAP_SIM, base64Challenge); Log.v(TAG, "Raw Response - " + tmResponse); @@ -685,8 +700,10 @@ public class TelephonyUtil { if (rand != null && authn != null) { String base64Challenge = Base64.encodeToString(concatHex(rand, authn), Base64.NO_WRAP); if (tm != null) { - tmResponse = tm.getIccAuthentication(TelephonyManager.APPTYPE_USIM, - TelephonyManager.AUTHTYPE_EAP_AKA, base64Challenge); + tmResponse = tm + .createForSubscriptionId(SubscriptionManager.getDefaultDataSubscriptionId()) + .getIccAuthentication(TelephonyManager.APPTYPE_USIM, + TelephonyManager.AUTHTYPE_EAP_AKA, base64Challenge); Log.v(TAG, "Raw Response - " + tmResponse); } else { Log.e(TAG, "No valid TelephonyManager"); @@ -741,12 +758,18 @@ public class TelephonyUtil { * ready or {@code tm} is {@code null} */ public static int getCarrierType(@NonNull TelephonyManager tm) { - if (tm == null || tm.getSimState() != TelephonyManager.SIM_STATE_READY) { + if (tm == null) { + return CARRIER_INVALID_TYPE; + } + TelephonyManager defaultDataTm = tm.createForSubscriptionId( + SubscriptionManager.getDefaultDataSubscriptionId()); + + if (defaultDataTm.getSimState() != TelephonyManager.SIM_STATE_READY) { return CARRIER_INVALID_TYPE; } // If two APIs return the same carrier ID, then is considered as MNO, otherwise MVNO - if (tm.getCarrierIdFromSimMccMnc() == tm.getSimCarrierId()) { + if (defaultDataTm.getCarrierIdFromSimMccMnc() == defaultDataTm.getSimCarrierId()) { return CARRIER_MNO_TYPE; } return CARRIER_MVNO_TYPE; |