diff options
author | Nate Jiang <qiangjiang@google.com> | 2020-04-09 18:34:09 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2020-04-09 18:34:09 +0000 |
commit | e75e4299ad619f0150fc52fa4ea56cd88e0a91b9 (patch) | |
tree | cd64f87a21abbbed8a63e00f25c69b4c43296833 /service | |
parent | 1a1b2b8f0fa7231f76136632e4bdc8b674fbdb02 (diff) | |
parent | be30bfa05fcc465cf2f37a75ef0b5fbbd058d1b1 (diff) |
Merge changes from topic "IMSINotification" into rvc-dev
* changes:
Move IMSI notification to WifiCarrierInfoManager
Rename TelephonyUtils to WifiCarrierInfoManager
Diffstat (limited to 'service')
15 files changed, 468 insertions, 355 deletions
diff --git a/service/java/com/android/server/wifi/ClientModeImpl.java b/service/java/com/android/server/wifi/ClientModeImpl.java index 96a2bf971..4ca7716c9 100644 --- a/service/java/com/android/server/wifi/ClientModeImpl.java +++ b/service/java/com/android/server/wifi/ClientModeImpl.java @@ -115,6 +115,8 @@ import com.android.internal.util.Protocol; import com.android.internal.util.State; import com.android.internal.util.StateMachine; import com.android.server.wifi.MboOceController.BtmFrameData; +import com.android.server.wifi.WifiCarrierInfoManager.SimAuthRequestData; +import com.android.server.wifi.WifiCarrierInfoManager.SimAuthResponseData; import com.android.server.wifi.hotspot2.AnqpEvent; import com.android.server.wifi.hotspot2.IconEvent; import com.android.server.wifi.hotspot2.NetworkDetail; @@ -130,9 +132,6 @@ import com.android.server.wifi.util.ExternalCallbackTracker; import com.android.server.wifi.util.NativeUtil; import com.android.server.wifi.util.RssiUtil; import com.android.server.wifi.util.ScanResultUtil; -import com.android.server.wifi.util.TelephonyUtil; -import com.android.server.wifi.util.TelephonyUtil.SimAuthRequestData; -import com.android.server.wifi.util.TelephonyUtil.SimAuthResponseData; import com.android.server.wifi.util.WifiPermissionsUtil; import com.android.server.wifi.util.WifiPermissionsWrapper; import com.android.wifi.resources.R; @@ -722,7 +721,7 @@ public class ClientModeImpl extends StateMachine { private final BatteryStatsManager mBatteryStatsManager; - private final TelephonyUtil mTelephonyUtil; + private final WifiCarrierInfoManager mWifiCarrierInfoManager; // Used for debug and stats gathering @@ -751,7 +750,8 @@ public class ClientModeImpl extends StateMachine { BatteryStatsManager batteryStatsManager, SupplicantStateTracker supplicantStateTracker, MboOceController mboOceController, - TelephonyUtil telephonyUtil, EapFailureNotifier eapFailureNotifier, + WifiCarrierInfoManager wifiCarrierInfoManager, + EapFailureNotifier eapFailureNotifier, SimRequiredNotifier simRequiredNotifier) { super(TAG, looper); mWifiInjector = wifiInjector; @@ -771,7 +771,7 @@ public class ClientModeImpl extends StateMachine { mWifiTrafficPoller = wifiTrafficPoller; mLinkProbeManager = linkProbeManager; mMboOceController = mboOceController; - mTelephonyUtil = telephonyUtil; + mWifiCarrierInfoManager = wifiCarrierInfoManager; mNetworkAgentState = DetailedState.DISCONNECTED; mBatteryStatsManager = batteryStatsManager; @@ -3930,7 +3930,7 @@ public class ClientModeImpl extends StateMachine { && mTargetWifiConfiguration.enterpriseConfig .isAuthenticationSimBased()) { // Pair<identity, encrypted identity> - Pair<String, String> identityPair = mTelephonyUtil + Pair<String, String> identityPair = mWifiCarrierInfoManager .getSimIdentity(mTargetWifiConfiguration); Log.i(TAG, "SUP_REQUEST_IDENTITY: identityPair=[" + ((identityPair.first.length() >= 7) @@ -4164,15 +4164,15 @@ public class ClientModeImpl extends StateMachine { // We need to get the updated pseudonym from supplicant for EAP-SIM/AKA/AKA' if (config.enterpriseConfig != null && config.enterpriseConfig.isAuthenticationSimBased()) { - mLastSubId = mTelephonyUtil.getBestMatchSubscriptionId(config); + mLastSubId = mWifiCarrierInfoManager.getBestMatchSubscriptionId(config); mLastSimBasedConnectionCarrierName = - mTelephonyUtil.getCarrierNameforSubId(mLastSubId); + mWifiCarrierInfoManager.getCarrierNameforSubId(mLastSubId); String anonymousIdentity = mWifiNative.getEapAnonymousIdentity(mInterfaceName); if (!TextUtils.isEmpty(anonymousIdentity) - && !TelephonyUtil + && !WifiCarrierInfoManager .isAnonymousAtRealmIdentity(anonymousIdentity)) { - String decoratedPseudonym = mTelephonyUtil + String decoratedPseudonym = mWifiCarrierInfoManager .decoratePseudonymWith3GppRealm(config, anonymousIdentity); if (decoratedPseudonym != null) { @@ -4488,7 +4488,7 @@ public class ClientModeImpl extends StateMachine { case WifiEnterpriseConfig.Eap.AKA: case WifiEnterpriseConfig.Eap.AKA_PRIME: if (errorCode == WifiNative.EAP_SIM_VENDOR_SPECIFIC_CERT_EXPIRED) { - mTelephonyUtil.resetCarrierKeysForImsiEncryption(targetedNetwork); + mWifiCarrierInfoManager.resetCarrierKeysForImsiEncryption(targetedNetwork); } break; @@ -4933,7 +4933,7 @@ public class ClientModeImpl extends StateMachine { && config.carrierId != TelephonyManager.UNKNOWN_CARRIER_ID) || (config.enterpriseConfig != null && config.enterpriseConfig.isAuthenticationSimBased() - && !mTelephonyUtil.isSimPresent(mLastSubId))) { + && !mWifiCarrierInfoManager.isSimPresent(mLastSubId))) { mWifiMetrics.logStaEvent(StaEvent.TYPE_FRAMEWORK_DISCONNECT, StaEvent.DISCONNECT_RESET_SIM_NETWORKS); // remove local PMKSA cache in framework @@ -5741,15 +5741,15 @@ public class ClientModeImpl extends StateMachine { * 3. 3GPP TS 11.11 2G_authentication [RAND] * [SRES][Cipher Key Kc] */ - String response = mTelephonyUtil + String response = mWifiCarrierInfoManager .getGsmSimAuthResponse(requestData.data, mTargetWifiConfiguration); if (response == null) { // In case of failure, issue may be due to sim type, retry as No.2 case - response = mTelephonyUtil + response = mWifiCarrierInfoManager .getGsmSimpleSimAuthResponse(requestData.data, mTargetWifiConfiguration); if (response == null) { // In case of failure, issue may be due to sim type, retry as No.3 case - response = mTelephonyUtil.getGsmSimpleSimNoLengthAuthResponse( + response = mWifiCarrierInfoManager.getGsmSimpleSimNoLengthAuthResponse( requestData.data, mTargetWifiConfiguration); } } @@ -5772,7 +5772,7 @@ public class ClientModeImpl extends StateMachine { return; } - SimAuthResponseData response = mTelephonyUtil + SimAuthResponseData response = mWifiCarrierInfoManager .get3GAuthResponse(requestData, mTargetWifiConfiguration); if (response != null) { mWifiNative.simAuthResponse( @@ -6338,10 +6338,10 @@ public class ClientModeImpl extends StateMachine { if (config.enterpriseConfig != null && config.enterpriseConfig.isAuthenticationSimBased() - && mTelephonyUtil.isImsiEncryptionInfoAvailable( - mTelephonyUtil.getBestMatchSubscriptionId(config)) + && mWifiCarrierInfoManager.isImsiEncryptionInfoAvailable( + mWifiCarrierInfoManager.getBestMatchSubscriptionId(config)) && TextUtils.isEmpty(config.enterpriseConfig.getAnonymousIdentity())) { - String anonAtRealm = mTelephonyUtil + String anonAtRealm = mWifiCarrierInfoManager .getAnonymousIdentityWith3GppRealm(config); // Use anonymous@<realm> when pseudonym is not available config.enterpriseConfig.setAnonymousIdentity(anonAtRealm); diff --git a/service/java/com/android/server/wifi/EapFailureNotifier.java b/service/java/com/android/server/wifi/EapFailureNotifier.java index 3cc80b982..fe4cfbd66 100644 --- a/service/java/com/android/server/wifi/EapFailureNotifier.java +++ b/service/java/com/android/server/wifi/EapFailureNotifier.java @@ -32,7 +32,6 @@ import android.text.TextUtils; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.messages.nano.SystemMessageProto.SystemMessage; -import com.android.server.wifi.util.TelephonyUtil; /** * This class may be used to launch notifications when EAP failure occurs. @@ -45,17 +44,17 @@ public class EapFailureNotifier { private final WifiContext mContext; private final NotificationManager mNotificationManager; private final FrameworkFacade mFrameworkFacade; - private final TelephonyUtil mTelephonyUtil; + private final WifiCarrierInfoManager mWifiCarrierInfoManager; // Unique ID associated with the notification. public static final int NOTIFICATION_ID = SystemMessage.NOTE_WIFI_EAP_FAILURE; private String mCurrentShownSsid; public EapFailureNotifier(WifiContext context, FrameworkFacade frameworkFacade, - TelephonyUtil telephonyUtil) { + WifiCarrierInfoManager wifiCarrierInfoManager) { mContext = context; mFrameworkFacade = frameworkFacade; - mTelephonyUtil = telephonyUtil; + mWifiCarrierInfoManager = wifiCarrierInfoManager; mNotificationManager = mContext.getSystemService(NotificationManager.class); } @@ -74,7 +73,7 @@ public class EapFailureNotifier { } } Resources res = getResourcesForSubId(mContext, - mTelephonyUtil.getBestMatchSubscriptionId(config)); + mWifiCarrierInfoManager.getBestMatchSubscriptionId(config)); if (res == null) return; int resourceId = res.getIdentifier(ERROR_MESSAGE_OVERLAY_PREFIX + errorCode, "string", mContext.getWifiOverlayApkPkgName()); diff --git a/service/java/com/android/server/wifi/ImsiPrivacyProtectionExemptionStoreData.java b/service/java/com/android/server/wifi/ImsiPrivacyProtectionExemptionStoreData.java index acfba80c5..98664d0fc 100644 --- a/service/java/com/android/server/wifi/ImsiPrivacyProtectionExemptionStoreData.java +++ b/service/java/com/android/server/wifi/ImsiPrivacyProtectionExemptionStoreData.java @@ -172,8 +172,7 @@ public class ImsiPrivacyProtectionExemptionStoreData implements WifiConfigStore. @Override public int getStoreFileId() { - // Suggestion Store. - return WifiConfigStore.STORE_FILE_USER_NETWORK_SUGGESTIONS; + // User general store. + return WifiConfigStore.STORE_FILE_USER_GENERAL; } - } diff --git a/service/java/com/android/server/wifi/NetworkSuggestionNominator.java b/service/java/com/android/server/wifi/NetworkSuggestionNominator.java index c4fd6a908..fbc1f5fdb 100644 --- a/service/java/com/android/server/wifi/NetworkSuggestionNominator.java +++ b/service/java/com/android/server/wifi/NetworkSuggestionNominator.java @@ -24,7 +24,6 @@ import android.util.Pair; import com.android.server.wifi.WifiNetworkSuggestionsManager.ExtendedWifiNetworkSuggestion; import com.android.server.wifi.hotspot2.PasspointNetworkNominateHelper; -import com.android.server.wifi.util.TelephonyUtil; import java.util.ArrayList; import java.util.Arrays; @@ -54,16 +53,16 @@ public class NetworkSuggestionNominator implements WifiNetworkSelector.NetworkNo private final WifiConfigManager mWifiConfigManager; private final PasspointNetworkNominateHelper mPasspointNetworkNominateHelper; private final LocalLog mLocalLog; - private final TelephonyUtil mTelephonyUtil; + private final WifiCarrierInfoManager mWifiCarrierInfoManager; NetworkSuggestionNominator(WifiNetworkSuggestionsManager networkSuggestionsManager, WifiConfigManager wifiConfigManager, PasspointNetworkNominateHelper nominateHelper, - LocalLog localLog, TelephonyUtil telephonyUtil) { + LocalLog localLog, WifiCarrierInfoManager wifiCarrierInfoManager) { mWifiNetworkSuggestionsManager = networkSuggestionsManager; mWifiConfigManager = wifiConfigManager; mPasspointNetworkNominateHelper = nominateHelper; mLocalLog = localLog; - mTelephonyUtil = telephonyUtil; + mWifiCarrierInfoManager = wifiCarrierInfoManager; } @Override @@ -111,7 +110,7 @@ public class NetworkSuggestionNominator implements WifiNetworkSelector.NetworkNo } if (WifiConfiguration.isMetered(config, null) - && mTelephonyUtil.isCarrierNetworkFromNonDefaultDataSim(config)) { + && mWifiCarrierInfoManager.isCarrierNetworkFromNonDefaultDataSim(config)) { continue; } if (!isSimBasedNetworkAvailableToAutoConnect(config)) { @@ -152,7 +151,7 @@ public class NetworkSuggestionNominator implements WifiNetworkSelector.NetworkNo continue; } if (WifiConfiguration.isMetered(config, null) - && mTelephonyUtil.isCarrierNetworkFromNonDefaultDataSim(config)) { + && mWifiCarrierInfoManager.isCarrierNetworkFromNonDefaultDataSim(config)) { continue; } if (!ewns.isAutojoinEnabled @@ -214,13 +213,13 @@ public class NetworkSuggestionNominator implements WifiNetworkSelector.NetworkNo || !config.enterpriseConfig.isAuthenticationSimBased()) { return true; } - int subId = mTelephonyUtil.getBestMatchSubscriptionId(config); - if (!mTelephonyUtil.isSimPresent(subId)) { + int subId = mWifiCarrierInfoManager.getBestMatchSubscriptionId(config); + if (!mWifiCarrierInfoManager.isSimPresent(subId)) { mLocalLog.log("SIM is not present for subId: " + subId); return false; } - if (mTelephonyUtil.requiresImsiEncryption(subId)) { - return mTelephonyUtil.isImsiEncryptionInfoAvailable(subId); + if (mWifiCarrierInfoManager.requiresImsiEncryption(subId)) { + return mWifiCarrierInfoManager.isImsiEncryptionInfoAvailable(subId); } return true; } diff --git a/service/java/com/android/server/wifi/SavedNetworkNominator.java b/service/java/com/android/server/wifi/SavedNetworkNominator.java index dd4d45f90..cbc2c323e 100644 --- a/service/java/com/android/server/wifi/SavedNetworkNominator.java +++ b/service/java/com/android/server/wifi/SavedNetworkNominator.java @@ -23,7 +23,6 @@ import android.util.LocalLog; import android.util.Pair; import com.android.server.wifi.hotspot2.PasspointNetworkNominateHelper; -import com.android.server.wifi.util.TelephonyUtil; import java.util.List; @@ -35,16 +34,16 @@ public class SavedNetworkNominator implements WifiNetworkSelector.NetworkNominat private static final String NAME = "SavedNetworkNominator"; private final WifiConfigManager mWifiConfigManager; private final LocalLog mLocalLog; - private final TelephonyUtil mTelephonyUtil; + private final WifiCarrierInfoManager mWifiCarrierInfoManager; private final PasspointNetworkNominateHelper mPasspointNetworkNominateHelper; SavedNetworkNominator(WifiConfigManager configManager, PasspointNetworkNominateHelper nominateHelper, - LocalLog localLog, TelephonyUtil telephonyUtil) { + LocalLog localLog, WifiCarrierInfoManager wifiCarrierInfoManager) { mWifiConfigManager = configManager; mPasspointNetworkNominateHelper = nominateHelper; mLocalLog = localLog; - mTelephonyUtil = telephonyUtil; + mWifiCarrierInfoManager = wifiCarrierInfoManager; } private void localLog(String log) { @@ -138,8 +137,8 @@ public class SavedNetworkNominator implements WifiNetworkSelector.NetworkNominat continue; } else if (network.enterpriseConfig != null && network.enterpriseConfig.isAuthenticationSimBased()) { - int subId = mTelephonyUtil.getBestMatchSubscriptionId(network); - if (!mTelephonyUtil.isSimPresent(subId)) { + int subId = mWifiCarrierInfoManager.getBestMatchSubscriptionId(network); + if (!mWifiCarrierInfoManager.isSimPresent(subId)) { // Don't select if security type is EAP SIM/AKA/AKA' when SIM is not present. localLog("No SIM card is good for Network " + WifiNetworkSelector.toNetworkString(network)); @@ -147,7 +146,7 @@ public class SavedNetworkNominator implements WifiNetworkSelector.NetworkNominat } // Ignore metered network with non-data Sim, ignore. if (WifiConfiguration.isMetered(network, null) - && mTelephonyUtil.isCarrierNetworkFromNonDefaultDataSim(network)) { + && mWifiCarrierInfoManager.isCarrierNetworkFromNonDefaultDataSim(network)) { continue; } } @@ -173,7 +172,7 @@ public class SavedNetworkNominator implements WifiNetworkSelector.NetworkNominat WifiConfiguration config = candidate.second; // Ignore metered network with non-data Sim, ignore. if (WifiConfiguration.isMetered(config, null) - && mTelephonyUtil.isCarrierNetworkFromNonDefaultDataSim(config)) { + && mWifiCarrierInfoManager.isCarrierNetworkFromNonDefaultDataSim(config)) { continue; } onConnectableListener.onConnectable(candidate.first, config); diff --git a/service/java/com/android/server/wifi/util/TelephonyUtil.java b/service/java/com/android/server/wifi/WifiCarrierInfoManager.java index b7b2d9e13..63786f920 100644 --- a/service/java/com/android/server/wifi/util/TelephonyUtil.java +++ b/service/java/com/android/server/wifi/WifiCarrierInfoManager.java @@ -14,14 +14,20 @@ * limitations under the License. */ -package com.android.server.wifi.util; +package com.android.server.wifi; import android.annotation.NonNull; +import android.app.AlertDialog; +import android.app.Notification; +import android.app.NotificationManager; +import android.app.PendingIntent; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; +import android.content.res.Resources; import android.database.ContentObserver; +import android.graphics.drawable.Icon; import android.net.Uri; import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiEnterpriseConfig; @@ -39,19 +45,21 @@ import android.util.Base64; import android.util.Log; import android.util.Pair; import android.util.SparseBooleanArray; +import android.view.WindowManager; import com.android.internal.annotations.VisibleForTesting; -import com.android.server.wifi.FrameworkFacade; -import com.android.server.wifi.IMSIParameter; -import com.android.server.wifi.WifiNative; +import com.android.internal.messages.nano.SystemMessageProto; +import com.android.wifi.resources.R; import java.io.FileDescriptor; import java.io.PrintWriter; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; import java.security.PublicKey; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.Map; import javax.annotation.Nullable; import javax.crypto.BadPaddingException; @@ -60,12 +68,12 @@ import javax.crypto.IllegalBlockSizeException; import javax.crypto.NoSuchPaddingException; /** - * Utilities for the Wifi Service to interact with telephony. + * This class provide APIs to get carrier info from telephony service. * TODO(b/132188983): Refactor into TelephonyFacade which owns all instances of * TelephonyManager/SubscriptionManager in Wifi */ -public class TelephonyUtil { - public static final String TAG = "TelephonyUtil"; +public class WifiCarrierInfoManager { + public static final String TAG = "WifiCarrierInfoManager"; public static final String DEFAULT_EAP_PREFIX = "\0"; public static final int CARRIER_INVALID_TYPE = -1; @@ -73,6 +81,24 @@ public class TelephonyUtil { public static final int CARRIER_MVNO_TYPE = 1; // Mobile Virtual Network Operator public static final String ANONYMOUS_IDENTITY = "anonymous"; public static final String THREE_GPP_NAI_REALM_FORMAT = "wlan.mnc%s.mcc%s.3gppnetwork.org"; + /** Intent when user tapped action button to allow the app. */ + @VisibleForTesting + public static final String NOTIFICATION_USER_ALLOWED_CARRIER_INTENT_ACTION = + "com.android.server.wifi.action.CarrierNetwork.USER_ALLOWED_CARRIER"; + /** Intent when user tapped action button to disallow the app. */ + @VisibleForTesting + public static final String NOTIFICATION_USER_DISALLOWED_CARRIER_INTENT_ACTION = + "com.android.server.wifi.action.CarrierNetwork.USER_DISALLOWED_CARRIER"; + /** Intent when user dismissed the notification. */ + @VisibleForTesting + public static final String NOTIFICATION_USER_DISMISSED_INTENT_ACTION = + "com.android.server.wifi.action.CarrierNetwork.USER_DISMISSED"; + @VisibleForTesting + public static final String EXTRA_CARRIER_NAME = + "com.android.server.wifi.extra.CarrierNetwork.CARRIER_NAME"; + @VisibleForTesting + public static final String EXTRA_CARRIER_ID = + "com.android.server.wifi.extra.CarrierNetwork.CARRIER_ID"; // IMSI encryption method: RSA-OAEP with SHA-256 hash function private static final String IMSI_CIPHER_TRANSFORMATION = @@ -97,27 +123,156 @@ public class TelephonyUtil { private static final Uri CONTENT_URI = Uri.parse("content://carrier_information/carrier"); + private final WifiContext mContext; + private final Handler mHandler; + private final WifiInjector mWifiInjector; + private final Resources mResources; private final TelephonyManager mTelephonyManager; private final SubscriptionManager mSubscriptionManager; + private final NotificationManager mNotificationManager; + + /** + * Intent filter for processing notification actions. + */ + private final IntentFilter mIntentFilter; + private final FrameworkFacade mFrameworkFacade; private boolean mVerboseLogEnabled = false; private SparseBooleanArray mImsiEncryptionRequired = new SparseBooleanArray(); private SparseBooleanArray mImsiEncryptionInfoAvailable = new SparseBooleanArray(); private SparseBooleanArray mEapMethodPrefixEnable = new SparseBooleanArray(); + private final Map<Integer, Boolean> mImsiPrivacyProtectionExemptionMap = new HashMap<>(); + private final List<OnUserApproveCarrierListener> + mOnUserApproveCarrierListeners = + new ArrayList<>(); + + private boolean mUserApprovalUiActive; + private boolean mHasNewDataToSerialize; + + /** + * Interface for other modules to listen to the user approve IMSI protection exemption. + */ + public interface OnUserApproveCarrierListener { + + /** + * Invoke when user approve the IMSI protection exemption. + */ + void onUserAllowed(int carrierId); + } + + /** + * Module to interact with the wifi config store. + */ + private class ImsiProtectionExemptionDataSource implements + ImsiPrivacyProtectionExemptionStoreData.DataSource { + @Override + public Map<Integer, Boolean> toSerialize() { + // Clear the flag after writing to disk. + // TODO(b/115504887): Don't reset the flag on write failure. + mHasNewDataToSerialize = false; + return mImsiPrivacyProtectionExemptionMap; + } + + @Override + public void fromDeserialized(Map<Integer, Boolean> imsiProtectionExemptionMap) { + mImsiPrivacyProtectionExemptionMap.putAll(imsiProtectionExemptionMap); + } + + @Override + public void reset() { + mImsiPrivacyProtectionExemptionMap.clear(); + } + + @Override + public boolean hasNewDataToSerialize() { + return mHasNewDataToSerialize; + } + } + + private final BroadcastReceiver mBroadcastReceiver = + new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + String carrierName = intent.getStringExtra(EXTRA_CARRIER_NAME); + int carrierId = intent.getIntExtra(EXTRA_CARRIER_ID, -1); + if (carrierName == null || carrierId == -1) { + Log.e(TAG, "No carrier name or carrier id found in intent"); + return; + } + + switch (intent.getAction()) { + case NOTIFICATION_USER_ALLOWED_CARRIER_INTENT_ACTION: + Log.i(TAG, "User clicked to allow carrier"); + sendImsiPrivacyConfirmationDialog(carrierName, carrierId); + // Collapse the notification bar + mContext.sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)); + break; + case NOTIFICATION_USER_DISALLOWED_CARRIER_INTENT_ACTION: + handleUserDisallowCarrierExemptionAction(carrierName, carrierId); + break; + case NOTIFICATION_USER_DISMISSED_INTENT_ACTION: + handleUserDismissAction(); + return; // no need to cancel a dismissed notification, return. + default: + Log.e(TAG, "Unknown action " + intent.getAction()); + return; + } + // Clear notification once the user interacts with it. + mNotificationManager.cancel(SystemMessageProto + .SystemMessage.NOTE_NETWORK_SUGGESTION_AVAILABLE); + } + }; + private void handleUserDismissAction() { + Log.i(TAG, "User dismissed the notification"); + mUserApprovalUiActive = false; + } + + private void handleUserAllowCarrierExemptionAction(String carrierName, int carrierId) { + Log.i(TAG, "User clicked to allow carrier:" + carrierName); + setHasUserApprovedImsiPrivacyExemptionForCarrier(true, carrierId); + mUserApprovalUiActive = false; + } + + private void handleUserDisallowCarrierExemptionAction(String carrierName, int carrierId) { + Log.i(TAG, "User clicked to disallow carrier:" + carrierName); + setHasUserApprovedImsiPrivacyExemptionForCarrier(false, carrierId); + mUserApprovalUiActive = false; + } /** - * Gets the instance of TelephonyUtil. + * Gets the instance of WifiCarrierInfoManager. * @param telephonyManager Instance of {@link TelephonyManager} * @param subscriptionManager Instance of {@link SubscriptionManager} - * @return The instance of TelephonyUtil + * @param WifiInjector Instance of {@link WifiInjector} + * @return The instance of WifiCarrierInfoManager */ - public TelephonyUtil(@NonNull TelephonyManager telephonyManager, + public WifiCarrierInfoManager(@NonNull TelephonyManager telephonyManager, @NonNull SubscriptionManager subscriptionManager, + @NonNull WifiInjector wifiInjector, @NonNull FrameworkFacade frameworkFacade, - @NonNull Context context, + @NonNull WifiContext context, + @NonNull WifiConfigStore configStore, @NonNull Handler handler) { mTelephonyManager = telephonyManager; + mContext = context; + mResources = mContext.getResources(); + mWifiInjector = wifiInjector; + mHandler = handler; mSubscriptionManager = subscriptionManager; + mFrameworkFacade = frameworkFacade; + + mNotificationManager = + (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); + // Register broadcast receiver for UI interactions. + mIntentFilter = new IntentFilter(); + mIntentFilter.addAction(NOTIFICATION_USER_DISMISSED_INTENT_ACTION); + mIntentFilter.addAction(NOTIFICATION_USER_ALLOWED_CARRIER_INTENT_ACTION); + mIntentFilter.addAction(NOTIFICATION_USER_DISALLOWED_CARRIER_INTENT_ACTION); + mUserApprovalUiActive = false; + + mContext.registerReceiver(mBroadcastReceiver, mIntentFilter, null, handler); + configStore.registerStoreData(wifiInjector.makeImsiProtectionExemptionStoreData( + new ImsiProtectionExemptionDataSource())); updateImsiEncryptionInfo(context); @@ -552,7 +707,7 @@ public class TelephonyUtil { */ public static boolean isAnonymousAtRealmIdentity(String identity) { if (TextUtils.isEmpty(identity)) return false; - final String anonymousId = TelephonyUtil.ANONYMOUS_IDENTITY + "@"; + final String anonymousId = WifiCarrierInfoManager.ANONYMOUS_IDENTITY + "@"; return identity.startsWith(anonymousId) || identity.substring(1).startsWith(anonymousId); } @@ -1184,4 +1339,166 @@ public class TelephonyUtil { int subId = getMatchingSubId(config.carrierId); return subId != SubscriptionManager.getDefaultDataSubscriptionId(); } + + /** + * Add a listener to monitor user approval IMSI protection exemption. + */ + public void addImsiExemptionUserApprovalListener( + OnUserApproveCarrierListener listener) { + mOnUserApproveCarrierListeners.add(listener); + } + + /** + * Clear the Imsi Privacy Exemption user approval info the target carrier. + */ + public void clearImsiPrivacyExemptionForCarrier(int carrierId) { + mImsiPrivacyProtectionExemptionMap.remove(carrierId); + saveToStore(); + } + + /** + * Check if carrier have user approved exemption for IMSI protection + */ + public boolean hasUserApprovedImsiPrivacyExemptionForCarrier(int carrierId) { + return mImsiPrivacyProtectionExemptionMap.getOrDefault(carrierId, false); + } + + /** + * Enable or disable exemption on IMSI protection. + */ + public void setHasUserApprovedImsiPrivacyExemptionForCarrier(boolean approved, int carrierId) { + if (mVerboseLogEnabled) { + Log.v(TAG, "Setting Imsi privacy exemption for carrier " + carrierId + + (approved ? " approved" : " not approved")); + } + mImsiPrivacyProtectionExemptionMap.put(carrierId, approved); + // If user approved the exemption restore to initial auto join configure. + if (approved) { + for (OnUserApproveCarrierListener listener : mOnUserApproveCarrierListeners) { + listener.onUserAllowed(carrierId); + } + } + saveToStore(); + } + + private void sendImsiPrivacyNotification(int carrierId) { + String carrierName = getCarrierNameforSubId(getMatchingSubId(carrierId)); + Notification.Action userAllowAppNotificationAction = + new Notification.Action.Builder(null, + mResources.getText(R.string + .wifi_suggestion_action_allow_imsi_privacy_exemption_carrier), + getPrivateBroadcast(NOTIFICATION_USER_ALLOWED_CARRIER_INTENT_ACTION, + Pair.create(EXTRA_CARRIER_NAME, carrierName), + Pair.create(EXTRA_CARRIER_ID, carrierId))) + .build(); + Notification.Action userDisallowAppNotificationAction = + new Notification.Action.Builder(null, + mResources.getText(R.string + .wifi_suggestion_action_disallow_imsi_privacy_exemption_carrier), + getPrivateBroadcast(NOTIFICATION_USER_DISALLOWED_CARRIER_INTENT_ACTION, + Pair.create(EXTRA_CARRIER_NAME, carrierName), + Pair.create(EXTRA_CARRIER_ID, carrierId))) + .build(); + + Notification notification = mFrameworkFacade.makeNotificationBuilder( + mContext, WifiService.NOTIFICATION_NETWORK_STATUS) + .setSmallIcon(Icon.createWithResource(mContext.getWifiOverlayApkPkgName(), + com.android.wifi.resources.R.drawable.stat_notify_wifi_in_range)) + .setTicker(mResources.getString( + R.string.wifi_suggestion_imsi_privacy_title, carrierName)) + .setContentTitle(mResources.getString( + R.string.wifi_suggestion_imsi_privacy_title, carrierName)) + .setStyle(new Notification.BigTextStyle() + .bigText(mResources.getString( + R.string.wifi_suggestion_imsi_privacy_content))) + .setDeleteIntent(getPrivateBroadcast(NOTIFICATION_USER_DISMISSED_INTENT_ACTION, + Pair.create(EXTRA_CARRIER_NAME, carrierName), + Pair.create(EXTRA_CARRIER_ID, carrierId))) + .setShowWhen(false) + .setLocalOnly(true) + .setColor(mResources.getColor(android.R.color.system_notification_accent_color, + mContext.getTheme())) + .addAction(userDisallowAppNotificationAction) + .addAction(userAllowAppNotificationAction) + .build(); + + // Post the notification. + mNotificationManager.notify( + SystemMessageProto.SystemMessage.NOTE_NETWORK_SUGGESTION_AVAILABLE, notification); + mUserApprovalUiActive = true; + } + + private void sendImsiPrivacyConfirmationDialog(@NonNull String carrierName, int carrierId) { + AlertDialog dialog = mFrameworkFacade.makeAlertDialogBuilder(mContext) + .setTitle(mResources.getString( + R.string.wifi_suggestion_imsi_privacy_exemption_confirmation_title)) + .setMessage(mResources.getString( + R.string.wifi_suggestion_imsi_privacy_exemption_confirmation_content, + carrierName)) + .setPositiveButton(mResources.getText( + R.string.wifi_suggestion_action_allow_imsi_privacy_exemption_confirmation), + (d, which) -> mHandler.post( + () -> handleUserAllowCarrierExemptionAction( + carrierName, carrierId))) + .setNegativeButton(mResources.getText( + R.string.wifi_suggestion_action_disallow_imsi_privacy_exemption_confirmation), + (d, which) -> mHandler.post( + () -> handleUserDisallowCarrierExemptionAction( + carrierName, carrierId))) + .setOnDismissListener( + (d) -> mHandler.post(this::handleUserDismissAction)) + .setOnCancelListener( + (d) -> mHandler.post(this::handleUserDismissAction)) + .create(); + dialog.setCanceledOnTouchOutside(false); + dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); + dialog.getWindow().addSystemFlags( + WindowManager.LayoutParams.SYSTEM_FLAG_SHOW_FOR_ALL_USERS); + dialog.show(); + mUserApprovalUiActive = true; + } + + /** + * Send notification for exemption of IMSI protection if user never made choice before. + */ + public void sendImsiProtectionExemptionNotificationIfRequired(int carrierId) { + int subId = getMatchingSubId(carrierId); + if (requiresImsiEncryption(subId)) { + return; + } + if (mImsiPrivacyProtectionExemptionMap.containsKey(carrierId)) { + return; + } + if (mUserApprovalUiActive) { + return; + } + Log.i(TAG, "Sending IMSI protection notification for " + carrierId); + sendImsiPrivacyNotification(carrierId); + } + + private PendingIntent getPrivateBroadcast(@NonNull String action, + @NonNull Pair<String, String> extra1, @NonNull Pair<String, Integer> extra2) { + Intent intent = new Intent(action) + .setPackage(mWifiInjector.getWifiStackPackageName()) + .putExtra(extra1.first, extra1.second) + .putExtra(extra2.first, extra2.second); + return mFrameworkFacade.getBroadcast(mContext, 0, intent, + PendingIntent.FLAG_UPDATE_CURRENT); + } + + private void saveToStore() { + // Set the flag to let WifiConfigStore that we have new data to write. + mHasNewDataToSerialize = true; + if (!mWifiInjector.getWifiConfigManager().saveToStore(true)) { + Log.w(TAG, "Failed to save to store"); + } + } + + /** + * Helper method for user factory reset network setting. + */ + public void clear() { + mImsiPrivacyProtectionExemptionMap.clear(); + saveToStore(); + } } diff --git a/service/java/com/android/server/wifi/WifiConfigManager.java b/service/java/com/android/server/wifi/WifiConfigManager.java index 476b21b68..309f54f60 100644 --- a/service/java/com/android/server/wifi/WifiConfigManager.java +++ b/service/java/com/android/server/wifi/WifiConfigManager.java @@ -54,7 +54,6 @@ import com.android.internal.annotations.VisibleForTesting; import com.android.server.wifi.hotspot2.PasspointManager; import com.android.server.wifi.util.LruConnectionTracker; import com.android.server.wifi.util.MissingCounterTimerLockList; -import com.android.server.wifi.util.TelephonyUtil; import com.android.server.wifi.util.WifiPermissionsUtil; import com.android.server.wifi.util.WifiPermissionsWrapper; import com.android.wifi.resources.R; @@ -240,7 +239,7 @@ public class WifiConfigManager { private final WifiPermissionsWrapper mWifiPermissionsWrapper; private final WifiInjector mWifiInjector; private final MacAddressUtil mMacAddressUtil; - private final TelephonyUtil mTelephonyUtil; + private final WifiCarrierInfoManager mWifiCarrierInfoManager; private final WifiScoreCard mWifiScoreCard; // Keep order of network connection. private final LruConnectionTracker mLruConnectionTracker; @@ -331,7 +330,7 @@ public class WifiConfigManager { */ WifiConfigManager( Context context, Clock clock, UserManager userManager, - TelephonyUtil telephonyUtil, WifiKeyStore wifiKeyStore, + WifiCarrierInfoManager wifiCarrierInfoManager, WifiKeyStore wifiKeyStore, WifiConfigStore wifiConfigStore, WifiPermissionsUtil wifiPermissionsUtil, WifiPermissionsWrapper wifiPermissionsWrapper, @@ -346,7 +345,7 @@ public class WifiConfigManager { mClock = clock; mUserManager = userManager; mBackupManagerProxy = new BackupManagerProxy(); - mTelephonyUtil = telephonyUtil; + mWifiCarrierInfoManager = wifiCarrierInfoManager; mWifiKeyStore = wifiKeyStore; mWifiConfigStore = wifiConfigStore; mWifiPermissionsUtil = wifiPermissionsUtil; @@ -2726,7 +2725,7 @@ public class WifiConfigManager { } if (config.enterpriseConfig.getEapMethod() == WifiEnterpriseConfig.Eap.PEAP) { Pair<String, String> currentIdentity = - mTelephonyUtil.getSimIdentity(config); + mWifiCarrierInfoManager.getSimIdentity(config); if (mVerboseLoggingEnabled) { Log.d(TAG, "New identity for config " + config + ": " + currentIdentity); } @@ -2741,7 +2740,7 @@ public class WifiConfigManager { } else { // reset identity as well: supplicant will ask us for it config.enterpriseConfig.setIdentity(""); - if (!TelephonyUtil.isAnonymousAtRealmIdentity( + if (!WifiCarrierInfoManager.isAnonymousAtRealmIdentity( config.enterpriseConfig.getAnonymousIdentity())) { config.enterpriseConfig.setAnonymousIdentity(""); } @@ -3194,7 +3193,7 @@ public class WifiConfigManager { pw.println("WifiConfigManager - PNO scan recency sorting enabled = " + mContext.getResources().getBoolean(R.bool.config_wifiPnoRecencySortingEnabled)); mWifiConfigStore.dump(fd, pw, args); - mTelephonyUtil.dump(fd, pw, args); + mWifiCarrierInfoManager.dump(fd, pw, args); } /** diff --git a/service/java/com/android/server/wifi/WifiInjector.java b/service/java/com/android/server/wifi/WifiInjector.java index 3f3e027b2..68311303b 100644 --- a/service/java/com/android/server/wifi/WifiInjector.java +++ b/service/java/com/android/server/wifi/WifiInjector.java @@ -56,7 +56,6 @@ import com.android.server.wifi.rtt.RttMetrics; import com.android.server.wifi.util.LruConnectionTracker; import com.android.server.wifi.util.NetdWrapper; import com.android.server.wifi.util.SettingsMigrationDataHolder; -import com.android.server.wifi.util.TelephonyUtil; import com.android.server.wifi.util.WifiPermissionsUtil; import com.android.server.wifi.util.WifiPermissionsWrapper; @@ -155,7 +154,7 @@ public class WifiInjector { private BssidBlocklistMonitor mBssidBlocklistMonitor; private final MacAddressUtil mMacAddressUtil; private final MboOceController mMboOceController; - private final TelephonyUtil mTelephonyUtil; + private final WifiCarrierInfoManager mWifiCarrierInfoManager; private WifiChannelUtilization mWifiChannelUtilizationScan; private WifiChannelUtilization mWifiChannelUtilizationConnected; private final KeyStore mKeyStore; @@ -260,8 +259,9 @@ public class WifiInjector { WifiConfigStore.createSharedFiles(mFrameworkFacade.isNiapModeOn(mContext))); SubscriptionManager subscriptionManager = mContext.getSystemService(SubscriptionManager.class); - mTelephonyUtil = new TelephonyUtil(makeTelephonyManager(), subscriptionManager, - mFrameworkFacade, mContext, wifiHandler); + mWifiCarrierInfoManager = new WifiCarrierInfoManager(makeTelephonyManager(), + subscriptionManager, this, mFrameworkFacade, mContext, + mWifiConfigStore, wifiHandler); String l2KeySeed = Secure.getString(mContext.getContentResolver(), Secure.ANDROID_ID); mWifiScoreCard = new WifiScoreCard(mClock, l2KeySeed, mDeviceConfigFacade); mWifiMetrics.setWifiScoreCard(mWifiScoreCard); @@ -269,7 +269,7 @@ public class WifiInjector { mContext); // Config Manager mWifiConfigManager = new WifiConfigManager(mContext, mClock, - mUserManager, mTelephonyUtil, + mUserManager, mWifiCarrierInfoManager, mWifiKeyStore, mWifiConfigStore, mWifiPermissionsUtil, mWifiPermissionsWrapper, this, new NetworkListSharedStoreData(mContext), @@ -301,17 +301,17 @@ public class WifiInjector { mWifiMetrics.setWifiNetworkSelector(mWifiNetworkSelector); mWifiNetworkSuggestionsManager = new WifiNetworkSuggestionsManager(mContext, wifiHandler, this, mWifiPermissionsUtil, mWifiConfigManager, mWifiConfigStore, mWifiMetrics, - mTelephonyUtil, mWifiKeyStore, mLruConnectionTracker); + mWifiCarrierInfoManager, mWifiKeyStore, mLruConnectionTracker); mPasspointManager = new PasspointManager(mContext, this, wifiHandler, mWifiNative, mWifiKeyStore, mClock, new PasspointObjectFactory(), - mWifiConfigManager, mWifiConfigStore, mWifiMetrics, mTelephonyUtil); + mWifiConfigManager, mWifiConfigStore, mWifiMetrics, mWifiCarrierInfoManager); PasspointNetworkNominateHelper nominateHelper = new PasspointNetworkNominateHelper(mPasspointManager, mWifiConfigManager, mConnectivityLocalLog); mSavedNetworkNominator = new SavedNetworkNominator( - mWifiConfigManager, nominateHelper, mConnectivityLocalLog, mTelephonyUtil); + mWifiConfigManager, nominateHelper, mConnectivityLocalLog, mWifiCarrierInfoManager); mNetworkSuggestionNominator = new NetworkSuggestionNominator(mWifiNetworkSuggestionsManager, - mWifiConfigManager, nominateHelper, mConnectivityLocalLog, mTelephonyUtil); + mWifiConfigManager, nominateHelper, mConnectivityLocalLog, mWifiCarrierInfoManager); mScoredNetworkNominator = new ScoredNetworkNominator(mContext, wifiHandler, mFrameworkFacade, mNetworkScoreManager, mContext.getPackageManager(), mWifiConfigManager, mConnectivityLocalLog, @@ -346,8 +346,8 @@ public class WifiInjector { this, mBackupManagerProxy, mCountryCode, mWifiNative, new WrongPasswordNotifier(mContext, mFrameworkFacade), mSarManager, mWifiTrafficPoller, mLinkProbeManager, mBatteryStats, - supplicantStateTracker, mMboOceController, mTelephonyUtil, - new EapFailureNotifier(mContext, mFrameworkFacade, mTelephonyUtil), + supplicantStateTracker, mMboOceController, mWifiCarrierInfoManager, + new EapFailureNotifier(mContext, mFrameworkFacade, mWifiCarrierInfoManager), new SimRequiredNotifier(mContext, mFrameworkFacade)); mActiveModeWarden = new ActiveModeWarden(this, wifiLooper, mWifiNative, new DefaultModeManager(mContext), mBatteryStats, mWifiDiagnostics, @@ -410,7 +410,7 @@ public class WifiInjector { mWifiNetworkSuggestionsManager.enableVerboseLogging(verbose); LogcatLog.enableVerboseLogging(verbose); mDppManager.enableVerboseLogging(verbose); - mTelephonyUtil.enableVerboseLogging(verbose); + mWifiCarrierInfoManager.enableVerboseLogging(verbose); } public UserManager getUserManager() { @@ -537,8 +537,8 @@ public class WifiInjector { return (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE); } - public TelephonyUtil getTelephonyUtil() { - return mTelephonyUtil; + public WifiCarrierInfoManager getWifiCarrierInfoManager() { + return mWifiCarrierInfoManager; } public WifiStateTracker getWifiStateTracker() { diff --git a/service/java/com/android/server/wifi/WifiMonitor.java b/service/java/com/android/server/wifi/WifiMonitor.java index 4e006a2fc..7f620851d 100644 --- a/service/java/com/android/server/wifi/WifiMonitor.java +++ b/service/java/com/android/server/wifi/WifiMonitor.java @@ -29,10 +29,10 @@ import android.util.SparseArray; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.util.Protocol; import com.android.server.wifi.MboOceController.BtmFrameData; +import com.android.server.wifi.WifiCarrierInfoManager.SimAuthRequestData; import com.android.server.wifi.hotspot2.AnqpEvent; import com.android.server.wifi.hotspot2.IconEvent; import com.android.server.wifi.hotspot2.WnmData; -import com.android.server.wifi.util.TelephonyUtil.SimAuthRequestData; import java.util.HashMap; import java.util.Map; diff --git a/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java b/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java index 003275c50..894a8bc0f 100644 --- a/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java +++ b/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java @@ -59,7 +59,6 @@ import com.android.internal.annotations.VisibleForTesting; import com.android.internal.messages.nano.SystemMessageProto.SystemMessage; import com.android.server.wifi.util.ExternalCallbackTracker; import com.android.server.wifi.util.LruConnectionTracker; -import com.android.server.wifi.util.TelephonyUtil; import com.android.server.wifi.util.WifiPermissionsUtil; import com.android.wifi.resources.R; @@ -106,22 +105,6 @@ public class WifiNetworkSuggestionsManager { public static final String EXTRA_UID = "com.android.server.wifi.extra.NetworkSuggestion.UID"; - @VisibleForTesting - public static final String EXTRA_CARRIER_NAME = - "com.android.server.wifi.extra.NetworkSuggestion.CARRIER_NAME"; - @VisibleForTesting - public static final String EXTRA_CARRIER_ID = - "com.android.server.wifi.extra.NetworkSuggestion.CARRIER_ID"; - - /** Intent when user tapped action button to allow the app. */ - @VisibleForTesting - public static final String NOTIFICATION_USER_ALLOWED_CARRIER_INTENT_ACTION = - "com.android.server.wifi.action.NetworkSuggestion.USER_ALLOWED_CARRIER"; - /** Intent when user tapped action button to disallow the app. */ - @VisibleForTesting - public static final String NOTIFICATION_USER_DISALLOWED_CARRIER_INTENT_ACTION = - "com.android.server.wifi.action.NetworkSuggestion.USER_DISALLOWED_CARRIER"; - /** * Limit number of hidden networks attach to scan */ @@ -140,7 +123,7 @@ public class WifiNetworkSuggestionsManager { private final WifiMetrics mWifiMetrics; private final WifiInjector mWifiInjector; private final FrameworkFacade mFrameworkFacade; - private final TelephonyUtil mTelephonyUtil; + private final WifiCarrierInfoManager mWifiCarrierInfoManager; private final WifiKeyStore mWifiKeyStore; // Keep order of network connection. private final LruConnectionTracker mLruConnectionTracker; @@ -362,8 +345,6 @@ public class WifiNetworkSuggestionsManager { private final HashMap<String, ExternalCallbackTracker<ISuggestionConnectionStatusListener>> mSuggestionStatusListenerPerApp = new HashMap<>(); - private final Map<Integer, Boolean> mImsiPrivacyProtectionExemptionMap = new HashMap<>(); - /** * Store the suggestion update listeners. */ @@ -488,35 +469,6 @@ public class WifiNetworkSuggestionsManager { } } - /** - * Module to interact with the wifi config store. - */ - private class ImsiProtectionExemptionDataSource implements - ImsiPrivacyProtectionExemptionStoreData.DataSource { - @Override - public Map<Integer, Boolean> toSerialize() { - // Clear the flag after writing to disk. - // TODO(b/115504887): Don't reset the flag on write failure. - mHasNewDataToSerialize = false; - return mImsiPrivacyProtectionExemptionMap; - } - - @Override - public void fromDeserialized(Map<Integer, Boolean> imsiProtectionExemptionMap) { - mImsiPrivacyProtectionExemptionMap.putAll(imsiProtectionExemptionMap); - } - - @Override - public void reset() { - mImsiPrivacyProtectionExemptionMap.clear(); - } - - @Override - public boolean hasNewDataToSerialize() { - return mHasNewDataToSerialize; - } - } - private void handleUserAllowAction(int uid, String packageName) { Log.i(TAG, "User clicked to allow app"); // Set the user approved flag. @@ -539,59 +491,23 @@ public class WifiNetworkSuggestionsManager { mUserApprovalUiActive = false; } - private void handleUserAllowCarrierExemptionAction(String carrierName, int carrierId) { - Log.i(TAG, "User clicked to allow carrier:" + carrierName); - setHasUserApprovedImsiPrivacyExemptionForCarrier(true, carrierId); - mUserApprovalUiActive = false; - } - - private void handleUserDisallowCarrierExemptionAction(String carrierName, int carrierId) { - Log.i(TAG, "User clicked to disallow carrier:" + carrierName); - setHasUserApprovedImsiPrivacyExemptionForCarrier(false, carrierId); - mUserApprovalUiActive = false; - } - private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String packageName = intent.getStringExtra(EXTRA_PACKAGE_NAME); - String carrierName = intent.getStringExtra(EXTRA_CARRIER_NAME); int uid = intent.getIntExtra(EXTRA_UID, -1); - int carrierId = intent.getIntExtra(EXTRA_CARRIER_ID, -1); - + if (packageName == null || uid == -1) { + Log.e(TAG, "No package name or uid found in intent"); + return; + } switch (intent.getAction()) { case NOTIFICATION_USER_ALLOWED_APP_INTENT_ACTION: - if (packageName == null || uid == -1) { - Log.e(TAG, "No package name or uid found in intent"); - return; - } handleUserAllowAction(uid, packageName); break; case NOTIFICATION_USER_DISALLOWED_APP_INTENT_ACTION: - if (packageName == null || uid == -1) { - Log.e(TAG, "No package name or uid found in intent"); - return; - } handleUserDisallowAction(uid, packageName); break; - case NOTIFICATION_USER_ALLOWED_CARRIER_INTENT_ACTION: - if (carrierName == null || carrierId == -1) { - Log.e(TAG, "No carrier name or carrier id found in intent"); - return; - } - Log.i(TAG, "User clicked to allow carrier"); - sendImsiPrivacyConfirmationDialog(carrierName, carrierId); - // Collapse the notification bar - mContext.sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)); - break; - case NOTIFICATION_USER_DISALLOWED_CARRIER_INTENT_ACTION: - if (carrierName == null || carrierId == -1) { - Log.e(TAG, "No carrier name or carrier id found in intent"); - return; - } - handleUserDisallowCarrierExemptionAction(carrierName, carrierId); - break; case NOTIFICATION_USER_DISMISSED_INTENT_ACTION: handleUserDismissAction(); return; // no need to cancel a dismissed notification, return. @@ -604,7 +520,6 @@ public class WifiNetworkSuggestionsManager { } }; - /** * Interface for other modules to listen to the suggestion updated events. */ @@ -619,10 +534,19 @@ public class WifiNetworkSuggestionsManager { void onSuggestionsRemoved(@NonNull List<WifiNetworkSuggestion> removedSuggestions); } + private final class UserApproveCarrierListener implements + WifiCarrierInfoManager.OnUserApproveCarrierListener { + + @Override + public void onUserAllowed(int carrierId) { + restoreInitialAutojoinForCarrierId(carrierId); + } + } + public WifiNetworkSuggestionsManager(WifiContext context, Handler handler, WifiInjector wifiInjector, WifiPermissionsUtil wifiPermissionsUtil, WifiConfigManager wifiConfigManager, WifiConfigStore wifiConfigStore, - WifiMetrics wifiMetrics, TelephonyUtil telephonyUtil, + WifiMetrics wifiMetrics, WifiCarrierInfoManager wifiCarrierInfoManager, WifiKeyStore keyStore, LruConnectionTracker lruConnectionTracker) { mContext = context; mResources = context.getResources(); @@ -638,22 +562,21 @@ public class WifiNetworkSuggestionsManager { mWifiPermissionsUtil = wifiPermissionsUtil; mWifiConfigManager = wifiConfigManager; mWifiMetrics = wifiMetrics; - mTelephonyUtil = telephonyUtil; + mWifiCarrierInfoManager = wifiCarrierInfoManager; mWifiKeyStore = keyStore; // register the data store for serializing/deserializing data. wifiConfigStore.registerStoreData( wifiInjector.makeNetworkSuggestionStoreData(new NetworkSuggestionDataSource())); - wifiConfigStore.registerStoreData(wifiInjector.makeImsiProtectionExemptionStoreData( - new ImsiProtectionExemptionDataSource())); + + mWifiCarrierInfoManager.addImsiExemptionUserApprovalListener( + new UserApproveCarrierListener()); // Register broadcast receiver for UI interactions. mIntentFilter = new IntentFilter(); mIntentFilter.addAction(NOTIFICATION_USER_ALLOWED_APP_INTENT_ACTION); mIntentFilter.addAction(NOTIFICATION_USER_DISALLOWED_APP_INTENT_ACTION); mIntentFilter.addAction(NOTIFICATION_USER_DISMISSED_INTENT_ACTION); - mIntentFilter.addAction(NOTIFICATION_USER_ALLOWED_CARRIER_INTENT_ACTION); - mIntentFilter.addAction(NOTIFICATION_USER_DISALLOWED_CARRIER_INTENT_ACTION); mContext.registerReceiver(mBroadcastReceiver, mIntentFilter, null, handler); mLruConnectionTracker = lruConnectionTracker; @@ -891,7 +814,8 @@ public class WifiNetworkSuggestionsManager { return WifiManager.STATUS_NETWORK_SUGGESTIONS_ERROR_ADD_NOT_ALLOWED; } - int carrierId = mTelephonyUtil.getCarrierIdForPackageWithCarrierPrivileges(packageName); + int carrierId = mWifiCarrierInfoManager + .getCarrierIdForPackageWithCarrierPrivileges(packageName); final String activeScorerPackage = mNetworkScoreManager.getActiveScorerPackage(); PerAppInfo perAppInfo = mActiveNetworkSuggestionsPerApp.get(packageName); if (perAppInfo == null) { @@ -948,9 +872,10 @@ public class WifiNetworkSuggestionsManager { // If network has no IMSI protection and user didn't approve exemption, make it initial // auto join disabled if (isSimBasedSuggestion(ewns)) { - int subId = mTelephonyUtil.getMatchingSubId(getCarrierIdFromSuggestion(ewns)); - if (!(mTelephonyUtil.requiresImsiEncryption(subId) - || hasUserApprovedImsiPrivacyExemptionForCarrier( + int subId = mWifiCarrierInfoManager + .getMatchingSubId(getCarrierIdFromSuggestion(ewns)); + if (!(mWifiCarrierInfoManager.requiresImsiEncryption(subId) + || mWifiCarrierInfoManager.hasUserApprovedImsiPrivacyExemptionForCarrier( getCarrierIdFromSuggestion(ewns)))) { ewns.isAutojoinEnabled = false; } @@ -1033,7 +958,7 @@ public class WifiNetworkSuggestionsManager { private boolean validateCarrierNetworkSuggestions( List<WifiNetworkSuggestion> networkSuggestions, int uid, String packageName) { if (mWifiPermissionsUtil.checkNetworkCarrierProvisioningPermission(uid) - || mTelephonyUtil.getCarrierIdForPackageWithCarrierPrivileges(packageName) + || mWifiCarrierInfoManager.getCarrierIdForPackageWithCarrierPrivileges(packageName) != TelephonyManager.UNKNOWN_CARRIER_ID) { return true; } @@ -1207,7 +1132,6 @@ public class WifiNetworkSuggestionsManager { iter.remove(); } mSuggestionStatusListenerPerApp.clear(); - mImsiPrivacyProtectionExemptionMap.clear(); saveToStore(); Log.i(TAG, "Cleared all internal state"); } @@ -1238,37 +1162,6 @@ public class WifiNetworkSuggestionsManager { } /** - * Clear the Imsi Privacy Exemption user approval info the target carrier. - */ - public void clearImsiPrivacyExemptionForCarrier(int carrierId) { - mImsiPrivacyProtectionExemptionMap.remove(carrierId); - saveToStore(); - } - - /** - * Check if carrier have user approved exemption for IMSI protection - */ - public boolean hasUserApprovedImsiPrivacyExemptionForCarrier(int carrierId) { - return mImsiPrivacyProtectionExemptionMap.getOrDefault(carrierId, false); - } - - /** - * Enable or disable exemption on IMSI protection. - */ - public void setHasUserApprovedImsiPrivacyExemptionForCarrier(boolean approved, int carrierId) { - if (mVerboseLoggingEnabled) { - Log.v(TAG, "Setting Imsi privacy exemption for carrier " + carrierId - + (approved ? " approved" : " not approved")); - } - mImsiPrivacyProtectionExemptionMap.put(carrierId, approved); - // If user approved the exemption restore to initial auto join configure. - if (approved) { - restoreInitialAutojoinForCarrierId(carrierId); - } - saveToStore(); - } - - /** * When user approve the IMSI protection exemption for carrier, restore the initial auto join * configure. If user already change it to enabled, keep that choice. */ @@ -1430,83 +1323,6 @@ public class WifiNetworkSuggestionsManager { mUserApprovalUiActive = true; } - private void sendImsiPrivacyNotification(@NonNull String carrierName, int carrierId) { - Notification.Action userAllowAppNotificationAction = - new Notification.Action.Builder(null, - mResources.getText(R.string - .wifi_suggestion_action_allow_imsi_privacy_exemption_carrier), - getPrivateBroadcast(NOTIFICATION_USER_ALLOWED_CARRIER_INTENT_ACTION, - Pair.create(EXTRA_CARRIER_NAME, carrierName), - Pair.create(EXTRA_CARRIER_ID, carrierId))) - .build(); - Notification.Action userDisallowAppNotificationAction = - new Notification.Action.Builder(null, - mResources.getText(R.string - .wifi_suggestion_action_disallow_imsi_privacy_exemption_carrier), - getPrivateBroadcast(NOTIFICATION_USER_DISALLOWED_CARRIER_INTENT_ACTION, - Pair.create(EXTRA_CARRIER_NAME, carrierName), - Pair.create(EXTRA_CARRIER_ID, carrierId))) - .build(); - - Notification notification = mFrameworkFacade.makeNotificationBuilder( - mContext, WifiService.NOTIFICATION_NETWORK_STATUS) - .setSmallIcon(Icon.createWithResource(mContext.getWifiOverlayApkPkgName(), - com.android.wifi.resources.R.drawable.stat_notify_wifi_in_range)) - .setTicker(mResources.getString( - R.string.wifi_suggestion_imsi_privacy_title, carrierName)) - .setContentTitle(mResources.getString( - R.string.wifi_suggestion_imsi_privacy_title, carrierName)) - .setStyle(new Notification.BigTextStyle() - .bigText(mResources.getString( - R.string.wifi_suggestion_imsi_privacy_content))) - .setDeleteIntent(getPrivateBroadcast(NOTIFICATION_USER_DISMISSED_INTENT_ACTION, - Pair.create(EXTRA_CARRIER_NAME, carrierName), - Pair.create(EXTRA_CARRIER_ID, carrierId))) - .setShowWhen(false) - .setLocalOnly(true) - .setColor(mResources.getColor(android.R.color.system_notification_accent_color, - mContext.getTheme())) - .addAction(userDisallowAppNotificationAction) - .addAction(userAllowAppNotificationAction) - .build(); - - // Post the notification. - mNotificationManager.notify( - SystemMessage.NOTE_NETWORK_SUGGESTION_AVAILABLE, notification); - mUserApprovalUiActive = true; - } - - private void sendImsiPrivacyConfirmationDialog(@NonNull String carrierName, int carrierId) { - AlertDialog dialog = mFrameworkFacade.makeAlertDialogBuilder(mContext) - .setTitle(mResources.getString( - R.string.wifi_suggestion_imsi_privacy_exemption_confirmation_title)) - .setMessage(mResources.getString( - R.string.wifi_suggestion_imsi_privacy_exemption_confirmation_content, - carrierName)) - .setPositiveButton(mResources.getText( - R.string.wifi_suggestion_action_allow_imsi_privacy_exemption_confirmation), - (d, which) -> mHandler.post( - () -> handleUserAllowCarrierExemptionAction( - carrierName, carrierId))) - .setNegativeButton(mResources.getText( - R.string.wifi_suggestion_action_disallow_imsi_privacy_exemption_confirmation), - (d, which) -> mHandler.post( - () -> handleUserDisallowCarrierExemptionAction( - carrierName, carrierId))) - .setOnDismissListener( - (d) -> mHandler.post(this::handleUserDismissAction)) - .setOnCancelListener( - (d) -> mHandler.post(this::handleUserDismissAction)) - .create(); - dialog.setCanceledOnTouchOutside(false); - dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); - dialog.getWindow().addSystemFlags( - WindowManager.LayoutParams.SYSTEM_FLAG_SHOW_FOR_ALL_USERS); - dialog.show(); - mUserApprovalUiActive = true; - } - - /** * Send user approval notification if the app is not approved * @param packageName app package name @@ -1531,24 +1347,6 @@ public class WifiNetworkSuggestionsManager { return true; } - /** - * Send notification for exemption of IMSI protection if user never made choice before. - */ - private void sendImsiProtectionExemptionNotificationIfRequired(int carrierId) { - int subId = mTelephonyUtil.getMatchingSubId(carrierId); - if (mTelephonyUtil.requiresImsiEncryption(subId)) { - return; - } - if (mImsiPrivacyProtectionExemptionMap.containsKey(carrierId)) { - return; - } - if (mUserApprovalUiActive) { - return; - } - Log.i(TAG, "Sending IMSI protection notification for " + carrierId); - sendImsiPrivacyNotification(mTelephonyUtil.getCarrierNameforSubId(subId), carrierId); - } - private @Nullable Set<ExtendedWifiNetworkSuggestion> getNetworkSuggestionsForScanResultMatchInfo( @NonNull ScanResultMatchInfo scanResultMatchInfo, @Nullable MacAddress bssid) { @@ -1598,8 +1396,8 @@ public class WifiNetworkSuggestionsManager { continue; } if (isSimBasedSuggestion(ewns)) { - int carrierId = getCarrierIdFromSuggestion(ewns); - sendImsiProtectionExemptionNotificationIfRequired(carrierId); + mWifiCarrierInfoManager.sendImsiProtectionExemptionNotificationIfRequired( + getCarrierIdFromSuggestion(ewns)); } approvedExtNetworkSuggestions.add(ewns); } @@ -1645,8 +1443,8 @@ public class WifiNetworkSuggestionsManager { continue; } if (isSimBasedSuggestion(ewns)) { - int carrierId = getCarrierIdFromSuggestion(ewns); - sendImsiProtectionExemptionNotificationIfRequired(carrierId); + mWifiCarrierInfoManager.sendImsiProtectionExemptionNotificationIfRequired( + getCarrierIdFromSuggestion(ewns)); } approvedExtNetworkSuggestions.add(ewns); } @@ -1753,7 +1551,7 @@ public class WifiNetworkSuggestionsManager { */ public boolean isPasspointSuggestionSharedWithUser(WifiConfiguration config) { if (WifiConfiguration.isMetered(config, null) - && mTelephonyUtil.isCarrierNetworkFromNonDefaultDataSim(config)) { + && mWifiCarrierInfoManager.isCarrierNetworkFromNonDefaultDataSim(config)) { return false; } Set<ExtendedWifiNetworkSuggestion> extendedWifiNetworkSuggestions = @@ -2080,7 +1878,7 @@ public class WifiNetworkSuggestionsManager { public void resetCarrierPrivilegedApps() { Log.w(TAG, "SIM state is changed!"); for (PerAppInfo appInfo : mActiveNetworkSuggestionsPerApp.values()) { - int carrierId = mTelephonyUtil + int carrierId = mWifiCarrierInfoManager .getCarrierIdForPackageWithCarrierPrivileges(appInfo.packageName); if (carrierId == appInfo.carrierId) { continue; diff --git a/service/java/com/android/server/wifi/WifiShellCommand.java b/service/java/com/android/server/wifi/WifiShellCommand.java index 64b29f2ac..f3bd4ba01 100644 --- a/service/java/com/android/server/wifi/WifiShellCommand.java +++ b/service/java/com/android/server/wifi/WifiShellCommand.java @@ -111,6 +111,7 @@ public class WifiShellCommand extends BasicShellCommandHandler { private final WifiServiceImpl mWifiService; private final Context mContext; private final ConnectivityManager mConnectivityManager; + private final WifiCarrierInfoManager mWifiCarrierInfoManager; WifiShellCommand(WifiInjector wifiInjector, WifiServiceImpl wifiService, Context context) { mClientModeImpl = wifiInjector.getClientModeImpl(); @@ -124,6 +125,7 @@ public class WifiShellCommand extends BasicShellCommandHandler { mWifiService = wifiService; mContext = context; mConnectivityManager = context.getSystemService(ConnectivityManager.class); + mWifiCarrierInfoManager = wifiInjector.getWifiCarrierInfoManager(); } @Override @@ -216,7 +218,7 @@ public class WifiShellCommand extends BasicShellCommandHandler { return -1; } boolean approved = getNextArgRequiredTrueOrFalse("yes", "no"); - mWifiNetworkSuggestionsManager + mWifiCarrierInfoManager .setHasUserApprovedImsiPrivacyExemptionForCarrier(approved, carrierId); return 0; } @@ -231,7 +233,7 @@ public class WifiShellCommand extends BasicShellCommandHandler { + "- 'carrierId' must be an Integer"); return -1; } - boolean hasUserApproved = mWifiNetworkSuggestionsManager + boolean hasUserApproved = mWifiCarrierInfoManager .hasUserApprovedImsiPrivacyExemptionForCarrier(carrierId); pw.println(hasUserApproved ? "yes" : "no"); return 0; @@ -247,7 +249,7 @@ public class WifiShellCommand extends BasicShellCommandHandler { + "- 'carrierId' must be an Integer"); return -1; } - mWifiNetworkSuggestionsManager.clearImsiPrivacyExemptionForCarrier(carrierId); + mWifiCarrierInfoManager.clearImsiPrivacyExemptionForCarrier(carrierId); return 0; } case "network-requests-remove-user-approved-access-points": { diff --git a/service/java/com/android/server/wifi/hotspot2/PasspointConfigUserStoreData.java b/service/java/com/android/server/wifi/hotspot2/PasspointConfigUserStoreData.java index e7de22f55..8400bb581 100644 --- a/service/java/com/android/server/wifi/hotspot2/PasspointConfigUserStoreData.java +++ b/service/java/com/android/server/wifi/hotspot2/PasspointConfigUserStoreData.java @@ -21,9 +21,9 @@ import android.net.wifi.hotspot2.PasspointConfiguration; import android.text.TextUtils; import android.util.Log; +import com.android.server.wifi.WifiCarrierInfoManager; import com.android.server.wifi.WifiConfigStore; import com.android.server.wifi.WifiKeyStore; -import com.android.server.wifi.util.TelephonyUtil; import com.android.server.wifi.util.WifiConfigStoreEncryptionUtil; import com.android.server.wifi.util.XmlUtil; @@ -77,7 +77,7 @@ public class PasspointConfigUserStoreData implements WifiConfigStore.StoreData { private static final String XML_TAG_IS_TRUSTED = "IsTrusted"; private final WifiKeyStore mKeyStore; - private final TelephonyUtil mTelephonyUtil; + private final WifiCarrierInfoManager mWifiCarrierInfoManager; private final DataSource mDataSource; /** @@ -99,10 +99,10 @@ public class PasspointConfigUserStoreData implements WifiConfigStore.StoreData { void setProviders(List<PasspointProvider> providers); } - PasspointConfigUserStoreData(WifiKeyStore keyStore, TelephonyUtil telephonyUtil, - DataSource dataSource) { + PasspointConfigUserStoreData(WifiKeyStore keyStore, + WifiCarrierInfoManager wifiCarrierInfoManager, DataSource dataSource) { mKeyStore = keyStore; - mTelephonyUtil = telephonyUtil; + mWifiCarrierInfoManager = wifiCarrierInfoManager; mDataSource = dataSource; } @@ -348,7 +348,8 @@ public class PasspointConfigUserStoreData implements WifiConfigStore.StoreData { if (config == null) { throw new XmlPullParserException("Missing Passpoint configuration"); } - PasspointProvider provider = new PasspointProvider(config, mKeyStore, mTelephonyUtil, + PasspointProvider provider = new PasspointProvider(config, mKeyStore, + mWifiCarrierInfoManager, providerId, creatorUid, packageName, isFromSuggestion, caCertificateAliases, clientPrivateKeyAndCertificateAlias, remediationCaCertificateAlias, hasEverConnected, shared); diff --git a/service/java/com/android/server/wifi/hotspot2/PasspointManager.java b/service/java/com/android/server/wifi/hotspot2/PasspointManager.java index 14f326ef0..a702c7e98 100644 --- a/service/java/com/android/server/wifi/hotspot2/PasspointManager.java +++ b/service/java/com/android/server/wifi/hotspot2/PasspointManager.java @@ -52,6 +52,7 @@ import android.util.Pair; import com.android.server.wifi.Clock; import com.android.server.wifi.NetworkUpdateResult; +import com.android.server.wifi.WifiCarrierInfoManager; import com.android.server.wifi.WifiConfigManager; import com.android.server.wifi.WifiConfigStore; import com.android.server.wifi.WifiInjector; @@ -63,7 +64,6 @@ import com.android.server.wifi.hotspot2.anqp.Constants; import com.android.server.wifi.hotspot2.anqp.HSOsuProvidersElement; 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.util.ArrayList; @@ -118,7 +118,7 @@ public class PasspointManager { private final WifiMetrics mWifiMetrics; private final PasspointProvisioner mPasspointProvisioner; private final AppOpsManager mAppOps; - private final TelephonyUtil mTelephonyUtil; + private final WifiCarrierInfoManager mWifiCarrierInfoManager; /** * Map of package name of an app to the app ops changed listener for the app. @@ -331,7 +331,7 @@ public class PasspointManager { PasspointObjectFactory objectFactory, WifiConfigManager wifiConfigManager, WifiConfigStore wifiConfigStore, WifiMetrics wifiMetrics, - TelephonyUtil telephonyUtil) { + WifiCarrierInfoManager wifiCarrierInfoManager) { mPasspointEventHandler = objectFactory.makePasspointEventHandler(wifiNative, new CallbackHandler(context)); mWifiInjector = wifiInjector; @@ -344,9 +344,9 @@ public class PasspointManager { mWifiConfigManager = wifiConfigManager; mWifiMetrics = wifiMetrics; mProviderIndex = 0; - mTelephonyUtil = telephonyUtil; + mWifiCarrierInfoManager = wifiCarrierInfoManager; wifiConfigStore.registerStoreData(objectFactory.makePasspointConfigUserStoreData( - mKeyStore, mTelephonyUtil, new UserDataSourceHandler())); + mKeyStore, mWifiCarrierInfoManager, new UserDataSourceHandler())); wifiConfigStore.registerStoreData(objectFactory.makePasspointConfigSharedStoreData( new SharedDataSourceHandler())); mPasspointProvisioner = objectFactory.makePasspointProvisioner(context, wifiNative, @@ -433,10 +433,10 @@ public class PasspointManager { return false; } - mTelephonyUtil.tryUpdateCarrierIdForPasspoint(config); + mWifiCarrierInfoManager.tryUpdateCarrierIdForPasspoint(config); // Create a provider and install the necessary certificates and keys. PasspointProvider newProvider = mObjectFactory.makePasspointProvider(config, mKeyStore, - mTelephonyUtil, mProviderIndex++, uid, packageName, isFromSuggestion); + mWifiCarrierInfoManager, mProviderIndex++, uid, packageName, isFromSuggestion); newProvider.setTrusted(isTrusted); if (!newProvider.installCertsAndKeys()) { @@ -1171,7 +1171,7 @@ public class PasspointManager { // Note that for legacy configuration, the alias for client private key is the same as the // alias for the client certificate. PasspointProvider provider = new PasspointProvider(passpointConfig, mKeyStore, - mTelephonyUtil, + mWifiCarrierInfoManager, mProviderIndex++, wifiConfig.creatorUid, null, false, Arrays.asList(enterpriseConfig.getCaCertificateAlias()), enterpriseConfig.getClientCertificateAlias(), null, false, false); @@ -1226,7 +1226,7 @@ public class PasspointManager { @NonNull PasspointConfiguration passpointConfiguration, @NonNull List<ScanResult> scanResults) { PasspointProvider provider = mObjectFactory.makePasspointProvider(passpointConfiguration, - null, mTelephonyUtil, 0, 0, null, false); + null, mWifiCarrierInfoManager, 0, 0, null, false); List<ScanResult> filteredScanResults = new ArrayList<>(); for (ScanResult scanResult : scanResults) { PasspointMatch matchInfo = provider.match(getANQPElements(scanResult), diff --git a/service/java/com/android/server/wifi/hotspot2/PasspointObjectFactory.java b/service/java/com/android/server/wifi/hotspot2/PasspointObjectFactory.java index 70095f0d4..2ce1b1a6d 100644 --- a/service/java/com/android/server/wifi/hotspot2/PasspointObjectFactory.java +++ b/service/java/com/android/server/wifi/hotspot2/PasspointObjectFactory.java @@ -20,10 +20,10 @@ import android.content.Context; import android.net.wifi.hotspot2.PasspointConfiguration; import com.android.server.wifi.Clock; +import com.android.server.wifi.WifiCarrierInfoManager; import com.android.server.wifi.WifiKeyStore; import com.android.server.wifi.WifiMetrics; import com.android.server.wifi.WifiNative; -import com.android.server.wifi.util.TelephonyUtil; import java.security.KeyStore; import java.security.KeyStoreException; @@ -59,23 +59,24 @@ public class PasspointObjectFactory{ * @return {@link PasspointProvider} */ public PasspointProvider makePasspointProvider(PasspointConfiguration config, - WifiKeyStore keyStore, TelephonyUtil telephonyUtil, long providerId, int creatorUid, - String packageName, boolean isFromSuggestion) { - return new PasspointProvider(config, keyStore, telephonyUtil, providerId, creatorUid, - packageName, isFromSuggestion); + WifiKeyStore keyStore, WifiCarrierInfoManager wifiCarrierInfoManager, long providerId, + int creatorUid, String packageName, boolean isFromSuggestion) { + return new PasspointProvider(config, keyStore, wifiCarrierInfoManager, providerId, + creatorUid, packageName, isFromSuggestion); } /** * Create a {@link PasspointConfigUserStoreData} instance. * * @param keyStore Instance of {@link WifiKeyStore} - * @param telephonyUtil Instance of {@link TelephonyUtil} + * @param wifiCarrierInfoManager Instance of {@link WifiCarrierInfoManager} * @param dataSource Passpoint configuration data source * @return {@link PasspointConfigUserStoreData} */ public PasspointConfigUserStoreData makePasspointConfigUserStoreData(WifiKeyStore keyStore, - TelephonyUtil telephonyUtil, PasspointConfigUserStoreData.DataSource dataSource) { - return new PasspointConfigUserStoreData(keyStore, telephonyUtil, dataSource); + WifiCarrierInfoManager wifiCarrierInfoManager, + PasspointConfigUserStoreData.DataSource dataSource) { + return new PasspointConfigUserStoreData(keyStore, wifiCarrierInfoManager, dataSource); } /** diff --git a/service/java/com/android/server/wifi/hotspot2/PasspointProvider.java b/service/java/com/android/server/wifi/hotspot2/PasspointProvider.java index 43d6f0634..006b8eaef 100644 --- a/service/java/com/android/server/wifi/hotspot2/PasspointProvider.java +++ b/service/java/com/android/server/wifi/hotspot2/PasspointProvider.java @@ -34,6 +34,7 @@ import android.util.Log; import android.util.Pair; import com.android.server.wifi.IMSIParameter; +import com.android.server.wifi.WifiCarrierInfoManager; import com.android.server.wifi.WifiKeyStore; import com.android.server.wifi.hotspot2.anqp.ANQPElement; import com.android.server.wifi.hotspot2.anqp.Constants.ANQPElementType; @@ -45,7 +46,6 @@ import com.android.server.wifi.hotspot2.anqp.eap.AuthParam; import com.android.server.wifi.hotspot2.anqp.eap.NonEAPInnerAuth; import com.android.server.wifi.util.ArrayUtils; import com.android.server.wifi.util.InformationElementUtil.RoamingConsortium; -import com.android.server.wifi.util.TelephonyUtil; import java.nio.charset.StandardCharsets; import java.security.MessageDigest; @@ -98,7 +98,7 @@ public class PasspointProvider { private final int mEAPMethodID; private final AuthParam mAuthParam; - private final TelephonyUtil mTelephonyUtil; + private final WifiCarrierInfoManager mWifiCarrierInfoManager; private int mBestGuessCarrierId = TelephonyManager.UNKNOWN_CARRIER_ID; private boolean mHasEverConnected; @@ -108,17 +108,16 @@ public class PasspointProvider { private boolean mVerboseLoggingEnabled; public PasspointProvider(PasspointConfiguration config, WifiKeyStore keyStore, - TelephonyUtil telephonyUtil, long providerId, int creatorUid, String packageName, - boolean isFromSuggestion) { - this(config, keyStore, telephonyUtil, providerId, creatorUid, packageName, isFromSuggestion, - null, null, null, false, false); + WifiCarrierInfoManager wifiCarrierInfoManager, long providerId, int creatorUid, + String packageName, boolean isFromSuggestion) { + this(config, keyStore, wifiCarrierInfoManager, providerId, creatorUid, packageName, + isFromSuggestion, null, null, null, false, false); } public PasspointProvider(PasspointConfiguration config, WifiKeyStore keyStore, - TelephonyUtil telephonyUtil, long providerId, int creatorUid, String packageName, - boolean isFromSuggestion, List<String> caCertificateAliases, - String clientPrivateKeyAndCertificateAlias, - String remediationCaCertificateAlias, + WifiCarrierInfoManager wifiCarrierInfoManager, long providerId, int creatorUid, + String packageName, boolean isFromSuggestion, List<String> caCertificateAliases, + String clientPrivateKeyAndCertificateAlias, String remediationCaCertificateAlias, boolean hasEverConnected, boolean isShared) { // Maintain a copy of the configuration to avoid it being updated by others. mConfig = new PasspointConfiguration(config); @@ -132,7 +131,7 @@ public class PasspointProvider { mHasEverConnected = hasEverConnected; mIsShared = isShared; mIsFromSuggestion = isFromSuggestion; - mTelephonyUtil = telephonyUtil; + mWifiCarrierInfoManager = wifiCarrierInfoManager; mIsTrusted = true; // Setup EAP method and authentication parameter based on the credential. @@ -351,19 +350,19 @@ public class PasspointProvider { * @return true if the carrier ID is updated, otherwise false. */ public boolean tryUpdateCarrierId() { - return mTelephonyUtil.tryUpdateCarrierIdForPasspoint(mConfig); + return mWifiCarrierInfoManager.tryUpdateCarrierIdForPasspoint(mConfig); } private @Nullable String getMatchingSimImsi() { String matchingSIMImsi = null; if (mConfig.getCarrierId() != TelephonyManager.UNKNOWN_CARRIER_ID) { - matchingSIMImsi = mTelephonyUtil + matchingSIMImsi = mWifiCarrierInfoManager .getMatchingImsi(mConfig.getCarrierId()); } else { // Get the IMSI and carrier ID of SIM card which match with the IMSI prefix from // passpoint profile - Pair<String, Integer> imsiCarrierIdPair = mTelephonyUtil.getMatchingImsiCarrierId( - mConfig.getCredential().getSimCredential().getImsi()); + Pair<String, Integer> imsiCarrierIdPair = mWifiCarrierInfoManager + .getMatchingImsiCarrierId(mConfig.getCredential().getSimCredential().getImsi()); if (imsiCarrierIdPair != null) { matchingSIMImsi = imsiCarrierIdPair.first; mBestGuessCarrierId = imsiCarrierIdPair.second; |