diff options
author | Tony Mak <tonymak@google.com> | 2016-02-11 21:21:30 +0000 |
---|---|---|
committer | Tony Mak <tonymak@google.com> | 2016-02-11 21:21:30 +0000 |
commit | 328f75ff518bf7d8863c6cf4446e26636e05b297 (patch) | |
tree | e0f06d2d23f2f23dc716d848743bec03099431c1 /src/com/android/dialer/calllog | |
parent | c52bc27da2a7e1e20a138d536fa0f4aad4f9a8c4 (diff) |
Use DATA.CONTACT_ID when lookup SIP call
It is actually a naming mistake in framework, the column store contact id
of normal query is _id, but that of sip query is contact_id.
It is an old issue and we can't do much in the framework side.
So, we need to use the correct projection when it is a SIP call.
Bug:27143980
Bug:27141566
Change-Id: I6a7eb6952f9cec5b8ea2461540806224c7a69640
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; |