Merge "Fix cannot build prefer or restore APN for Secondary SIM/Sub." am: 5620699fb9

am: 1545987bec

* commit '1545987bec5f2f8c5b98c1cfbba610ece2d537b0':
  Fix cannot build prefer or restore APN for Secondary SIM/Sub.

Change-Id: I739817ba6a0adfdd1b8edf9d04ee135346f1283a
This commit is contained in:
Amit Mahajan
2016-05-13 16:54:49 +00:00
committed by android-build-merger

View File

@@ -399,14 +399,14 @@ public class ApnSettings extends RestrictedSettingsFragment 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);
@@ -437,6 +437,17 @@ public class ApnSettings extends RestrictedSettingsFragment 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) {
@@ -474,7 +485,7 @@ public class ApnSettings extends RestrictedSettingsFragment 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;