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
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 7e87b2f..ed88b96 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 64ccd5f..6abf241 100644
--- a/src/com/android/dialer/calllog/CallLogNotificationsHelper.java
+++ b/src/com/android/dialer/calllog/CallLogNotificationsHelper.java
@@ -26,6 +26,7 @@
 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 String getName(@Nullable String number, int numberPresentation,
                           @Nullable String countryIso) {
-        String name = PhoneNumberDisplayUtil.getDisplayName(
-                mContext,
-                number,
-                numberPresentation,
-                false).toString();
-        if (!TextUtils.isEmpty(name)) {
-            return name;
-        }
+        return getContactInfo(number, numberPresentation, countryIso).name;
+    }
 
-        // Look it up in the database.
-        name = mNameLookupQuery.query(number);
-        if (!TextUtils.isEmpty(name)) {
-            return 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;
         }
 
-        // Look it up in the cache
-        ContactInfo contactInfo = mContactInfoHelper.lookupNumber(number, countryIso);
+        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);
 
-        if (contactInfo != null && !TextUtils.isEmpty(contactInfo.name)) {
-            return contactInfo.name;
+        // 1. Special number representation.
+        contactInfo.name = PhoneNumberDisplayUtil.getDisplayName(
+                mContext,
+                number,
+                numberPresentation,
+                false).toString();
+        if (!TextUtils.isEmpty(contactInfo.name)) {
+            return contactInfo;
         }
 
-        if (!TextUtils.isEmpty(number)) {
-            // If we cannot lookup the contact, use the number instead.
-            return PhoneNumberUtils.formatNumber(number, countryIso);
+        // 2. Personal ContactsProvider phonelookup query.
+        contactInfo.name = mNameLookupQuery.query(number);
+        if (!TextUtils.isEmpty(contactInfo.name)) {
+            return contactInfo;
         }
-        return mContext.getResources().getString(R.string.unknown);
+
+        // 3. Look it up in the cache.
+        ContactInfo cachedContactInfo = mContactInfoHelper.lookupNumber(number, countryIso);
+
+        if (cachedContactInfo != null && !TextUtils.isEmpty(cachedContactInfo.name)) {
+            return cachedContactInfo;
+        }
+
+        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 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 40d963e..8fe4964 100644
--- a/src/com/android/dialer/calllog/ContactInfo.java
+++ b/src/com/android/dialer/calllog/ContactInfo.java
@@ -40,6 +40,15 @@
     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 8811baf..a9dfd44 100644
--- a/src/com/android/dialer/calllog/MissedCallNotifier.java
+++ b/src/com/android/dialer/calllog/MissedCallNotifier.java
@@ -26,6 +26,7 @@
 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 @@
         // 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 =