Skip to content

Commit 9ffa500

Browse files
author
Christoph Studer
committed
NoMan: Evaluate all contacts matching EXTRA_PEOPLE URI
Bug: 17660485 Change-Id: I8684067538fcd2d43a9f95c6aa707b275b13ee40
1 parent 2086787 commit 9ffa500

1 file changed

Lines changed: 29 additions & 33 deletions

File tree

services/core/java/com/android/server/notification/ValidateNotificationPeople.java

Lines changed: 29 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ private PeopleRankingReconsideration validatePeople(Context context, String key,
231231
if (lookupResult == null || lookupResult.isExpired()) {
232232
pendingLookups.add(handle);
233233
} else {
234-
if (DEBUG) Slog.d(TAG, "using cached lookupResult: " + lookupResult.mId);
234+
if (DEBUG) Slog.d(TAG, "using cached lookupResult");
235235
}
236236
if (lookupResult != null) {
237237
affinity = Math.max(affinity, lookupResult.getAffinity());
@@ -336,11 +336,14 @@ private LookupResult searchContacts(Context context, Uri lookupUri) {
336336
Cursor c = null;
337337
try {
338338
c = context.getContentResolver().query(lookupUri, LOOKUP_PROJECTION, null, null, null);
339-
if (c != null && c.getCount() > 0) {
340-
c.moveToFirst();
341-
lookupResult.readContact(c);
339+
if (c == null) {
340+
Slog.w(TAG, "Null cursor from contacts query.");
341+
return lookupResult;
342342
}
343-
} catch(Throwable t) {
343+
while (c.moveToNext()) {
344+
lookupResult.mergeContact(c);
345+
}
346+
} catch (Throwable t) {
344347
Slog.w(TAG, "Problem getting content resolver or performing contacts query.", t);
345348
} finally {
346349
if (c != null) {
@@ -352,61 +355,54 @@ private LookupResult searchContacts(Context context, Uri lookupUri) {
352355

353356
private static class LookupResult {
354357
private static final long CONTACT_REFRESH_MILLIS = 60 * 60 * 1000; // 1hr
355-
public static final int INVALID_ID = -1;
356358

357359
private final long mExpireMillis;
358-
private int mId;
359-
private boolean mStarred;
360+
private float mAffinity = NONE;
360361

361362
public LookupResult() {
362-
mId = INVALID_ID;
363-
mStarred = false;
364363
mExpireMillis = System.currentTimeMillis() + CONTACT_REFRESH_MILLIS;
365364
}
366365

367-
public void readContact(Cursor cursor) {
366+
public void mergeContact(Cursor cursor) {
367+
mAffinity = Math.max(mAffinity, VALID_CONTACT);
368+
369+
// Contact ID
370+
int id;
368371
final int idIdx = cursor.getColumnIndex(Contacts._ID);
369372
if (idIdx >= 0) {
370-
mId = cursor.getInt(idIdx);
371-
if (DEBUG) Slog.d(TAG, "contact _ID is: " + mId);
373+
id = cursor.getInt(idIdx);
374+
if (DEBUG) Slog.d(TAG, "contact _ID is: " + id);
372375
} else {
373-
if (DEBUG) Slog.d(TAG, "invalid cursor: no _ID");
376+
id = -1;
377+
Slog.i(TAG, "invalid cursor: no _ID");
374378
}
379+
380+
// Starred
375381
final int starIdx = cursor.getColumnIndex(Contacts.STARRED);
376382
if (starIdx >= 0) {
377-
mStarred = cursor.getInt(starIdx) != 0;
378-
if (DEBUG) Slog.d(TAG, "contact STARRED is: " + mStarred);
383+
boolean isStarred = cursor.getInt(starIdx) != 0;
384+
if (isStarred) {
385+
mAffinity = Math.max(mAffinity, STARRED_CONTACT);
386+
}
387+
if (DEBUG) Slog.d(TAG, "contact STARRED is: " + isStarred);
379388
} else {
380389
if (DEBUG) Slog.d(TAG, "invalid cursor: no STARRED");
381390
}
382391
}
383392

384-
public boolean isExpired() {
393+
private boolean isExpired() {
385394
return mExpireMillis < System.currentTimeMillis();
386395
}
387396

388-
public boolean isInvalid() {
389-
return mId == INVALID_ID || isExpired();
397+
private boolean isInvalid() {
398+
return mAffinity == NONE || isExpired();
390399
}
391400

392401
public float getAffinity() {
393402
if (isInvalid()) {
394403
return NONE;
395-
} else if (mStarred) {
396-
return STARRED_CONTACT;
397-
} else {
398-
return VALID_CONTACT;
399404
}
400-
}
401-
402-
public LookupResult setStarred(boolean starred) {
403-
mStarred = starred;
404-
return this;
405-
}
406-
407-
public LookupResult setId(int id) {
408-
mId = id;
409-
return this;
405+
return mAffinity;
410406
}
411407
}
412408

0 commit comments

Comments
 (0)