[Wi-Fi] Support multi-SIM for SIM dependent EAP methods

Before this change, users are not able to choose SIM
card for SIM dependent EAP methods when a device supports
multi-SIM.

This change support to choose a SIM when adding an EAP
Wi-Fi network. And this change support to show the related
SIM information on Wi-Fi detail screen.

Bug: 142792009
Test: make RunSettingsRoboTests ROBOTEST_FILTER=com.android.settings.wifi.WifiConfigController2Test
      make RunSettingsRoboTests ROBOTEST_FILTER=com.android.settings.wifi.details2.WifiDetailPreferenceController2Test
      Manually add an EAP Wi-Fi network of EAP-SIM type, observe the
      value in Wi-Fi detail screen.
Change-Id: I2910931166dc6541897663857c46abcc1b3115fa
This commit is contained in:
Arc Wang
2020-07-03 14:12:58 +08:00
parent c8e69e99db
commit e410325b37
7 changed files with 336 additions and 5 deletions

View File

@@ -23,8 +23,10 @@ import static android.net.NetworkCapabilities.TRANSPORT_WIFI;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.settings.SettingsEnums;
import android.content.AsyncQueryHandler;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
@@ -41,9 +43,14 @@ import android.net.NetworkRequest;
import android.net.NetworkUtils;
import android.net.RouteInfo;
import android.net.Uri;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Handler;
import android.provider.Telephony.CarrierId;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.FeatureFlagUtils;
import android.util.Log;
@@ -97,6 +104,7 @@ import java.time.Instant;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.FormatStyle;
import java.util.List;
import java.util.StringJoiner;
import java.util.stream.Collectors;
@@ -132,6 +140,8 @@ public class WifiDetailPreferenceController2 extends AbstractPreferenceControlle
@VisibleForTesting
static final String KEY_SSID_PREF = "ssid";
@VisibleForTesting
static final String KEY_EAP_SIM_SUBSCRIPTION_PREF = "eap_sim_subscription";
@VisibleForTesting
static final String KEY_MAC_ADDRESS_PREF = "mac_address";
@VisibleForTesting
static final String KEY_IP_ADDRESS_PREF = "ip_address";
@@ -169,6 +179,7 @@ public class WifiDetailPreferenceController2 extends AbstractPreferenceControlle
private Preference mFrequencyPref;
private Preference mSecurityPref;
private Preference mSsidPref;
private Preference mEapSimSubscriptionPref;
private Preference mMacAddressPref;
private Preference mIpAddressPref;
private Preference mGatewayPref;
@@ -186,6 +197,35 @@ public class WifiDetailPreferenceController2 extends AbstractPreferenceControlle
private final NetworkRequest mNetworkRequest = new NetworkRequest.Builder()
.clearCapabilities().addTransportType(TRANSPORT_WIFI).build();
private CarrierIdAsyncQueryHandler mCarrierIdAsyncQueryHandler;
private static final int TOKEN_QUERY_CARRIER_ID_AND_UPDATE_SIM_SUMMARY = 1;
private static final int COLUMN_CARRIER_NAME = 0;
private class CarrierIdAsyncQueryHandler extends AsyncQueryHandler {
private CarrierIdAsyncQueryHandler(Context context) {
super(context.getContentResolver());
}
@Override
protected void onQueryComplete(int token, Object cookie, Cursor cursor) {
if (token == TOKEN_QUERY_CARRIER_ID_AND_UPDATE_SIM_SUMMARY) {
if (mContext == null || cursor == null || !cursor.moveToFirst()) {
if (cursor != null) {
cursor.close();
}
mEapSimSubscriptionPref.setSummary(R.string.wifi_require_sim_card_to_connect);
return;
}
mEapSimSubscriptionPref.setSummary(mContext.getString(
R.string.wifi_require_specific_sim_card_to_connect,
cursor.getString(COLUMN_CARRIER_NAME)));
cursor.close();
return;
}
}
}
// Must be run on the UI thread since it directly manipulates UI state.
private final NetworkCallback mNetworkCallback = new NetworkCallback() {
@Override
@@ -335,6 +375,7 @@ public class WifiDetailPreferenceController2 extends AbstractPreferenceControlle
mSecurityPref = screen.findPreference(KEY_SECURITY_PREF);
mSsidPref = screen.findPreference(KEY_SSID_PREF);
mEapSimSubscriptionPref = screen.findPreference(KEY_EAP_SIM_SUBSCRIPTION_PREF);
mMacAddressPref = screen.findPreference(KEY_MAC_ADDRESS_PREF);
mIpAddressPref = screen.findPreference(KEY_IP_ADDRESS_PREF);
mGatewayPref = screen.findPreference(KEY_GATEWAY_PREF);
@@ -506,6 +547,8 @@ public class WifiDetailPreferenceController2 extends AbstractPreferenceControlle
refreshIpLayerInfo();
// SSID Pref
refreshSsid();
// EAP SIM subscription
refreshEapSimSubscription();
// MAC Address Pref
refreshMacAddress();
}
@@ -627,6 +670,62 @@ public class WifiDetailPreferenceController2 extends AbstractPreferenceControlle
}
}
private void refreshEapSimSubscription() {
mEapSimSubscriptionPref.setVisible(false);
if (mWifiEntry.getSecurity() != WifiEntry.SECURITY_EAP) {
return;
}
final WifiConfiguration config = mWifiEntry.getWifiConfiguration();
if (config == null || config.enterpriseConfig == null) {
return;
}
if (!config.enterpriseConfig.isAuthenticationSimBased()) {
return;
}
mEapSimSubscriptionPref.setVisible(true);
// Checks if the SIM subscription is active.
final List<SubscriptionInfo> activeSubscriptionInfos = mContext
.getSystemService(SubscriptionManager.class).getActiveSubscriptionInfoList();
final int defaultDataSubscriptionId = SubscriptionManager.getDefaultDataSubscriptionId();
if (activeSubscriptionInfos != null) {
for (SubscriptionInfo subscriptionInfo : activeSubscriptionInfos) {
if (config.carrierId == subscriptionInfo.getCarrierId()) {
mEapSimSubscriptionPref.setSummary(subscriptionInfo.getDisplayName());
return;
}
// When it's UNKNOWN_CARRIER_ID, devices connects it with the SIM subscription of
// defaultDataSubscriptionId.
if (config.carrierId == TelephonyManager.UNKNOWN_CARRIER_ID
&& defaultDataSubscriptionId == subscriptionInfo.getSubscriptionId()) {
mEapSimSubscriptionPref.setSummary(subscriptionInfo.getDisplayName());
return;
}
}
}
if (config.carrierId == TelephonyManager.UNKNOWN_CARRIER_ID) {
mEapSimSubscriptionPref.setSummary(R.string.wifi_no_related_sim_card);
return;
}
// The Wi-Fi network has specified carrier id, query carrier name from CarrierIdProvider.
if (mCarrierIdAsyncQueryHandler == null) {
mCarrierIdAsyncQueryHandler = new CarrierIdAsyncQueryHandler(mContext);
}
mCarrierIdAsyncQueryHandler.cancelOperation(TOKEN_QUERY_CARRIER_ID_AND_UPDATE_SIM_SUMMARY);
mCarrierIdAsyncQueryHandler.startQuery(TOKEN_QUERY_CARRIER_ID_AND_UPDATE_SIM_SUMMARY,
null /* cookie */,
CarrierId.All.CONTENT_URI,
new String[]{CarrierId.CARRIER_NAME},
CarrierId.CARRIER_ID + "=?",
new String[] {Integer.toString(config.carrierId)},
null /* orderBy */);
}
private void refreshMacAddress() {
final String macAddress = mWifiEntry.getMacAddress();
if (TextUtils.isEmpty(macAddress)) {