diff options
author | linyuh <linyuh@google.com> | 2017-12-12 22:50:06 -0800 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2017-12-12 22:52:11 -0800 |
commit | e7ea93d5235c097151e40f8922a1efb000734904 (patch) | |
tree | 5d6c024860bd04bd36a226d6a72aa75acdb146d8 /java/com/android/dialer/phonenumbercache | |
parent | a4745bddb3a012c826225df313820ccd8a68455d (diff) |
Refactor CallerInfo and ContactInfoHelper to improve readability.
Test: Existing tests
PiperOrigin-RevId: 178862915
Change-Id: I2dd58db10d546c062b0f43dad80f74d588cb65e1
Diffstat (limited to 'java/com/android/dialer/phonenumbercache')
-rw-r--r-- | java/com/android/dialer/phonenumbercache/ContactInfoHelper.java | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/java/com/android/dialer/phonenumbercache/ContactInfoHelper.java b/java/com/android/dialer/phonenumbercache/ContactInfoHelper.java index c3f5b692f..39e3866cf 100644 --- a/java/com/android/dialer/phonenumbercache/ContactInfoHelper.java +++ b/java/com/android/dialer/phonenumbercache/ContactInfoHelper.java @@ -337,30 +337,28 @@ public class ContactInfoHelper { return ContactInfo.EMPTY; } - Cursor phoneLookupCursor = null; - try { - String[] projection = PhoneQuery.getPhoneLookupProjection(uri); - phoneLookupCursor = mContext.getContentResolver().query(uri, projection, null, null, null); - } catch (NullPointerException e) { - LogUtil.e("ContactInfoHelper.lookupContactFromUri", "phone lookup", e); - // Trap NPE from pre-N CP2 - return null; - } - if (phoneLookupCursor == null) { - LogUtil.d("ContactInfoHelper.lookupContactFromUri", "phoneLookupCursor is null"); - return null; - } + try (Cursor phoneLookupCursor = + mContext + .getContentResolver() + .query( + uri, + PhoneQuery.getPhoneLookupProjection(uri), + null /* selection */, + null /* selectionArgs */, + null /* sortOrder */)) { + if (phoneLookupCursor == null) { + LogUtil.d("ContactInfoHelper.lookupContactFromUri", "phoneLookupCursor is null"); + return null; + } - try { if (!phoneLookupCursor.moveToFirst()) { return ContactInfo.EMPTY; } + String lookupKey = phoneLookupCursor.getString(PhoneQuery.LOOKUP_KEY); ContactInfo contactInfo = createPhoneLookupContactInfo(phoneLookupCursor, lookupKey); fillAdditionalContactInfo(mContext, contactInfo); return contactInfo; - } finally { - phoneLookupCursor.close(); } } |