From 0d2ed5aa12839d3fc15ac9c769b28f564da53df7 Mon Sep 17 00:00:00 2001 From: Raj Yengisetty Date: Tue, 10 Mar 2015 10:08:23 -0700 Subject: ContactsCommon: fix FC when deleting SIM contacts after SIM is removed Repro: - Create local contact - Export to SIM - Remove SIM - Go to delete menu option - Select all (*include* exported SIM contact) - Click check mark - Observe Contacts app force closes when deleting the exported contact Change-Id: I2bfecf8b19c8f1eae9559a4e6f46ff477da4dc74 --- src/com/android/contacts/common/SimContactsOperation.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/com/android/contacts/common/SimContactsOperation.java b/src/com/android/contacts/common/SimContactsOperation.java index 55c7b79f..fe1d85c1 100644 --- a/src/com/android/contacts/common/SimContactsOperation.java +++ b/src/com/android/contacts/common/SimContactsOperation.java @@ -92,6 +92,9 @@ public class SimContactsOperation { public Uri insert(ContentValues values, int subscription) { Uri uri = getContentUri(subscription); + if (uri == null) { + return null; + } String number = values.getAsString(SimContactsConstants.STR_NUMBER); String anrs = values.getAsString(SimContactsConstants.STR_ANRS); String emails = values.getAsString(SimContactsConstants.STR_EMAILS); @@ -106,7 +109,9 @@ public class SimContactsOperation { public int update(ContentValues values,int subscription) { Uri uri = getContentUri(subscription); - + if (uri == null) { + return -1; + } int result; String oldNumber = values.getAsString(SimContactsConstants.STR_NUMBER); String newNumber = values.getAsString(SimContactsConstants.STR_NEW_NUMBER); @@ -136,6 +141,10 @@ public class SimContactsOperation { anrs = PhoneNumberUtils.stripSeparators(anrs); Uri uri = getContentUri(subscription); + if (uri == null) { + return -1; + } + if (!TextUtils.isEmpty(name)) { buf.append("tag='"); @@ -168,6 +177,9 @@ public class SimContactsOperation { long[] subId = SubscriptionManager.getSubId(subscription); if (subId != null && TelephonyManager.getDefault().isMultiSimEnabled()) { + if (subId.length < 1 || subId[0] < 0) { + return null; + } uri = Uri.parse(SimContactsConstants.SIM_SUB_URI + subId[0]); } else { uri = Uri.parse(SimContactsConstants.SIM_URI); -- cgit v1.2.3