Refine APN fetching logic

APN fetching logic has been encapsulated in URL_SIM_APN_LIST API in
TelephonyProvider

Bug: 115709816
Test: Live netwrk test
Change-Id: I735bc50e912dfbec0903fbcafdc4d6eaa6ccfc7b
This commit is contained in:
Josh Hou
2018-11-23 09:57:20 +08:00
parent 006d1c6027
commit 1e1d6d1466

View File

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