Merge "Covnert @AutoValue PhotoInfo into a proto."
diff --git a/java/com/android/dialer/calllog/ui/NewCallLogViewHolder.java b/java/com/android/dialer/calllog/ui/NewCallLogViewHolder.java
index cf01608..4c2d124 100644
--- a/java/com/android/dialer/calllog/ui/NewCallLogViewHolder.java
+++ b/java/com/android/dialer/calllog/ui/NewCallLogViewHolder.java
@@ -22,6 +22,7 @@
 import android.provider.CallLog.Calls;
 import android.support.annotation.DrawableRes;
 import android.support.v7.widget.RecyclerView;
+import android.text.TextUtils;
 import android.view.View;
 import android.widget.ImageView;
 import android.widget.QuickContactBadge;
@@ -35,6 +36,7 @@
 import com.android.dialer.compat.AppCompatConstants;
 import com.android.dialer.compat.telephony.TelephonyManagerCompat;
 import com.android.dialer.glidephotomanager.GlidePhotoManager;
+import com.android.dialer.glidephotomanager.PhotoInfo;
 import com.android.dialer.oem.MotorolaUtils;
 import com.android.dialer.time.Clock;
 import com.google.common.util.concurrent.FutureCallback;
@@ -150,11 +152,13 @@
   }
 
   private void setPhoto(CoalescedRow row) {
-    glidePhotoManager.loadQuickContactBadge(
-        quickContactBadge,
-        NumberAttributesConverter.toPhotoInfoBuilder(row.numberAttributes())
-            .setFormattedNumber(row.formattedNumber())
-            .build());
+    PhotoInfo.Builder photoInfoBuilder =
+        NumberAttributesConverter.toPhotoInfoBuilder(row.numberAttributes());
+    if (!TextUtils.isEmpty(row.formattedNumber())) {
+      photoInfoBuilder.setFormattedNumber(row.formattedNumber());
+    }
+
+    glidePhotoManager.loadQuickContactBadge(quickContactBadge, photoInfoBuilder.build());
   }
 
   private void setFeatureIcons(CoalescedRow row) {
diff --git a/java/com/android/dialer/calllog/ui/menu/PrimaryAction.java b/java/com/android/dialer/calllog/ui/menu/PrimaryAction.java
index de4a70c..aec4dc6 100644
--- a/java/com/android/dialer/calllog/ui/menu/PrimaryAction.java
+++ b/java/com/android/dialer/calllog/ui/menu/PrimaryAction.java
@@ -18,10 +18,12 @@
 
 import android.content.Context;
 import android.provider.CallLog.Calls;
+import android.text.TextUtils;
 import com.android.dialer.calllog.model.CoalescedRow;
 import com.android.dialer.calllogutils.CallLogEntryText;
 import com.android.dialer.calllogutils.CallLogIntents;
 import com.android.dialer.calllogutils.NumberAttributesConverter;
+import com.android.dialer.glidephotomanager.PhotoInfo;
 import com.android.dialer.historyitemactions.HistoryItemPrimaryActionInfo;
 
 /** Configures the primary action row (top row) for the bottom sheet. */
@@ -29,13 +31,17 @@
 
   static HistoryItemPrimaryActionInfo fromRow(Context context, CoalescedRow row) {
     CharSequence primaryText = CallLogEntryText.buildPrimaryText(context, row);
+
+    PhotoInfo.Builder photoInfoBuilder =
+        NumberAttributesConverter.toPhotoInfoBuilder(row.numberAttributes())
+            .setIsVideo((row.features() & Calls.FEATURES_VIDEO) == Calls.FEATURES_VIDEO);
+    if (!TextUtils.isEmpty(row.formattedNumber())) {
+      photoInfoBuilder.setFormattedNumber(row.formattedNumber());
+    }
+
     return HistoryItemPrimaryActionInfo.builder()
         .setNumber(row.number())
-        .setPhotoInfo(
-            NumberAttributesConverter.toPhotoInfoBuilder(row.numberAttributes())
-                .setFormattedNumber(row.formattedNumber())
-                .setIsVideo((row.features() & Calls.FEATURES_VIDEO) == Calls.FEATURES_VIDEO)
-                .build())
+        .setPhotoInfo(photoInfoBuilder.build())
         .setPrimaryText(primaryText)
         .setSecondaryText(CallLogEntryText.buildSecondaryTextForBottomSheet(context, row))
         .setIntent(CallLogIntents.getCallBackIntent(context, row))
diff --git a/java/com/android/dialer/calllogutils/NumberAttributesConverter.java b/java/com/android/dialer/calllogutils/NumberAttributesConverter.java
index a9376bb..df6b680 100644
--- a/java/com/android/dialer/calllogutils/NumberAttributesConverter.java
+++ b/java/com/android/dialer/calllogutils/NumberAttributesConverter.java
@@ -27,7 +27,7 @@
 
   /** Converts {@link NumberAttributes} to {@link PhotoInfo.Builder} */
   public static PhotoInfo.Builder toPhotoInfoBuilder(NumberAttributes numberAttributes) {
-    return PhotoInfo.builder()
+    return PhotoInfo.newBuilder()
         .setName(numberAttributes.getName())
         .setPhotoUri(numberAttributes.getPhotoUri())
         .setPhotoId(numberAttributes.getPhotoId())
diff --git a/java/com/android/dialer/glidephotomanager/PhotoInfo.java b/java/com/android/dialer/glidephotomanager/PhotoInfo.java
deleted file mode 100644
index 016221f..0000000
--- a/java/com/android/dialer/glidephotomanager/PhotoInfo.java
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * Copyright (C) 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.dialer.glidephotomanager;
-
-import android.support.annotation.Nullable;
-import com.google.auto.value.AutoValue;
-
-/** The number information used to create the photo.. */
-@AutoValue
-public abstract class PhotoInfo {
-
-  /** The display name of the number */
-  @Nullable
-  public abstract String name();
-
-  /** The number displayed to the user. */
-  @Nullable
-  public abstract String formattedNumber();
-
-  /** The URI to the photo */
-  @Nullable
-  public abstract String photoUri();
-
-  /** Value of {@link android.provider.ContactsContract.CommonDataKinds.Photo#_ID} */
-  public abstract long photoId();
-
-  /** The contacts provider lookup URI for the contact associated with the number */
-  @Nullable
-  public abstract String lookupUri();
-
-  /** Should a business icon be displayed */
-  public abstract boolean isBusiness();
-
-  /** Should a voicemail icon be displayed */
-  public abstract boolean isVoicemail();
-
-  /** Should a blocked icon be displayed */
-  public abstract boolean isBlocked();
-
-  /** Should a spam icon be displayed */
-  public abstract boolean isSpam();
-
-  /**
-   * Should the photo be badged as video call.
-   *
-   * <p>Defaults to false.
-   */
-  public abstract boolean isVideo();
-
-  /** Builder for {@link PhotoInfo} */
-  @AutoValue.Builder
-  public abstract static class Builder {
-
-    public abstract Builder setName(@Nullable String name);
-
-    public abstract Builder setFormattedNumber(@Nullable String formattedNumber);
-
-    public abstract Builder setPhotoUri(@Nullable String uri);
-
-    public abstract Builder setPhotoId(long id);
-
-    public abstract Builder setLookupUri(@Nullable String uri);
-
-    public abstract Builder setIsBusiness(boolean isBusiness);
-
-    public abstract Builder setIsVoicemail(boolean isVoicemail);
-
-    public abstract Builder setIsBlocked(boolean isBlocked);
-
-    public abstract Builder setIsSpam(boolean isSpam);
-
-    public abstract Builder setIsVideo(boolean isVideo);
-
-    public abstract PhotoInfo build();
-  }
-
-  public static PhotoInfo.Builder builder() {
-    return new AutoValue_PhotoInfo.Builder()
-        .setPhotoId(0)
-        .setIsBusiness(false)
-        .setIsVoicemail(false)
-        .setIsBlocked(false)
-        .setIsSpam(false)
-        .setIsVideo(false);
-  }
-}
diff --git a/java/com/android/dialer/glidephotomanager/impl/GlidePhotoManagerImpl.java b/java/com/android/dialer/glidephotomanager/impl/GlidePhotoManagerImpl.java
index e14e604..45af4e3 100644
--- a/java/com/android/dialer/glidephotomanager/impl/GlidePhotoManagerImpl.java
+++ b/java/com/android/dialer/glidephotomanager/impl/GlidePhotoManagerImpl.java
@@ -49,7 +49,7 @@
   @Override
   public void loadQuickContactBadge(QuickContactBadge badge, PhotoInfo photoInfo) {
     Assert.isMainThread();
-    badge.assignContactUri(parseUri(photoInfo.lookupUri()));
+    badge.assignContactUri(parseUri(photoInfo.getLookupUri()));
     badge.setOverlay(null);
     GlideRequest<Drawable> request = buildRequest(GlideApp.with(badge), photoInfo);
     request.into(badge);
@@ -62,20 +62,20 @@
     GlideRequest<Drawable> request;
     boolean circleCrop = true; // Photos are cropped to a circle by default.
 
-    if (photoInfo.isBlocked()) {
+    if (photoInfo.getIsBlocked()) {
       // Whether the number is blocked takes precedence over the spam status.
       request = requestManager.load(R.drawable.ic_block_grey_48dp);
 
-    } else if (photoInfo.isSpam()) {
+    } else if (photoInfo.getIsSpam()) {
       request = requestManager.load(R.drawable.quantum_ic_report_vd_red_24);
       circleCrop = false; // The spam icon is an octagon so we don't crop it.
 
-    } else if (!TextUtils.isEmpty(photoInfo.photoUri())) {
-      request = requestManager.load(parseUri(photoInfo.photoUri()));
+    } else if (!TextUtils.isEmpty(photoInfo.getPhotoUri())) {
+      request = requestManager.load(parseUri(photoInfo.getPhotoUri()));
 
-    } else if (photoInfo.photoId() != 0) {
+    } else if (photoInfo.getPhotoId() != 0) {
       request =
-          requestManager.load(ContentUris.withAppendedId(Data.CONTENT_URI, photoInfo.photoId()));
+          requestManager.load(ContentUris.withAppendedId(Data.CONTENT_URI, photoInfo.getPhotoId()));
 
     } else {
       // load null to indicate fallback should be used.
@@ -102,23 +102,25 @@
     LetterTileDrawable letterTileDrawable = new LetterTileDrawable(appContext.getResources());
     String displayName;
     String identifier;
-    if (TextUtils.isEmpty(photoInfo.lookupUri())) {
+    if (TextUtils.isEmpty(photoInfo.getLookupUri())) {
       // Use generic avatar instead of letter for non-contacts.
       displayName = null;
       identifier =
-          TextUtils.isEmpty(photoInfo.name()) ? photoInfo.formattedNumber() : photoInfo.name();
+          TextUtils.isEmpty(photoInfo.getName())
+              ? photoInfo.getFormattedNumber()
+              : photoInfo.getName();
     } else {
-      displayName = photoInfo.name();
-      identifier = photoInfo.lookupUri();
+      displayName = photoInfo.getName();
+      identifier = photoInfo.getLookupUri();
     }
     letterTileDrawable.setCanonicalDialerLetterTileDetails(
         displayName,
         identifier,
         LetterTileDrawable.SHAPE_CIRCLE,
         LetterTileDrawable.getContactTypeFromPrimitives(
-            photoInfo.isVoicemail(),
-            photoInfo.isSpam(),
-            photoInfo.isBusiness(),
+            photoInfo.getIsVoicemail(),
+            photoInfo.getIsSpam(),
+            photoInfo.getIsBusiness(),
             TelecomManager.PRESENTATION_ALLOWED, // TODO(twyen):implement
             false)); // TODO(twyen):implement
     return letterTileDrawable;
diff --git a/java/com/android/dialer/glidephotomanager/photo_info.proto b/java/com/android/dialer/glidephotomanager/photo_info.proto
new file mode 100644
index 0000000..447cfe8
--- /dev/null
+++ b/java/com/android/dialer/glidephotomanager/photo_info.proto
@@ -0,0 +1,44 @@
+syntax = "proto2";
+
+option java_package = "com.android.dialer.glidephotomanager";
+option java_multiple_files = true;
+option optimize_for = LITE_RUNTIME;
+
+
+package com.android.dialer.glidephotomanager;
+
+// Contains information associated with a number, which is used to create the
+// photo.
+// Next ID: 11
+message PhotoInfo {
+  // The display name of the number.
+  optional string name = 1;
+
+  // The number presented to the user.
+  optional string formatted_number = 2;
+
+  // The URI of the photo.
+  optional string photo_uri = 3;
+
+  // Value of android.provider.ContactsContract.CommonDataKinds.Photo#_ID
+  optional int64 photo_id = 4;
+
+  // The Contacts Provider lookup URI for the contact associated with the
+  // number.
+  optional string lookup_uri = 5;
+
+  // Whether a business icon should be displayed.
+  optional bool is_business = 6;
+
+  // Whether a voicemail icon should be displayed.
+  optional bool is_voicemail = 7;
+
+  // Whether a "blocked" icon should be displayed.
+  optional bool is_blocked = 8;
+
+  // Whether a "spam" icon should be displayed.
+  optional bool is_spam = 9;
+
+  // Whether the photo should be badged as video call.
+  optional bool is_video = 10;
+}
diff --git a/java/com/android/dialer/voicemail/listui/NewVoicemailViewHolder.java b/java/com/android/dialer/voicemail/listui/NewVoicemailViewHolder.java
index 5328dd3..1d42e64 100644
--- a/java/com/android/dialer/voicemail/listui/NewVoicemailViewHolder.java
+++ b/java/com/android/dialer/voicemail/listui/NewVoicemailViewHolder.java
@@ -45,6 +45,7 @@
 import com.android.dialer.common.concurrent.DialerExecutorComponent;
 import com.android.dialer.compat.android.provider.VoicemailCompat;
 import com.android.dialer.glidephotomanager.GlidePhotoManager;
+import com.android.dialer.glidephotomanager.PhotoInfo;
 import com.android.dialer.time.Clock;
 import com.android.dialer.voicemail.listui.menu.NewVoicemailMenu;
 import com.android.dialer.voicemail.model.VoicemailEntry;
@@ -210,11 +211,13 @@
   }
 
   private void setPhoto(VoicemailEntry voicemailEntry) {
-    glidePhotoManager.loadQuickContactBadge(
-        quickContactBadge,
-        NumberAttributesConverter.toPhotoInfoBuilder(voicemailEntry.numberAttributes())
-            .setFormattedNumber(voicemailEntry.formattedNumber())
-            .build());
+    PhotoInfo.Builder photoInfoBuilder =
+        NumberAttributesConverter.toPhotoInfoBuilder(voicemailEntry.numberAttributes());
+    if (!TextUtils.isEmpty(voicemailEntry.formattedNumber())) {
+      photoInfoBuilder.setFormattedNumber(voicemailEntry.formattedNumber());
+    }
+
+    glidePhotoManager.loadQuickContactBadge(quickContactBadge, photoInfoBuilder.build());
   }
 
   void collapseViewHolder() {
diff --git a/java/com/android/dialer/voicemail/listui/menu/PrimaryAction.java b/java/com/android/dialer/voicemail/listui/menu/PrimaryAction.java
index 9a5aa18..dbc417c 100644
--- a/java/com/android/dialer/voicemail/listui/menu/PrimaryAction.java
+++ b/java/com/android/dialer/voicemail/listui/menu/PrimaryAction.java
@@ -19,6 +19,7 @@
 import android.content.Context;
 import android.text.TextUtils;
 import com.android.dialer.calllogutils.NumberAttributesConverter;
+import com.android.dialer.glidephotomanager.PhotoInfo;
 import com.android.dialer.historyitemactions.HistoryItemPrimaryActionInfo;
 import com.android.dialer.voicemail.model.VoicemailEntry;
 
@@ -33,12 +34,15 @@
   // setSecondaryText - check in with UX
   static HistoryItemPrimaryActionInfo fromVoicemailEntry(
       Context context, VoicemailEntry voicemailEntry) {
+    PhotoInfo.Builder photoInfoBuilder =
+        NumberAttributesConverter.toPhotoInfoBuilder(voicemailEntry.numberAttributes());
+    if (!TextUtils.isEmpty(voicemailEntry.formattedNumber())) {
+      photoInfoBuilder.setFormattedNumber(voicemailEntry.formattedNumber());
+    }
+
     return HistoryItemPrimaryActionInfo.builder()
         .setNumber(voicemailEntry.number())
-        .setPhotoInfo(
-            NumberAttributesConverter.toPhotoInfoBuilder(voicemailEntry.numberAttributes())
-                .setFormattedNumber(voicemailEntry.formattedNumber())
-                .build())
+        .setPhotoInfo(photoInfoBuilder.build())
         .setPrimaryText(buildPrimaryVoicemailText(context, voicemailEntry))
         .setSecondaryText(buildSecondaryVoicemailText(voicemailEntry))
         .build();