Skip to content

Commit 4e9c63c

Browse files
rpiusAndroid (Google) Code Review
authored andcommitted
Merge "Handle exceptions when accessing Content providers." into mnc-dev
2 parents 68fd7c7 + 93018a4 commit 4e9c63c

2 files changed

Lines changed: 22 additions & 10 deletions

File tree

telephony/java/android/telephony/PhoneNumberUtils.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,15 +177,19 @@ public static String getNumberFromIntent(Intent intent, Context context) {
177177
phoneColumn = ContactsContract.CommonDataKinds.Phone.NUMBER;
178178
}
179179

180-
final Cursor c = context.getContentResolver().query(uri, new String[] {
181-
phoneColumn
182-
}, null, null, null);
183-
if (c != null) {
184-
try {
180+
Cursor c = null;
181+
try {
182+
c = context.getContentResolver().query(uri, new String[] { phoneColumn },
183+
null, null, null);
184+
if (c != null) {
185185
if (c.moveToFirst()) {
186186
number = c.getString(c.getColumnIndex(phoneColumn));
187187
}
188-
} finally {
188+
}
189+
} catch (RuntimeException e) {
190+
Rlog.e(LOG_TAG, "Error getting phone number.", e);
191+
} finally {
192+
if (c != null) {
189193
c.close();
190194
}
191195
}

telephony/java/com/android/internal/telephony/CallerInfo.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package com.android.internal.telephony;
1818

19+
import android.content.ContentResolver;
1920
import android.content.Context;
2021
import android.database.Cursor;
2122
import android.graphics.Bitmap;
@@ -282,10 +283,17 @@ public static CallerInfo getCallerInfo(Context context, Uri contactRef, Cursor c
282283
* number. The returned CallerInfo is null if no number is supplied.
283284
*/
284285
public static CallerInfo getCallerInfo(Context context, Uri contactRef) {
285-
286-
return getCallerInfo(context, contactRef,
287-
CallerInfoAsyncQuery.getCurrentProfileContentResolver(context)
288-
.query(contactRef, null, null, null, null));
286+
CallerInfo info = null;
287+
ContentResolver cr = CallerInfoAsyncQuery.getCurrentProfileContentResolver(context);
288+
if (cr != null) {
289+
try {
290+
info = getCallerInfo(context, contactRef,
291+
cr.query(contactRef, null, null, null, null));
292+
} catch (RuntimeException re) {
293+
Rlog.e(TAG, "Error getting caller info.", re);
294+
}
295+
}
296+
return info;
289297
}
290298

291299
/**

0 commit comments

Comments
 (0)