summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--res/values/strings.xml2
-rw-r--r--src/com/android/dialer/calllog/CallLogNotificationsHelper.java63
-rw-r--r--src/com/android/dialer/calllog/ContactInfo.java9
-rw-r--r--src/com/android/dialer/calllog/MissedCallNotifier.java13
4 files changed, 64 insertions, 23 deletions
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 7e87b2fb0..ed88b960f 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -106,6 +106,8 @@
<!-- Notification strings -->
<!-- Missed call notification label, used when there's exactly one missed call -->
<string name="notification_missedCallTitle">Missed call</string>
+ <!-- Missed call notification label, used when there's exactly one missed call from work contact -->
+ <string name="notification_missedWorkCallTitle">Missed work call</string>
<!-- Missed call notification label, used when there are two or more missed calls -->
<string name="notification_missedCallsTitle">Missed calls</string>
<!-- Missed call notification message used when there are multiple missed calls -->
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. */
diff --git a/src/com/android/dialer/calllog/ContactInfo.java b/src/com/android/dialer/calllog/ContactInfo.java
index 40d963e4e..8fe4964bc 100644
--- a/src/com/android/dialer/calllog/ContactInfo.java
+++ b/src/com/android/dialer/calllog/ContactInfo.java
@@ -40,6 +40,15 @@ public class ContactInfo {
public String label;
public String number;
public String formattedNumber;
+ /*
+ * ContactInfo.normalizedNumber is a column value returned by PhoneLookup query. By definition,
+ * it's E164 representation.
+ * http://developer.android.com/reference/android/provider/ContactsContract.PhoneLookupColumns.
+ * html#NORMALIZED_NUMBER.
+ *
+ * The fallback value, when PhoneLookup fails or else, should be either null or
+ * PhoneNumberUtils.formatNumberToE164.
+ */
public String normalizedNumber;
/** The photo for the contact, if available. */
public long photoId;
diff --git a/src/com/android/dialer/calllog/MissedCallNotifier.java b/src/com/android/dialer/calllog/MissedCallNotifier.java
index 8811baff8..a9dfd442f 100644
--- a/src/com/android/dialer/calllog/MissedCallNotifier.java
+++ b/src/com/android/dialer/calllog/MissedCallNotifier.java
@@ -26,6 +26,7 @@ import android.provider.CallLog.Calls;
import android.text.TextUtils;
import android.util.Log;
+import com.android.contacts.common.ContactsUtils;
import com.android.contacts.common.util.PhoneNumberHelper;
import com.android.dialer.calllog.CallLogNotificationsHelper.NewCall;
import com.android.dialer.DialtactsActivity;
@@ -97,14 +98,18 @@ public class MissedCallNotifier {
// 1 missed call: <caller name || handle>
// More than 1 missed call: <number of calls> + "missed calls"
if (count == 1) {
- titleResId = R.string.notification_missedCallTitle;
-
//TODO: look up caller ID that is not in contacts.
- expandedText = CallLogNotificationsHelper.getInstance(mContext)
- .getName(useCallLog ? newestCall.number : number,
+ ContactInfo contactInfo = CallLogNotificationsHelper.getInstance(mContext)
+ .getContactInfo(useCallLog ? newestCall.number : number,
useCallLog ? newestCall.numberPresentation
: Calls.PRESENTATION_ALLOWED,
useCallLog ? newestCall.countryIso : null);
+
+ titleResId = contactInfo.userType == ContactsUtils.USER_TYPE_WORK
+ ? R.string.notification_missedWorkCallTitle
+ : R.string.notification_missedCallTitle;
+
+ expandedText = contactInfo.name;
} else {
titleResId = R.string.notification_missedCallsTitle;
expandedText =