Updating SecondaryInfo value class to use AutoValue with builder pattern.

Test: CallCardPresenterTest,SecondaryInfoTest
PiperOrigin-RevId: 187481728
Change-Id: I3d2b23b5d51ea1e5ff30b8f6b6570d76c006fe86
diff --git a/java/com/android/incallui/CallCardPresenter.java b/java/com/android/incallui/CallCardPresenter.java
index ad92f57..c60da63 100644
--- a/java/com/android/incallui/CallCardPresenter.java
+++ b/java/com/android/incallui/CallCardPresenter.java
@@ -907,7 +907,7 @@
 
     if (secondary == null) {
       // Clear the secondary display info.
-      inCallScreen.setSecondary(SecondaryInfo.createEmptySecondaryInfo(isFullscreen));
+      inCallScreen.setSecondary(SecondaryInfo.builder().setIsFullscreen(isFullscreen).build());
       return;
     }
 
@@ -915,39 +915,39 @@
       LogUtil.i(
           "CallCardPresenter.updateSecondaryDisplayInfo",
           "secondary call is merge in process, clearing info");
-      inCallScreen.setSecondary(SecondaryInfo.createEmptySecondaryInfo(isFullscreen));
+      inCallScreen.setSecondary(SecondaryInfo.builder().setIsFullscreen(isFullscreen).build());
       return;
     }
 
     if (secondary.isConferenceCall()) {
       inCallScreen.setSecondary(
-          new SecondaryInfo(
-              true /* show */,
-              CallerInfoUtils.getConferenceString(
-                  context, secondary.hasProperty(Details.PROPERTY_GENERIC_CONFERENCE)),
-              false /* nameIsNumber */,
-              null /* label */,
-              secondary.getCallProviderLabel(),
-              true /* isConference */,
-              secondary.isVideoCall(),
-              isFullscreen));
+          SecondaryInfo.builder()
+              .setShouldShow(true)
+              .setName(
+                  CallerInfoUtils.getConferenceString(
+                      context, secondary.hasProperty(Details.PROPERTY_GENERIC_CONFERENCE)))
+              .setProviderLabel(secondary.getCallProviderLabel())
+              .setIsConference(true)
+              .setIsVideoCall(secondary.isVideoCall())
+              .setIsFullscreen(isFullscreen)
+              .build());
     } else if (secondaryContactInfo != null) {
       LogUtil.v("CallCardPresenter.updateSecondaryDisplayInfo", "" + secondaryContactInfo);
       String name = getNameForCall(secondaryContactInfo);
       boolean nameIsNumber = name != null && name.equals(secondaryContactInfo.number);
       inCallScreen.setSecondary(
-          new SecondaryInfo(
-              true /* show */,
-              secondary.updateNameIfRestricted(name),
-              nameIsNumber,
-              secondaryContactInfo.label,
-              secondary.getCallProviderLabel(),
-              false /* isConference */,
-              secondary.isVideoCall(),
-              isFullscreen));
+          SecondaryInfo.builder()
+              .setShouldShow(true)
+              .setName(secondary.updateNameIfRestricted(name))
+              .setNameIsNumber(nameIsNumber)
+              .setLabel(secondaryContactInfo.label)
+              .setProviderLabel(secondary.getCallProviderLabel())
+              .setIsVideoCall(secondary.isVideoCall())
+              .setIsFullscreen(isFullscreen)
+              .build());
     } else {
       // Clear the secondary display info.
-      inCallScreen.setSecondary(SecondaryInfo.createEmptySecondaryInfo(isFullscreen));
+      inCallScreen.setSecondary(SecondaryInfo.builder().setIsFullscreen(isFullscreen).build());
     }
   }
 
diff --git a/java/com/android/incallui/hold/OnHoldFragment.java b/java/com/android/incallui/hold/OnHoldFragment.java
index 33ca158..bddb9ba 100644
--- a/java/com/android/incallui/hold/OnHoldFragment.java
+++ b/java/com/android/incallui/hold/OnHoldFragment.java
@@ -59,14 +59,14 @@
 
     ((TextView) view.findViewById(R.id.hold_contact_name))
         .setText(
-            secondaryInfo.nameIsNumber
+            secondaryInfo.nameIsNumber()
                 ? PhoneNumberUtils.createTtsSpannable(
                     BidiFormatter.getInstance()
-                        .unicodeWrap(secondaryInfo.name, TextDirectionHeuristics.LTR))
-                : secondaryInfo.name);
+                        .unicodeWrap(secondaryInfo.name(), TextDirectionHeuristics.LTR))
+                : secondaryInfo.name());
     ((ImageView) view.findViewById(R.id.hold_phone_icon))
         .setImageResource(
-            secondaryInfo.isVideoCall
+            secondaryInfo.isVideoCall()
                 ? R.drawable.quantum_ic_videocam_white_18
                 : R.drawable.quantum_ic_phone_paused_vd_theme_24);
     view.addOnAttachStateChangeListener(
diff --git a/java/com/android/incallui/incall/impl/InCallFragment.java b/java/com/android/incallui/incall/impl/InCallFragment.java
index 29160ab..5f558a4 100644
--- a/java/com/android/incallui/incall/impl/InCallFragment.java
+++ b/java/com/android/incallui/incall/impl/InCallFragment.java
@@ -305,7 +305,7 @@
     savedSecondaryInfo = null;
     FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
     Fragment oldBanner = getChildFragmentManager().findFragmentById(R.id.incall_on_hold_banner);
-    if (secondaryInfo.shouldShow) {
+    if (secondaryInfo.shouldShow()) {
       transaction.replace(R.id.incall_on_hold_banner, OnHoldFragment.newInstance(secondaryInfo));
     } else {
       if (oldBanner != null) {
diff --git a/java/com/android/incallui/incall/protocol/SecondaryInfo.java b/java/com/android/incallui/incall/protocol/SecondaryInfo.java
index cadfca6..2dfd220 100644
--- a/java/com/android/incallui/incall/protocol/SecondaryInfo.java
+++ b/java/com/android/incallui/incall/protocol/SecondaryInfo.java
@@ -18,41 +18,62 @@
 
 import android.os.Parcel;
 import android.os.Parcelable;
+import android.support.annotation.Nullable;
 import com.android.dialer.common.LogUtil;
+import com.google.auto.value.AutoValue;
 import java.util.Locale;
 
 /** Information about the secondary call. */
-public class SecondaryInfo implements Parcelable {
-  public final boolean shouldShow;
-  public final String name;
-  public final boolean nameIsNumber;
-  public final String label;
-  public final String providerLabel;
-  public final boolean isConference;
-  public final boolean isVideoCall;
-  public final boolean isFullscreen;
+@AutoValue
+public abstract class SecondaryInfo implements Parcelable {
+  public abstract boolean shouldShow();
 
-  public static SecondaryInfo createEmptySecondaryInfo(boolean isFullScreen) {
-    return new SecondaryInfo(false, null, false, null, null, false, false, isFullScreen);
+  @Nullable
+  public abstract String name();
+
+  public abstract boolean nameIsNumber();
+
+  @Nullable
+  public abstract String label();
+
+  @Nullable
+  public abstract String providerLabel();
+
+  public abstract boolean isConference();
+
+  public abstract boolean isVideoCall();
+
+  public abstract boolean isFullscreen();
+
+  public static Builder builder() {
+    return new AutoValue_SecondaryInfo.Builder()
+        .setShouldShow(false)
+        .setNameIsNumber(false)
+        .setIsConference(false)
+        .setIsVideoCall(false)
+        .setIsFullscreen(false);
   }
 
-  public SecondaryInfo(
-      boolean shouldShow,
-      String name,
-      boolean nameIsNumber,
-      String label,
-      String providerLabel,
-      boolean isConference,
-      boolean isVideoCall,
-      boolean isFullscreen) {
-    this.shouldShow = shouldShow;
-    this.name = name;
-    this.nameIsNumber = nameIsNumber;
-    this.label = label;
-    this.providerLabel = providerLabel;
-    this.isConference = isConference;
-    this.isVideoCall = isVideoCall;
-    this.isFullscreen = isFullscreen;
+  /** Builder class for secondary info. */
+  @AutoValue.Builder
+  public abstract static class Builder {
+    public abstract Builder setShouldShow(boolean shouldShow);
+
+    public abstract Builder setName(String name);
+
+    public abstract Builder setNameIsNumber(boolean nameIsNumber);
+
+    public abstract Builder setLabel(String label);
+
+    public abstract Builder setProviderLabel(String providerLabel);
+
+    public abstract Builder setIsConference(boolean isConference);
+
+    public abstract Builder setIsVideoCall(boolean isVideoCall);
+
+    public abstract Builder setIsFullscreen(boolean isFullscreen);
+
+    public abstract SecondaryInfo build();
   }
 
   @Override
@@ -60,28 +81,26 @@
     return String.format(
         Locale.US,
         "SecondaryInfo, show: %b, name: %s, label: %s, " + "providerLabel: %s",
-        shouldShow,
-        LogUtil.sanitizePii(name),
-        label,
-        providerLabel);
-  }
-
-  protected SecondaryInfo(Parcel in) {
-    shouldShow = in.readByte() != 0;
-    name = in.readString();
-    nameIsNumber = in.readByte() != 0;
-    label = in.readString();
-    providerLabel = in.readString();
-    isConference = in.readByte() != 0;
-    isVideoCall = in.readByte() != 0;
-    isFullscreen = in.readByte() != 0;
+        shouldShow(),
+        LogUtil.sanitizePii(name()),
+        label(),
+        providerLabel());
   }
 
   public static final Creator<SecondaryInfo> CREATOR =
       new Creator<SecondaryInfo>() {
         @Override
         public SecondaryInfo createFromParcel(Parcel in) {
-          return new SecondaryInfo(in);
+          return builder()
+              .setShouldShow(in.readByte() != 0)
+              .setName(in.readString())
+              .setNameIsNumber(in.readByte() != 0)
+              .setLabel(in.readString())
+              .setProviderLabel(in.readString())
+              .setIsConference(in.readByte() != 0)
+              .setIsVideoCall(in.readByte() != 0)
+              .setIsFullscreen(in.readByte() != 0)
+              .build();
         }
 
         @Override
@@ -97,13 +116,13 @@
 
   @Override
   public void writeToParcel(Parcel dest, int flags) {
-    dest.writeByte((byte) (shouldShow ? 1 : 0));
-    dest.writeString(name);
-    dest.writeByte((byte) (nameIsNumber ? 1 : 0));
-    dest.writeString(label);
-    dest.writeString(providerLabel);
-    dest.writeByte((byte) (isConference ? 1 : 0));
-    dest.writeByte((byte) (isVideoCall ? 1 : 0));
-    dest.writeByte((byte) (isFullscreen ? 1 : 0));
+    dest.writeByte((byte) (shouldShow() ? 1 : 0));
+    dest.writeString(name());
+    dest.writeByte((byte) (nameIsNumber() ? 1 : 0));
+    dest.writeString(label());
+    dest.writeString(providerLabel());
+    dest.writeByte((byte) (isConference() ? 1 : 0));
+    dest.writeByte((byte) (isVideoCall() ? 1 : 0));
+    dest.writeByte((byte) (isFullscreen() ? 1 : 0));
   }
 }
diff --git a/java/com/android/incallui/video/impl/SurfaceViewVideoCallFragment.java b/java/com/android/incallui/video/impl/SurfaceViewVideoCallFragment.java
index 631cc1d..28ee774 100644
--- a/java/com/android/incallui/video/impl/SurfaceViewVideoCallFragment.java
+++ b/java/com/android/incallui/video/impl/SurfaceViewVideoCallFragment.java
@@ -846,7 +846,7 @@
     updateButtonStates();
     FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
     Fragment oldBanner = getChildFragmentManager().findFragmentById(R.id.videocall_on_hold_banner);
-    if (secondaryInfo.shouldShow) {
+    if (secondaryInfo.shouldShow()) {
       OnHoldFragment onHoldFragment = OnHoldFragment.newInstance(secondaryInfo);
       onHoldFragment.setPadTopInset(!isInFullscreenMode);
       transaction.replace(R.id.videocall_on_hold_banner, onHoldFragment);
diff --git a/java/com/android/incallui/video/impl/SwitchOnHoldCallController.java b/java/com/android/incallui/video/impl/SwitchOnHoldCallController.java
index 372b56b..3efdfd7 100644
--- a/java/com/android/incallui/video/impl/SwitchOnHoldCallController.java
+++ b/java/com/android/incallui/video/impl/SwitchOnHoldCallController.java
@@ -74,7 +74,7 @@
   }
 
   private boolean hasSecondaryInfo() {
-    return secondaryInfo != null && secondaryInfo.shouldShow;
+    return secondaryInfo != null && secondaryInfo.shouldShow();
   }
 
   public void updateButtonState() {
diff --git a/java/com/android/incallui/video/impl/VideoCallFragment.java b/java/com/android/incallui/video/impl/VideoCallFragment.java
index 0793d18..6b5a979 100644
--- a/java/com/android/incallui/video/impl/VideoCallFragment.java
+++ b/java/com/android/incallui/video/impl/VideoCallFragment.java
@@ -887,7 +887,7 @@
     updateButtonStates();
     FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
     Fragment oldBanner = getChildFragmentManager().findFragmentById(R.id.videocall_on_hold_banner);
-    if (secondaryInfo.shouldShow) {
+    if (secondaryInfo.shouldShow()) {
       OnHoldFragment onHoldFragment = OnHoldFragment.newInstance(secondaryInfo);
       onHoldFragment.setPadTopInset(!isInFullscreenMode);
       transaction.replace(R.id.videocall_on_hold_banner, onHoldFragment);