summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/com/android/dialer/calllog/ContactInfoHelper.java20
-rw-r--r--src/com/android/dialer/calllog/PhoneQuery.java21
-rw-r--r--tests/src/com/android/dialer/calllog/ContactInfoHelperTest.java8
3 files changed, 36 insertions, 13 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;
diff --git a/tests/src/com/android/dialer/calllog/ContactInfoHelperTest.java b/tests/src/com/android/dialer/calllog/ContactInfoHelperTest.java
index 588a27fcf..0e032c15f 100644
--- a/tests/src/com/android/dialer/calllog/ContactInfoHelperTest.java
+++ b/tests/src/com/android/dialer/calllog/ContactInfoHelperTest.java
@@ -58,7 +58,7 @@ public class ContactInfoHelperTest extends AndroidTestCase {
}
public void testLookupContactFromUri_NullUri() {
- Assert.assertNull(mContactInfoHelper.lookupContactFromUri(null));
+ Assert.assertNull(mContactInfoHelper.lookupContactFromUri(null, false));
}
public void testLookupContactFromUri_NoResults() {
@@ -66,7 +66,7 @@ public class ContactInfoHelperTest extends AndroidTestCase {
PhoneQuery.PHONE_LOOKUP_PROJECTION);
Assert.assertEquals(ContactInfo.EMPTY, mContactInfoHelper.lookupContactFromUri(
- PhoneLookup.ENTERPRISE_CONTENT_FILTER_URI));
+ PhoneLookup.ENTERPRISE_CONTENT_FILTER_URI, false));
mContext.verify();
}
@@ -77,7 +77,7 @@ public class ContactInfoHelperTest extends AndroidTestCase {
PhoneQuery.DISPLAY_NAME_ALTERNATIVE_PROJECTION);
ContactInfo contactInfo = mContactInfoHelper.lookupContactFromUri(
- PhoneLookup.ENTERPRISE_CONTENT_FILTER_URI);
+ PhoneLookup.ENTERPRISE_CONTENT_FILTER_URI, false);
Assert.assertEquals(TEST_DISPLAY_NAME, contactInfo.name);
Assert.assertNull(contactInfo.nameAlternative);
mContext.verify();
@@ -90,7 +90,7 @@ public class ContactInfoHelperTest extends AndroidTestCase {
PhoneQuery.DISPLAY_NAME_ALTERNATIVE_PROJECTION, TEST_DISPLAY_NAME_ALTERNATIVE_ROW);
ContactInfo contactInfo = mContactInfoHelper.lookupContactFromUri(
- PhoneLookup.ENTERPRISE_CONTENT_FILTER_URI);
+ PhoneLookup.ENTERPRISE_CONTENT_FILTER_URI, false);
Assert.assertEquals(TEST_DISPLAY_NAME, contactInfo.name);
Assert.assertEquals(TEST_DISPLAY_NAME_ALTERNATIVE, contactInfo.nameAlternative);
mContext.verify();