diff options
author | kenshin <foufou33@gmail.com> | 2012-05-05 10:12:35 -0400 |
---|---|---|
committer | kenshin <foufou33@gmail.com> | 2012-05-05 10:12:35 -0400 |
commit | 779b5ef980722ce1a28b9141a33c345b62ca7307 (patch) | |
tree | 5cb235c7e75aebf73bd5fb2781a5ca12069b6666 | |
parent | 258b9be2dba0d77d20b7b66c0353885249fc2839 (diff) | |
download | packages_apps_Contacts-779b5ef980722ce1a28b9141a33c345b62ca7307.tar.gz packages_apps_Contacts-779b5ef980722ce1a28b9141a33c345b62ca7307.tar.bz2 packages_apps_Contacts-779b5ef980722ce1a28b9141a33c345b62ca7307.zip |
Add lookup in Call logs to lookupNumber
http://review.cyanogenmod.com/#/c/11168/ added caller name display
to GSM phones. But whenever Call log is opened the information was overwritten,
if no contact is present with that phoen number.
This patch add a lookup function that tries to find a match in the Call log
(after other posibilities failed) and returns that information to be put in cache.
Change-Id: Iefdd134bd1fffe392f0b9adf64e8c2d0494a5539
-rw-r--r-- | src/com/android/contacts/calllog/ContactInfoHelper.java | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/src/com/android/contacts/calllog/ContactInfoHelper.java b/src/com/android/contacts/calllog/ContactInfoHelper.java index 90d5e8b0b..083ec2711 100644 --- a/src/com/android/contacts/calllog/ContactInfoHelper.java +++ b/src/com/android/contacts/calllog/ContactInfoHelper.java @@ -21,6 +21,8 @@ import com.android.contacts.util.UriUtils; import android.content.Context; import android.database.Cursor; import android.net.Uri; +import android.provider.CallLog; +import android.provider.CallLog.Calls; import android.provider.ContactsContract.Contacts; import android.provider.ContactsContract.PhoneLookup; import android.telephony.PhoneNumberUtils; @@ -72,6 +74,11 @@ public class ContactInfoHelper { if (phoneInfo == null || phoneInfo == ContactInfo.EMPTY) { // Check whether the phone number has been saved as an "Internet call" number. phoneInfo = queryContactInfoForSipAddress(number); + + if (phoneInfo == null || phoneInfo == ContactInfo.EMPTY) { + //Check contact in Calllog may we have some info there + phoneInfo = queryContactInfoForPhoneNumberFromCallLog(number, countryIso); + } } info = phoneInfo; } @@ -187,6 +194,63 @@ public class ContactInfoHelper { return info; } + + /** + * Determines the contact information stored in the call log for the given phone number. + * <p> + * It returns the contact info if found. + * <p> + * If no contact corresponds to the given phone number, returns {@link ContactInfo#EMPTY}. + * <p> + * If the lookup fails for some other reason, it returns null. + */ + private ContactInfo queryContactInfoForPhoneNumberFromCallLog(String number, String countryIso) { + final ContactInfo info; + String contactNumber = number; + if (!TextUtils.isEmpty(countryIso)) { + // Normalize the number: this is needed because the PhoneLookup query below does not + // accept a country code as an input. + String numberE164 = PhoneNumberUtils.formatNumberToE164(number, countryIso); + if (!TextUtils.isEmpty(numberE164)) { + // Only use it if the number could be formatted to E164. + contactNumber = numberE164; + } + } + + // The "contactNumber" is a regular phone number, so use the CallLog table. + Uri uri = Uri.withAppendedPath(CallLog.Calls.CONTENT_FILTER_URI, Uri.encode(contactNumber)); + Cursor c = mContext.getContentResolver().query( + uri, + CallLogQuery._PROJECTION, + null, + null, + Calls.DEFAULT_SORT_ORDER + " LIMIT 1"); + + if (c != null) { + try { + if (c.moveToFirst()){ + info = new ContactInfo(); + info.lookupUri = UriUtils.parseUriOrNull(c.getString(CallLogQuery.CACHED_LOOKUP_URI)); + info.name = c.getString(CallLogQuery.CACHED_NAME); + info.type = c.getInt(CallLogQuery.CACHED_NUMBER_TYPE); + info.label = c.getString(CallLogQuery.CACHED_NUMBER_LABEL); + String matchedNumber = c.getString(CallLogQuery.CACHED_MATCHED_NUMBER); + info.number = matchedNumber == null ? c.getString(CallLogQuery.NUMBER) : matchedNumber; + info.normalizedNumber = c.getString(CallLogQuery.CACHED_NORMALIZED_NUMBER); + info.photoId = c.getLong(CallLogQuery.CACHED_PHOTO_ID); + info.photoUri = null; // We do not cache the photo URI. + info.formattedNumber = c.getString(CallLogQuery.CACHED_FORMATTED_NUMBER); + } else { + info = ContactInfo.EMPTY; + } + }finally { + c.close(); + } + } else { + info = null; + } + return info; + } /** * Format the given phone number * |