Merge "[Settings] Refactor of ApnSettings"

This commit is contained in:
Bonian Chen
2020-03-19 16:54:42 +00:00
committed by Gerrit Code Review

View File

@@ -150,19 +150,20 @@ public class ApnSettings extends RestrictedSettingsFragment
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(
TelephonyManager.ACTION_SUBSCRIPTION_CARRIER_IDENTITY_CHANGED)) {
if (!mRestoreDefaultApnMode) {
int extraSubId = intent.getIntExtra(TelephonyManager.EXTRA_SUBSCRIPTION_ID,
SubscriptionManager.INVALID_SUBSCRIPTION_ID);
if (SubscriptionManager.isValidSubscriptionId(extraSubId)
&& mPhoneId == SubscriptionUtil.getPhoneId(context, extraSubId)
&& extraSubId != mSubId) {
// subscription has changed
mSubId = extraSubId;
mSubscriptionInfo = getSubscriptionInfo(mSubId);
restartPhoneStateListener(mSubId);
}
fillList();
if (mRestoreDefaultApnMode) {
return;
}
final int extraSubId = intent.getIntExtra(TelephonyManager.EXTRA_SUBSCRIPTION_ID,
SubscriptionManager.INVALID_SUBSCRIPTION_ID);
if (SubscriptionManager.isValidSubscriptionId(extraSubId)
&& mPhoneId == SubscriptionUtil.getPhoneId(context, extraSubId)
&& extraSubId != mSubId) {
// subscription has changed
mSubId = extraSubId;
mSubscriptionInfo = getSubscriptionInfo(mSubId);
restartPhoneStateListener(mSubId);
}
fillList();
}
}
};
@@ -205,13 +206,13 @@ public class ApnSettings extends RestrictedSettingsFragment
mSubscriptionInfo = getSubscriptionInfo(mSubId);
mTelephonyManager = activity.getSystemService(TelephonyManager.class);
CarrierConfigManager configManager = (CarrierConfigManager)
final CarrierConfigManager configManager = (CarrierConfigManager)
getSystemService(Context.CARRIER_CONFIG_SERVICE);
PersistableBundle b = configManager.getConfigForSubId(mSubId);
final PersistableBundle b = configManager.getConfigForSubId(mSubId);
mHideImsApn = b.getBoolean(CarrierConfigManager.KEY_HIDE_IMS_APN_BOOL);
mAllowAddingApns = b.getBoolean(CarrierConfigManager.KEY_ALLOW_ADDING_APNS_BOOL);
if (mAllowAddingApns) {
String[] readOnlyApnTypes = b.getStringArray(
final String[] readOnlyApnTypes = b.getStringArray(
CarrierConfigManager.KEY_READ_ONLY_APN_TYPES_STRING_ARRAY);
// if no apn type can be edited, do not allow adding APNs
if (ApnEditor.hasAllApns(readOnlyApnTypes)) {
@@ -298,36 +299,37 @@ public class ApnSettings extends RestrictedSettingsFragment
: SubscriptionManager.INVALID_SUBSCRIPTION_ID;
final Uri simApnUri = Uri.withAppendedPath(Telephony.Carriers.SIM_APN_URI,
String.valueOf(subId));
StringBuilder where = new StringBuilder("NOT (type='ia' AND (apn=\"\" OR apn IS NULL)) AND "
final 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(simApnUri,
final Cursor cursor = getContentResolver().query(simApnUri,
CARRIERS_PROJECTION, where.toString(), null,
Telephony.Carriers.DEFAULT_SORT_ORDER);
if (cursor != null) {
PreferenceGroup apnPrefList = (PreferenceGroup) findPreference("apn_list");
final PreferenceGroup apnPrefList = (PreferenceGroup) findPreference("apn_list");
apnPrefList.removeAll();
ArrayList<ApnPreference> apnList = new ArrayList<ApnPreference>();
ArrayList<ApnPreference> mmsApnList = new ArrayList<ApnPreference>();
final ArrayList<ApnPreference> apnList = new ArrayList<ApnPreference>();
final ArrayList<ApnPreference> mmsApnList = new ArrayList<ApnPreference>();
mSelectedKey = getSelectedApnKey();
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
String name = cursor.getString(NAME_INDEX);
String apn = cursor.getString(APN_INDEX);
String key = cursor.getString(ID_INDEX);
String type = cursor.getString(TYPES_INDEX);
int edited = cursor.getInt(EDITED_INDEX);
final String name = cursor.getString(NAME_INDEX);
final String apn = cursor.getString(APN_INDEX);
final String key = cursor.getString(ID_INDEX);
final String type = cursor.getString(TYPES_INDEX);
final int edited = cursor.getInt(EDITED_INDEX);
mMvnoType = cursor.getString(MVNO_TYPE_INDEX);
mMvnoMatchData = cursor.getString(MVNO_MATCH_DATA_INDEX);
ApnPreference pref = new ApnPreference(getPrefContext());
final ApnPreference pref = new ApnPreference(getPrefContext());
pref.setKey(key);
pref.setTitle(name);
@@ -340,7 +342,7 @@ public class ApnSettings extends RestrictedSettingsFragment
pref.setSummary(apn);
}
boolean selectable = ((type == null) || !type.equals("mms"));
final boolean selectable = ((type == null) || !type.equals("mms"));
pref.setSelectable(selectable);
if (selectable) {
if ((mSelectedKey != null) && mSelectedKey.equals(key)) {
@@ -395,10 +397,11 @@ public class ApnSettings extends RestrictedSettingsFragment
}
private void addNewApn() {
Intent intent = new Intent(Intent.ACTION_INSERT, Telephony.Carriers.CONTENT_URI);
int subId = mSubscriptionInfo != null ? mSubscriptionInfo.getSubscriptionId()
final Intent intent = new Intent(Intent.ACTION_INSERT, Telephony.Carriers.CONTENT_URI);
final int subId = mSubscriptionInfo != null ? mSubscriptionInfo.getSubscriptionId()
: SubscriptionManager.INVALID_SUBSCRIPTION_ID;
intent.putExtra(SUB_ID, subId);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
if (!TextUtils.isEmpty(mMvnoType) && !TextUtils.isEmpty(mMvnoMatchData)) {
intent.putExtra(MVNO_TYPE, mMvnoType);
intent.putExtra(MVNO_MATCH_DATA, mMvnoMatchData);
@@ -420,9 +423,9 @@ public class ApnSettings extends RestrictedSettingsFragment
private void setSelectedApnKey(String key) {
mSelectedKey = key;
ContentResolver resolver = getContentResolver();
final ContentResolver resolver = getContentResolver();
ContentValues values = new ContentValues();
final ContentValues values = new ContentValues();
values.put(APN_ID, mSelectedKey);
resolver.update(getUriForCurrSubId(PREFERAPN_URI), values, null, null);
}
@@ -430,7 +433,7 @@ public class ApnSettings extends RestrictedSettingsFragment
private String getSelectedApnKey() {
String key = null;
Cursor cursor = getContentResolver().query(getUriForCurrSubId(PREFERAPN_URI),
final Cursor cursor = getContentResolver().query(getUriForCurrSubId(PREFERAPN_URI),
new String[] {"_id"}, null, null, Telephony.Carriers.DEFAULT_SORT_ORDER);
if (cursor.getCount() > 0) {
cursor.moveToFirst();
@@ -464,7 +467,7 @@ public class ApnSettings extends RestrictedSettingsFragment
// Append subId to the Uri
private Uri getUriForCurrSubId(Uri uri) {
int subId = mSubscriptionInfo != null ? mSubscriptionInfo.getSubscriptionId()
final int subId = mSubscriptionInfo != null ? mSubscriptionInfo.getSubscriptionId()
: SubscriptionManager.INVALID_SUBSCRIPTION_ID;
if (SubscriptionManager.isValidSubscriptionId(subId)) {
return Uri.withAppendedPath(uri, "subId/" + String.valueOf(subId));
@@ -478,7 +481,7 @@ public class ApnSettings extends RestrictedSettingsFragment
public void handleMessage(Message msg) {
switch (msg.what) {
case EVENT_RESTORE_DEFAULTAPN_COMPLETE:
Activity activity = getActivity();
final Activity activity = getActivity();
if (activity == null) {
mRestoreDefaultApnMode = false;
return;
@@ -509,7 +512,7 @@ public class ApnSettings extends RestrictedSettingsFragment
public void handleMessage(Message msg) {
switch (msg.what) {
case EVENT_RESTORE_DEFAULTAPN_START:
ContentResolver resolver = getContentResolver();
final ContentResolver resolver = getContentResolver();
resolver.delete(getUriForCurrSubId(DEFAULTAPN_URI), null, null);
mRestoreApnUiHandler
.sendEmptyMessage(EVENT_RESTORE_DEFAULTAPN_COMPLETE);
@@ -521,7 +524,7 @@ public class ApnSettings extends RestrictedSettingsFragment
@Override
public Dialog onCreateDialog(int id) {
if (id == DIALOG_RESTORE_DEFAULTAPN) {
ProgressDialog dialog = new ProgressDialog(getActivity()) {
final ProgressDialog dialog = new ProgressDialog(getActivity()) {
public boolean onTouchEvent(MotionEvent event) {
return true;
}