Fixed labels for speed dial UI.

Bug: 78922118
Test: tap + manual
PiperOrigin-RevId: 194971448
Change-Id: I906250cb83c17198fac87f5ad6d3014cc8a34db2
diff --git a/java/com/android/dialer/speeddial/FavoritesViewHolder.java b/java/com/android/dialer/speeddial/FavoritesViewHolder.java
index 474516e..f06672d 100644
--- a/java/com/android/dialer/speeddial/FavoritesViewHolder.java
+++ b/java/com/android/dialer/speeddial/FavoritesViewHolder.java
@@ -68,10 +68,15 @@
     Assert.checkArgument(speedDialUiItem.isStarred());
 
     nameView.setText(speedDialUiItem.name());
-    if (speedDialUiItem.defaultChannel() != null) {
-      phoneType.setText(speedDialUiItem.defaultChannel().label());
-      videoCallIcon.setVisibility(
-          speedDialUiItem.defaultChannel().isVideoTechnology() ? View.VISIBLE : View.GONE);
+
+    Channel channel = speedDialUiItem.defaultChannel();
+    if (channel == null) {
+      channel = speedDialUiItem.getDefaultVoiceChannel();
+    }
+
+    if (channel != null) {
+      phoneType.setText(channel.label());
+      videoCallIcon.setVisibility(channel.isVideoTechnology() ? View.VISIBLE : View.GONE);
     } else {
       phoneType.setText("");
       videoCallIcon.setVisibility(View.GONE);
diff --git a/java/com/android/dialer/speeddial/loader/SpeedDialUiItem.java b/java/com/android/dialer/speeddial/loader/SpeedDialUiItem.java
index 325af23..731c8c6 100644
--- a/java/com/android/dialer/speeddial/loader/SpeedDialUiItem.java
+++ b/java/com/android/dialer/speeddial/loader/SpeedDialUiItem.java
@@ -16,6 +16,7 @@
 
 package com.android.dialer.speeddial.loader;
 
+import android.content.res.Resources;
 import android.database.Cursor;
 import android.provider.ContactsContract.CommonDataKinds.Phone;
 import android.provider.ContactsContract.Contacts;
@@ -102,7 +103,7 @@
    * <p>If the cursor started at row X, this method will advance to row Y s.t. rows X, X + 1, ... Y
    * - 1 all belong to the same contact (that is, share the same contact id and lookup key).
    */
-  public static SpeedDialUiItem fromCursor(Cursor cursor) {
+  public static SpeedDialUiItem fromCursor(Resources resources, Cursor cursor) {
     Assert.checkArgument(cursor != null);
     Assert.checkArgument(cursor.getCount() != 0);
     String lookupKey = cursor.getString(LOOKUP_KEY);
@@ -125,7 +126,7 @@
           Channel.builder()
               .setNumber(cursor.getString(NUMBER))
               .setPhoneType(cursor.getInt(TYPE))
-              .setLabel(TextUtils.isEmpty(cursor.getString(LABEL)) ? "" : cursor.getString(LABEL))
+              .setLabel(getLabel(resources, cursor))
               .setTechnology(Channel.VOICE)
               .build();
       channels.add(channel);
@@ -141,6 +142,17 @@
     return builder.build();
   }
 
+  private static String getLabel(Resources resources, Cursor cursor) {
+    int numberType = cursor.getInt(TYPE);
+    String numberLabel = cursor.getString(LABEL);
+
+    // Returns empty label instead of "custom" if the custom label is empty.
+    if (numberType == Phone.TYPE_CUSTOM && TextUtils.isEmpty(numberLabel)) {
+      return "";
+    }
+    return (String) Phone.getTypeLabel(resources, numberType, numberLabel);
+  }
+
   public PhotoInfo getPhotoInfo() {
     return PhotoInfo.newBuilder()
         .setPhotoId(photoId())
diff --git a/java/com/android/dialer/speeddial/loader/SpeedDialUiItemMutator.java b/java/com/android/dialer/speeddial/loader/SpeedDialUiItemMutator.java
index 0a2a241..1ad37dc 100644
--- a/java/com/android/dialer/speeddial/loader/SpeedDialUiItemMutator.java
+++ b/java/com/android/dialer/speeddial/loader/SpeedDialUiItemMutator.java
@@ -205,7 +205,7 @@
         return loadSpeedDialUiItemsInternal();
       }
       Assert.checkArgument(cursor.moveToFirst(), "Cursor should never be empty");
-      SpeedDialUiItem item = SpeedDialUiItem.fromCursor(cursor);
+      SpeedDialUiItem item = SpeedDialUiItem.fromCursor(appContext.getResources(), cursor);
 
       // Star the contact if it isn't starred already, then return.
       if (!item.isStarred()) {
@@ -410,7 +410,7 @@
                 null)) {
       Map<SpeedDialEntry, SpeedDialUiItem> map = new ArrayMap<>();
       for (cursor.moveToFirst(); !cursor.isAfterLast(); /* Iterate in the loop */ ) {
-        SpeedDialUiItem item = SpeedDialUiItem.fromCursor(cursor);
+        SpeedDialUiItem item = SpeedDialUiItem.fromCursor(appContext.getResources(), cursor);
         for (SpeedDialEntry entry : entries) {
           if (entry.contactId() == item.contactId()) {
             // Update the id and pinned position to match it's corresponding SpeedDialEntry.
@@ -513,7 +513,7 @@
         return contacts;
       }
       for (cursor.moveToFirst(); !cursor.isAfterLast(); /* Iterate in the loop */ ) {
-        contacts.add(SpeedDialUiItem.fromCursor(cursor));
+        contacts.add(SpeedDialUiItem.fromCursor(appContext.getResources(), cursor));
       }
       return contacts;
     }