Merge "Refine APN fetching logic" am: 765621670b

am: 74069bc022

Change-Id: I372d73a75a7dd2077e39dfc29c66b29b1a3ace65
This commit is contained in:
Josh Hou
2018-12-17 00:25:12 -08:00
committed by android-build-merger

View File

@@ -42,7 +42,6 @@ import android.telephony.CarrierConfigManager;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.telephony.data.ApnSetting;
import android.text.TextUtils;
import android.util.Log;
import android.view.Menu;
@@ -54,8 +53,6 @@ import android.widget.Toast;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.internal.telephony.PhoneConstants;
import com.android.internal.telephony.TelephonyIntents;
import com.android.internal.telephony.dataconnection.ApnSettingUtils;
import com.android.internal.telephony.uicc.IccRecords;
import com.android.internal.telephony.uicc.UiccController;
import com.android.settings.R;
import com.android.settings.RestrictedSettingsFragment;
@@ -277,34 +274,27 @@ public class ApnSettings extends RestrictedSettingsFragment {
}
private void fillList() {
final TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
final int subId = mSubscriptionInfo != null ? mSubscriptionInfo.getSubscriptionId()
: SubscriptionManager.INVALID_SUBSCRIPTION_ID;
final String mccmnc = mSubscriptionInfo == null ? "" : tm.getSimOperator(subId);
Log.d(TAG, "mccmnc = " + mccmnc);
StringBuilder where = new StringBuilder("numeric=\"" + mccmnc +
"\" AND NOT (type='ia' AND (apn=\"\" OR apn IS NULL)) AND user_visible!=0");
final Uri simApnUri = Uri.withAppendedPath(Telephony.Carriers.SIM_APN_LIST,
String.valueOf(subId));
StringBuilder where = new StringBuilder("NOT (type='ia' AND (apn=\"\" OR apn IS NULL)) AND "
+ "user_visible!=0");
if (mHideImsApn) {
where.append(" AND NOT (type='ims')");
}
Cursor cursor = getContentResolver().query(Telephony.Carriers.CONTENT_URI,
CARRIERS_PROJECTION, where.toString(), null, Telephony.Carriers.DEFAULT_SORT_ORDER);
Cursor cursor = getContentResolver().query(simApnUri,
CARRIERS_PROJECTION, where.toString(), null,
Telephony.Carriers.DEFAULT_SORT_ORDER);
if (cursor != null) {
IccRecords r = null;
if (mUiccController != null && mSubscriptionInfo != null) {
r = mUiccController.getIccRecords(
SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
}
PreferenceGroup apnList = (PreferenceGroup) findPreference("apn_list");
apnList.removeAll();
PreferenceGroup apnPrefList = (PreferenceGroup) findPreference("apn_list");
apnPrefList.removeAll();
ArrayList<ApnPreference> mnoApnList = new ArrayList<ApnPreference>();
ArrayList<ApnPreference> mvnoApnList = new ArrayList<ApnPreference>();
ArrayList<ApnPreference> mnoMmsApnList = new ArrayList<ApnPreference>();
ArrayList<ApnPreference> mvnoMmsApnList = new ArrayList<ApnPreference>();
ArrayList<ApnPreference> apnList = new ArrayList<ApnPreference>();
ArrayList<ApnPreference> mmsApnList = new ArrayList<ApnPreference>();
mSelectedKey = getSelectedApnKey();
cursor.moveToFirst();
@@ -313,9 +303,9 @@ public class ApnSettings extends RestrictedSettingsFragment {
String apn = cursor.getString(APN_INDEX);
String key = cursor.getString(ID_INDEX);
String type = cursor.getString(TYPES_INDEX);
String mvnoType = cursor.getString(MVNO_TYPE_INDEX);
String mvnoMatchData = cursor.getString(MVNO_MATCH_DATA_INDEX);
int edited = cursor.getInt(EDITED_INDEX);
mMvnoType = cursor.getString(MVNO_TYPE_INDEX);
mMvnoMatchData = cursor.getString(MVNO_MATCH_DATA_INDEX);
ApnPreference pref = new ApnPreference(getPrefContext());
@@ -335,43 +325,20 @@ public class ApnSettings extends RestrictedSettingsFragment {
if ((mSelectedKey != null) && mSelectedKey.equals(key)) {
pref.setChecked();
}
addApnToList(pref, mnoApnList, mvnoApnList, r, mvnoType, mvnoMatchData);
apnList.add(pref);
} else {
addApnToList(pref, mnoMmsApnList, mvnoMmsApnList, r, mvnoType, mvnoMatchData);
mmsApnList.add(pref);
}
cursor.moveToNext();
}
cursor.close();
if (!mvnoApnList.isEmpty()) {
mnoApnList = mvnoApnList;
mnoMmsApnList = mvnoMmsApnList;
// Also save the mvno info
for (Preference preference : apnList) {
apnPrefList.addPreference(preference);
}
for (Preference preference : mnoApnList) {
apnList.addPreference(preference);
for (Preference preference : mmsApnList) {
apnPrefList.addPreference(preference);
}
for (Preference preference : mnoMmsApnList) {
apnList.addPreference(preference);
}
}
}
private void addApnToList(ApnPreference pref, ArrayList<ApnPreference> mnoList,
ArrayList<ApnPreference> mvnoList, IccRecords r, String mvnoType,
String mvnoMatchData) {
if (r != null && !TextUtils.isEmpty(mvnoType) && !TextUtils.isEmpty(mvnoMatchData)) {
if (ApnSettingUtils.mvnoMatches(r, ApnSetting.getMvnoTypeIntFromString(mvnoType),
mvnoMatchData)) {
mvnoList.add(pref);
// Since adding to mvno list, save mvno info
mMvnoType = mvnoType;
mMvnoMatchData = mvnoMatchData;
}
} else {
mnoList.add(pref);
}
}