From 1dbbda3b035f2e1e581bb8c403b1d351d2ccdbc9 Mon Sep 17 00:00:00 2001 From: Victor Chang Date: Mon, 1 Feb 2016 19:54:33 +0000 Subject: Show work call title for missed call notification 1. return complete ContactInfo in CallLogNotificationsHelper 2. use ContactInfo.userType to decide use work call title or not BUG=26902076 Change-Id: Ic58fea1002de053ba69bc0aff06691b8a8605e64 --- .../dialer/calllog/CallLogNotificationsHelper.java | 63 +++++++++++++++------- 1 file changed, 44 insertions(+), 19 deletions(-) (limited to 'src/com/android/dialer/calllog/CallLogNotificationsHelper.java') diff --git a/src/com/android/dialer/calllog/CallLogNotificationsHelper.java b/src/com/android/dialer/calllog/CallLogNotificationsHelper.java index 64ccd5f88..6abf241b4 100644 --- a/src/com/android/dialer/calllog/CallLogNotificationsHelper.java +++ b/src/com/android/dialer/calllog/CallLogNotificationsHelper.java @@ -26,6 +26,7 @@ import android.database.Cursor; import android.net.Uri; import android.provider.CallLog.Calls; import android.provider.ContactsContract.PhoneLookup; +import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.telephony.PhoneNumberUtils; import android.text.TextUtils; @@ -104,37 +105,61 @@ public class CallLogNotificationsHelper { */ public String getName(@Nullable String number, int numberPresentation, @Nullable String countryIso) { - String name = PhoneNumberDisplayUtil.getDisplayName( + return getContactInfo(number, numberPresentation, countryIso).name; + } + + /** + * Given a number and number information (presentation and country ISO), get + * {@link ContactInfo}. If the name is empty but we have a special presentation, display that. + * Otherwise attempt to look it up in the database or the cache. + * If that fails, fall back to displaying the number. + */ + public @NonNull ContactInfo getContactInfo(@Nullable String number, int numberPresentation, + @Nullable String countryIso) { + if (countryIso == null) { + countryIso = mCurrentCountryIso; + } + + ContactInfo contactInfo = new ContactInfo(); + contactInfo.number = number; + contactInfo.formattedNumber = PhoneNumberUtils.formatNumber(number, countryIso); + // contactInfo.normalizedNumber is not PhoneNumberUtils.normalizeNumber. Read ContactInfo. + contactInfo.normalizedNumber = PhoneNumberUtils.formatNumberToE164(number, countryIso); + + // 1. Special number representation. + contactInfo.name = PhoneNumberDisplayUtil.getDisplayName( mContext, number, numberPresentation, false).toString(); - if (!TextUtils.isEmpty(name)) { - return name; + if (!TextUtils.isEmpty(contactInfo.name)) { + return contactInfo; } - // Look it up in the database. - name = mNameLookupQuery.query(number); - if (!TextUtils.isEmpty(name)) { - return name; - } - - if (countryIso == null) { - countryIso = mCurrentCountryIso; + // 2. Personal ContactsProvider phonelookup query. + contactInfo.name = mNameLookupQuery.query(number); + if (!TextUtils.isEmpty(contactInfo.name)) { + return contactInfo; } - // Look it up in the cache - ContactInfo contactInfo = mContactInfoHelper.lookupNumber(number, countryIso); + // 3. Look it up in the cache. + ContactInfo cachedContactInfo = mContactInfoHelper.lookupNumber(number, countryIso); - if (contactInfo != null && !TextUtils.isEmpty(contactInfo.name)) { - return contactInfo.name; + if (cachedContactInfo != null && !TextUtils.isEmpty(cachedContactInfo.name)) { + return cachedContactInfo; } - if (!TextUtils.isEmpty(number)) { - // If we cannot lookup the contact, use the number instead. - return PhoneNumberUtils.formatNumber(number, countryIso); + if (!TextUtils.isEmpty(contactInfo.formattedNumber)) { + // 4. If we cannot lookup the contact, use the formatted number instead. + contactInfo.name = contactInfo.formattedNumber; + } else if (!TextUtils.isEmpty(number)) { + // 5. If number can't be formatted, use number. + contactInfo.name = number; + } else { + // 6. Otherwise, it's unknown number. + contactInfo.name = mContext.getResources().getString(R.string.unknown); } - return mContext.getResources().getString(R.string.unknown); + return contactInfo; } /** Removes the missed call notifications. */ -- cgit v1.2.3