diff --git a/services/core/java/com/android/server/notification/CalendarTracker.java b/services/core/java/com/android/server/notification/CalendarTracker.java index 5d50f3b7947fe..d42c7c1939a2a 100644 --- a/services/core/java/com/android/server/notification/CalendarTracker.java +++ b/services/core/java/com/android/server/notification/CalendarTracker.java @@ -180,12 +180,12 @@ public class CalendarTracker { final Cursor cursor = mUserContext.getContentResolver().query(Attendees.CONTENT_URI, ATTENDEE_PROJECTION, selection, selectionArgs, null); try { - if (cursor.getCount() == 0) { + if (cursor == null || cursor.getCount() == 0) { if (DEBUG) Log.d(TAG, "No attendees found"); return true; } boolean rt = false; - while (cursor.moveToNext()) { + while (cursor != null && cursor.moveToNext()) { final long rowEventId = cursor.getLong(0); final String rowEmail = cursor.getString(1); final int status = cursor.getInt(2); @@ -200,7 +200,9 @@ public class CalendarTracker { } return rt; } finally { - cursor.close(); + if (cursor != null) { + cursor.close(); + } if (DEBUG) Log.d(TAG, "meetsAttendee took " + (System.currentTimeMillis() - start)); } }