From db9a9bb0b0438816909e002156cb7322c66a0d28 Mon Sep 17 00:00:00 2001 From: yuemingw Date: Tue, 23 Jan 2018 18:58:38 +0000 Subject: [PATCH] Fix the crash when editing or deleting APN. Previously ApnPrefence starts an intent with URI content://telephony/carrier/filtered/id, this URI is only implemented in telephony provider for query(), but not for delete() or update(). This caused the crash when user tries to update or delete an APN through this URI. We should let ApnPrefence starts an intent with URI content://telephony/carrier/id, which is a general telephony URI and all of query() add() delete() update() are implemented for non-DPC mode. And let ApnPrefence starts an intent with URI content://telephony/carrier/filtered/id in DPC mode(as the general URI can't access DPC-owned APN), when only DPC-owned APNs are presented to user. In the DPC mode, user can't update, add or delete an APN, they can only view(query) the APN, so it won't crash with URI_FILTERED. Bug: 72387301 Test: manual. Tried update, delete, and add action in Access Point Name page, no crash occurs. Instrumentation test will be added in b/72154761. Change-Id: I9979cbffcc94a37b2bd96db766ececd0ac7b20e2 --- src/com/android/settings/ApnPreference.java | 9 ++++++++- src/com/android/settings/ApnSettings.java | 5 ++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/com/android/settings/ApnPreference.java b/src/com/android/settings/ApnPreference.java index 4e89efc781c..9a6eeaf46da 100755 --- a/src/com/android/settings/ApnPreference.java +++ b/src/com/android/settings/ApnPreference.java @@ -16,6 +16,7 @@ package com.android.settings; +import static android.provider.Telephony.Carriers.CONTENT_URI; import static android.provider.Telephony.Carriers.FILTERED_URI; import android.content.ContentUris; @@ -36,6 +37,7 @@ import android.widget.RelativeLayout; public class ApnPreference extends Preference implements CompoundButton.OnCheckedChangeListener, OnClickListener { final static String TAG = "ApnPreference"; + private boolean mDpcEnforced = false; private int mSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; @@ -119,7 +121,8 @@ public class ApnPreference extends Preference implements Context context = getContext(); if (context != null) { int pos = Integer.parseInt(getKey()); - Uri url = ContentUris.withAppendedId(FILTERED_URI, pos); + Uri url = ContentUris.withAppendedId( + mDpcEnforced ? FILTERED_URI : CONTENT_URI, pos); Intent editIntent = new Intent(Intent.ACTION_EDIT, url); editIntent.putExtra(ApnSettings.SUB_ID, mSubId); context.startActivity(editIntent); @@ -138,4 +141,8 @@ public class ApnPreference extends Preference implements public void setSubId(int subId) { mSubId = subId; } + + public void setDpcEnforced(boolean enforced) { + mDpcEnforced = enforced; + } } diff --git a/src/com/android/settings/ApnSettings.java b/src/com/android/settings/ApnSettings.java index 3628121808e..2c22a790e8d 100755 --- a/src/com/android/settings/ApnSettings.java +++ b/src/com/android/settings/ApnSettings.java @@ -16,6 +16,7 @@ package com.android.settings; +import static android.provider.Telephony.Carriers.CONTENT_URI; import static android.provider.Telephony.Carriers.ENFORCE_MANAGED_URI; import static android.provider.Telephony.Carriers.FILTERED_URI; @@ -291,6 +292,7 @@ public class ApnSettings extends RestrictedSettingsFragment implements mSelectedKey = getSelectedApnKey(); cursor.moveToFirst(); + boolean enforced = isDpcApnEnforced(); while (!cursor.isAfterLast()) { String name = cursor.getString(NAME_INDEX); String apn = cursor.getString(APN_INDEX); @@ -307,6 +309,7 @@ public class ApnSettings extends RestrictedSettingsFragment implements pref.setPersistent(false); pref.setOnPreferenceChangeListener(this); pref.setSubId(subId); + pref.setDpcEnforced(enforced); boolean selectable = ((type == null) || !type.equals("mms")); pref.setSelectable(selectable); @@ -398,7 +401,7 @@ public class ApnSettings extends RestrictedSettingsFragment implements @Override public boolean onPreferenceTreeClick(Preference preference) { int pos = Integer.parseInt(preference.getKey()); - Uri url = ContentUris.withAppendedId(FILTERED_URI, pos); + Uri url = ContentUris.withAppendedId(isDpcApnEnforced() ? FILTERED_URI : CONTENT_URI, pos); startActivity(new Intent(Intent.ACTION_EDIT, url)); return true; }