Merge "Improve fields displayed for reverse phone lookup" into klp-dev
diff --git a/InCallUI/src/com/android/incallui/CallCardPresenter.java b/InCallUI/src/com/android/incallui/CallCardPresenter.java
index d2295d3..ee58706 100644
--- a/InCallUI/src/com/android/incallui/CallCardPresenter.java
+++ b/InCallUI/src/com/android/incallui/CallCardPresenter.java
@@ -21,6 +21,7 @@
 import android.content.pm.PackageManager;
 import android.graphics.drawable.Drawable;
 import android.graphics.Bitmap;
+import android.provider.ContactsContract.CommonDataKinds.Phone;
 import android.telephony.PhoneNumberUtils;
 import android.text.TextUtils;
 import android.text.format.DateUtils;
@@ -252,7 +253,8 @@
                     if (entry.label == null) {
                         // Name not found.  Try lookup.
                         Log.d(TAG, "Contact lookup. Contact provider miss. Searching people api.");
-                        lookupPhoneNumber(identification.getNumber());
+                        lookupPhoneNumber(identification.getNumber(),
+                                isPrimary, isConference);
                     } else {
                         Log.d(TAG, "Contact lookup. Found in contact provider: " + entry);
                         updateContactEntry(entry, isPrimary, isConference);
@@ -379,25 +381,35 @@
         }
     }
 
-    public void lookupPhoneNumber(String phoneNumber) {
+    public void lookupPhoneNumber(final String phoneNumber,
+            final boolean isPrimary, final boolean isConference) {
         if (mPhoneNumberService != null) {
             mPhoneNumberService.getPhoneNumberInfo(phoneNumber,
                     new PhoneNumberService.NumberLookupListener() {
                         @Override
                         public void onPhoneNumberInfoComplete(
                                 final PhoneNumberService.PhoneNumberInfo info) {
-                            if (info == null) {
+                            if (info == null || getUi() == null) {
                                 return;
                             }
-                            // TODO(klp): Ui is sometimes null due to something being shutdown.
-                            if (getUi() != null) {
-                                if (info.getDisplayName() != null) {
-                                    getUi().setPrimaryName(info.getDisplayName(), false);
-                                }
+                            ContactCacheEntry entry = new ContactCacheEntry();
+                            entry.name = info.getDisplayName();
+                            entry.number = info.getNumber();
+                            final int type = info.getPhoneType();
+                            final String label = info.getPhoneLabel();
+                            if (type == Phone.TYPE_CUSTOM) {
+                                entry.label = label;
+                            } else {
+                                final CharSequence typeStr = Phone.getTypeLabel(
+                                        mContext.getResources(), type, label);
+                                entry.label = typeStr == null ? null :
+                                    typeStr.toString();
+                            }
 
-                                if (info.getImageUrl() != null) {
-                                    fetchImage(info.getImageUrl());
-                                }
+                            updateContactEntry(entry, isPrimary, isConference);
+
+                            if (info.getImageUrl() != null) {
+                                fetchImage(info.getImageUrl());
                             }
                         }
                     });
diff --git a/InCallUI/src/com/android/incallui/service/PhoneNumberService.java b/InCallUI/src/com/android/incallui/service/PhoneNumberService.java
index 1fc2858..279593d 100644
--- a/InCallUI/src/com/android/incallui/service/PhoneNumberService.java
+++ b/InCallUI/src/com/android/incallui/service/PhoneNumberService.java
@@ -61,7 +61,10 @@
 
     public interface PhoneNumberInfo {
         public String getDisplayName();
-        public String getPhoneNumber();
+        public String getNumber();
+        public int getPhoneType();
+        public String getPhoneLabel();
+        public String getNormalizedNumber();
         public String getImageUrl();
     }
 }