Handle the case of a null cursor being returned.
While unlikely, it is possible for the content resolver to return a null
cursor. Instead of crashing with a NullPointerException, handle this
case gracefully.
Bug: 5642539
Change-Id: I69423c32a124e3e7c8d6734e5561c316919eb1b4
diff --git a/src/com/android/contacts/calllog/DefaultVoicemailNotifier.java b/src/com/android/contacts/calllog/DefaultVoicemailNotifier.java
index c5e8f91..dc31bb2 100644
--- a/src/com/android/contacts/calllog/DefaultVoicemailNotifier.java
+++ b/src/com/android/contacts/calllog/DefaultVoicemailNotifier.java
@@ -90,6 +90,11 @@
// TODO: Move this into a service, to avoid holding the receiver up.
final NewCall[] newCalls = mNewCallsQuery.query();
+ if (newCalls == null) {
+ // Query failed, just return.
+ return;
+ }
+
if (newCalls.length == 0) {
Log.e(TAG, "No voicemails to notify about: clear the notification.");
clearNotification();
@@ -243,6 +248,9 @@
try {
cursor = mContentResolver.query(Calls.CONTENT_URI_WITH_VOICEMAIL, PROJECTION,
selection, selectionArgs, Calls.DEFAULT_SORT_ORDER);
+ if (cursor == null) {
+ return null;
+ }
NewCall[] newCalls = new NewCall[cursor.getCount()];
while (cursor.moveToNext()) {
newCalls[cursor.getPosition()] = createNewCallsFromCursor(cursor);
@@ -301,7 +309,7 @@
cursor = mContentResolver.query(
Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number)),
PROJECTION, null, null, null);
- if (!cursor.moveToFirst()) return null;
+ if (cursor == null || !cursor.moveToFirst()) return null;
return cursor.getString(DISPLAY_NAME_COLUMN_INDEX);
} finally {
if (cursor != null) {