Merge "Fix cannot build prefer or restore APN for Secondary SIM/Sub."
This commit is contained in:
@@ -393,14 +393,14 @@ public class ApnSettings extends SettingsPreferenceFragment implements
|
||||
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(APN_ID, mSelectedKey);
|
||||
resolver.update(PREFERAPN_URI, values, null, null);
|
||||
resolver.update(getUriForCurrSubId(PREFERAPN_URI), values, null, null);
|
||||
}
|
||||
|
||||
private String getSelectedApnKey() {
|
||||
String key = null;
|
||||
|
||||
Cursor cursor = getContentResolver().query(PREFERAPN_URI, new String[] {"_id"},
|
||||
null, null, Telephony.Carriers.DEFAULT_SORT_ORDER);
|
||||
Cursor cursor = getContentResolver().query(getUriForCurrSubId(PREFERAPN_URI),
|
||||
new String[] {"_id"}, null, null, Telephony.Carriers.DEFAULT_SORT_ORDER);
|
||||
if (cursor.getCount() > 0) {
|
||||
cursor.moveToFirst();
|
||||
key = cursor.getString(ID_INDEX);
|
||||
@@ -431,6 +431,17 @@ public class ApnSettings extends SettingsPreferenceFragment implements
|
||||
return true;
|
||||
}
|
||||
|
||||
// Append subId to the Uri
|
||||
private Uri getUriForCurrSubId(Uri uri) {
|
||||
int subId = mSubscriptionInfo != null ? mSubscriptionInfo.getSubscriptionId()
|
||||
: SubscriptionManager.INVALID_SUBSCRIPTION_ID;
|
||||
if (SubscriptionManager.isValidSubscriptionId(subId)) {
|
||||
return Uri.withAppendedPath(uri, "subId/" + String.valueOf(subId));
|
||||
} else {
|
||||
return uri;
|
||||
}
|
||||
}
|
||||
|
||||
private class RestoreApnUiHandler extends Handler {
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
@@ -468,7 +479,7 @@ public class ApnSettings extends SettingsPreferenceFragment implements
|
||||
switch (msg.what) {
|
||||
case EVENT_RESTORE_DEFAULTAPN_START:
|
||||
ContentResolver resolver = getContentResolver();
|
||||
resolver.delete(DEFAULTAPN_URI, null, null);
|
||||
resolver.delete(getUriForCurrSubId(DEFAULTAPN_URI), null, null);
|
||||
mRestoreApnUiHandler
|
||||
.sendEmptyMessage(EVENT_RESTORE_DEFAULTAPN_COMPLETE);
|
||||
break;
|
||||
|
Reference in New Issue
Block a user