diff options
author | Tony Mak <tonymak@google.com> | 2016-02-12 10:13:57 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2016-02-12 10:13:57 +0000 |
commit | 0b8571824768f6c2b8c168cb350bcbc643364daa (patch) | |
tree | 9d4d3ee8a3bbd0fca46408c55206820157bafda3 /src/com/android/dialer/calllog | |
parent | e69ab63eac4cebf71da89de42c91b694ba18c34e (diff) | |
parent | 328f75ff518bf7d8863c6cf4446e26636e05b297 (diff) |
Merge "Use DATA.CONTACT_ID when lookup SIP call"
Diffstat (limited to 'src/com/android/dialer/calllog')
-rw-r--r-- | src/com/android/dialer/calllog/ContactInfoHelper.java | 20 | ||||
-rw-r--r-- | src/com/android/dialer/calllog/PhoneQuery.java | 21 |
2 files changed, 32 insertions, 9 deletions
diff --git a/src/com/android/dialer/calllog/ContactInfoHelper.java b/src/com/android/dialer/calllog/ContactInfoHelper.java index 7f08fdc18..75e7ab746 100644 --- a/src/com/android/dialer/calllog/ContactInfoHelper.java +++ b/src/com/android/dialer/calllog/ContactInfoHelper.java @@ -40,6 +40,7 @@ import com.android.dialer.service.CachedNumberLookupService; import com.android.dialer.service.CachedNumberLookupService.CachedContactInfo; import com.android.dialer.util.TelecomUtil; import com.android.dialerbind.ObjectFactory; +import com.google.common.annotations.VisibleForTesting; import org.json.JSONException; import org.json.JSONObject; @@ -82,17 +83,17 @@ public class ContactInfoHelper { if (PhoneNumberHelper.isUriNumber(number)) { // The number is a SIP address.. - info = lookupContactFromUri(getContactInfoLookupUri(number)); + info = lookupContactFromUri(getContactInfoLookupUri(number), true); if (info == null || info == ContactInfo.EMPTY) { // If lookup failed, check if the "username" of the SIP address is a phone number. String username = PhoneNumberHelper.getUsernameFromUriNumber(number); if (PhoneNumberUtils.isGlobalPhoneNumber(username)) { - info = queryContactInfoForPhoneNumber(username, countryIso); + info = queryContactInfoForPhoneNumber(username, countryIso, true); } } } else { // Look for a contact that has the given phone number. - info = queryContactInfoForPhoneNumber(number, countryIso); + info = queryContactInfoForPhoneNumber(number, countryIso, false); } final ContactInfo updatedInfo; @@ -153,7 +154,7 @@ public class ContactInfoHelper { * The {@link ContactInfo#formattedNumber} field is always set to {@code null} in the returned * value. */ - public ContactInfo lookupContactFromUri(Uri uri) { + ContactInfo lookupContactFromUri(Uri uri, boolean isSip) { if (uri == null) { return null; } @@ -163,8 +164,10 @@ public class ContactInfoHelper { Cursor phoneLookupCursor = null; try { - phoneLookupCursor = mContext.getContentResolver().query(uri, - PhoneQuery.PHONE_LOOKUP_PROJECTION, null, null, null); + String[] projection = (isSip) ? PhoneQuery.SIP_PHONE_LOOKUP_PROJECTION + : PhoneQuery.PHONE_LOOKUP_PROJECTION; + phoneLookupCursor = mContext.getContentResolver().query(uri, projection, null, null, + null); } catch (NullPointerException e) { // Trap NPE from pre-N CP2 return null; @@ -241,12 +244,13 @@ public class ContactInfoHelper { * <p> * If the lookup fails for some other reason, it returns null. */ - private ContactInfo queryContactInfoForPhoneNumber(String number, String countryIso) { + private ContactInfo queryContactInfoForPhoneNumber(String number, String countryIso, + boolean isSip) { if (TextUtils.isEmpty(number)) { return null; } - ContactInfo info = lookupContactFromUri(getContactInfoLookupUri(number)); + ContactInfo info = lookupContactFromUri(getContactInfoLookupUri(number), isSip); if (info != null && info != ContactInfo.EMPTY) { info.formattedNumber = formatPhoneNumber(number, null, countryIso); } else if (mCachedNumberLookupService != null) { diff --git a/src/com/android/dialer/calllog/PhoneQuery.java b/src/com/android/dialer/calllog/PhoneQuery.java index 200b5e1f4..5261874c8 100644 --- a/src/com/android/dialer/calllog/PhoneQuery.java +++ b/src/com/android/dialer/calllog/PhoneQuery.java @@ -17,6 +17,7 @@ package com.android.dialer.calllog; import android.provider.ContactsContract.Contacts; +import android.provider.ContactsContract.Data; import android.provider.ContactsContract.PhoneLookup; /** @@ -37,7 +38,25 @@ final class PhoneQuery { PhoneLookup.NORMALIZED_NUMBER, PhoneLookup.PHOTO_ID, PhoneLookup.LOOKUP_KEY, - PhoneLookup.PHOTO_URI}; + PhoneLookup.PHOTO_URI + }; + + /** + * Similar to {@link PHONE_LOOKUP_PROJECTION}. Due to a bug in framework, the column name of + * contact id in normal phonelookup query is _id, but that in sip phonelookup query is + * contact_id. + */ + public static final String[] SIP_PHONE_LOOKUP_PROJECTION = new String[] { + Data.CONTACT_ID, + PhoneLookup.DISPLAY_NAME, + PhoneLookup.TYPE, + PhoneLookup.LABEL, + PhoneLookup.NUMBER, + PhoneLookup.NORMALIZED_NUMBER, + PhoneLookup.PHOTO_ID, + PhoneLookup.LOOKUP_KEY, + PhoneLookup.PHOTO_URI + }; public static final int PERSON_ID = 0; public static final int NAME = 1; |