From e00ab6c5d9fcb667c034e1ed4b6501fc97d2bfe4 Mon Sep 17 00:00:00 2001 From: Yifan Bai Date: Wed, 6 Apr 2016 18:00:40 +0800 Subject: [PATCH] Fix cannot build prefer or restore APN for Secondary SIM/Sub. When built prefer or restore APN with URI, the URI does not contain Sub Id. This leads to the fail of display selected APN on Secondary SIM/Sub. To fix, SubId needs to be appended in the URI. Change-Id: If4b98b0bdd02474b3e7b7537c5a1257dcdbe9511 --- src/com/android/settings/ApnSettings.java | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/com/android/settings/ApnSettings.java b/src/com/android/settings/ApnSettings.java index fdc09148f74..2680ad3b1ee 100644 --- a/src/com/android/settings/ApnSettings.java +++ b/src/com/android/settings/ApnSettings.java @@ -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;