Convert CequintCallerIdContact into an @AutoValue

Bug: 70989584
Test: None
PiperOrigin-RevId: 194161852
Change-Id: I35e0748ab634a84f6b6a19b790bfc55090026a35
diff --git a/java/com/android/dialer/oem/CequintCallerIdManager.java b/java/com/android/dialer/oem/CequintCallerIdManager.java
index ee865bc..55cafc1 100644
--- a/java/com/android/dialer/oem/CequintCallerIdManager.java
+++ b/java/com/android/dialer/oem/CequintCallerIdManager.java
@@ -30,6 +30,7 @@
 import com.android.dialer.common.Assert;
 import com.android.dialer.common.LogUtil;
 import com.android.dialer.configprovider.ConfigProviderBindings;
+import com.google.auto.value.AutoValue;
 import java.util.concurrent.ConcurrentHashMap;
 
 /**
@@ -70,20 +71,37 @@
   // TODO(wangqi): Revisit it and maybe remove it if it's not necessary.
   private final ConcurrentHashMap<String, CequintCallerIdContact> callLogCache;
 
-  /** Cequint caller id contact information. */
-  public static class CequintCallerIdContact {
-    public final String name;
-    public final String geoDescription;
-    public final String imageUrl;
+  /** Cequint caller ID contact information. */
+  @AutoValue
+  public abstract static class CequintCallerIdContact {
 
-    private CequintCallerIdContact(String name, String geoDescription, String imageUrl) {
-      this.name = name;
-      this.geoDescription = geoDescription;
-      this.imageUrl = imageUrl;
+    public abstract String name();
+
+    /**
+     * Description of the geolocation (e.g., "Mountain View, CA"), which is for display purpose
+     * only.
+     */
+    public abstract String geolocation();
+
+    public abstract String photoUri();
+
+    static Builder builder() {
+      return new AutoValue_CequintCallerIdManager_CequintCallerIdContact.Builder();
+    }
+
+    @AutoValue.Builder
+    abstract static class Builder {
+      abstract Builder setName(String name);
+
+      abstract Builder setGeolocation(String geolocation);
+
+      abstract Builder setPhotoUri(String photoUri);
+
+      abstract CequintCallerIdContact build();
     }
   }
 
-  /** Check whether Cequint Caller Id provider package is available and enabled. */
+  /** Check whether Cequint Caller ID provider package is available and enabled. */
   @AnyThread
   public static synchronized boolean isCequintCallerIdEnabled(@NonNull Context context) {
     if (!ConfigProviderBindings.get(context).getBoolean(CONFIG_CALLER_ID_ENABLED, true)) {
@@ -175,22 +193,26 @@
         String name = getString(cursor, cursor.getColumnIndex(NAME));
         String firstName = getString(cursor, cursor.getColumnIndex(FIRST_NAME));
         String lastName = getString(cursor, cursor.getColumnIndex(LAST_NAME));
-        String imageUrl = getString(cursor, cursor.getColumnIndex(IMAGE));
+        String photoUri = getString(cursor, cursor.getColumnIndex(IMAGE));
         String displayName = getString(cursor, cursor.getColumnIndex(DISPLAY_NAME));
 
         String contactName =
             TextUtils.isEmpty(displayName)
                 ? generateDisplayName(firstName, lastName, company, name)
                 : displayName;
-        String geoDescription = getGeoDescription(city, state, stateAbbr, country);
+        String geolocation = getGeolocation(city, state, stateAbbr, country);
         LogUtil.d(
             "CequintCallerIdManager.lookup",
             "number: %s, contact name: %s, geo: %s, photo url: %s",
             LogUtil.sanitizePhoneNumber(number),
             LogUtil.sanitizePii(contactName),
-            LogUtil.sanitizePii(geoDescription),
-            imageUrl);
-        return new CequintCallerIdContact(contactName, geoDescription, imageUrl);
+            LogUtil.sanitizePii(geolocation),
+            photoUri);
+        return CequintCallerIdContact.builder()
+            .setName(contactName)
+            .setGeolocation(geolocation)
+            .setPhotoUri(photoUri)
+            .build();
       } else {
         LogUtil.d("CequintCallerIdManager.lookup", "No CequintCallerIdContact found");
         return null;
@@ -249,8 +271,8 @@
     return null;
   }
 
-  /** Returns geo location information. e.g. Mountain View, CA. */
-  private static String getGeoDescription(
+  /** Returns geolocation information (e.g., "Mountain View, CA"). */
+  private static String getGeolocation(
       String city, String state, String stateAbbr, String country) {
     String geoDescription = null;
 
diff --git a/java/com/android/dialer/phonenumbercache/ContactInfoHelper.java b/java/com/android/dialer/phonenumbercache/ContactInfoHelper.java
index 777175e..4302436 100644
--- a/java/com/android/dialer/phonenumbercache/ContactInfoHelper.java
+++ b/java/com/android/dialer/phonenumbercache/ContactInfoHelper.java
@@ -625,16 +625,16 @@
     if (cequintCallerIdContact == null) {
       return;
     }
-    if (TextUtils.isEmpty(info.name) && !TextUtils.isEmpty(cequintCallerIdContact.name)) {
-      info.name = cequintCallerIdContact.name;
+    if (TextUtils.isEmpty(info.name) && !TextUtils.isEmpty(cequintCallerIdContact.name())) {
+      info.name = cequintCallerIdContact.name();
     }
-    if (!TextUtils.isEmpty(cequintCallerIdContact.geoDescription)) {
-      info.geoDescription = cequintCallerIdContact.geoDescription;
+    if (!TextUtils.isEmpty(cequintCallerIdContact.geolocation())) {
+      info.geoDescription = cequintCallerIdContact.geolocation();
       info.sourceType = ContactSource.Type.SOURCE_TYPE_CEQUINT_CALLER_ID;
     }
     // Only update photo if local lookup has no result.
-    if (!info.contactExists && info.photoUri == null && cequintCallerIdContact.imageUrl != null) {
-      info.photoUri = UriUtils.parseUriOrNull(cequintCallerIdContact.imageUrl);
+    if (!info.contactExists && info.photoUri == null && cequintCallerIdContact.photoUri() != null) {
+      info.photoUri = UriUtils.parseUriOrNull(cequintCallerIdContact.photoUri());
     }
   }
 }
diff --git a/java/com/android/incallui/ContactInfoCache.java b/java/com/android/incallui/ContactInfoCache.java
index 165ec13..eefd483 100644
--- a/java/com/android/incallui/ContactInfoCache.java
+++ b/java/com/android/incallui/ContactInfoCache.java
@@ -522,20 +522,20 @@
     }
     boolean hasUpdate = false;
 
-    if (TextUtils.isEmpty(callerInfo.name) && !TextUtils.isEmpty(cequintCallerIdContact.name)) {
-      callerInfo.name = cequintCallerIdContact.name;
+    if (TextUtils.isEmpty(callerInfo.name) && !TextUtils.isEmpty(cequintCallerIdContact.name())) {
+      callerInfo.name = cequintCallerIdContact.name();
       hasUpdate = true;
     }
-    if (!TextUtils.isEmpty(cequintCallerIdContact.geoDescription)) {
-      callerInfo.geoDescription = cequintCallerIdContact.geoDescription;
+    if (!TextUtils.isEmpty(cequintCallerIdContact.geolocation())) {
+      callerInfo.geoDescription = cequintCallerIdContact.geolocation();
       callerInfo.shouldShowGeoDescription = true;
       hasUpdate = true;
     }
     // Don't overwrite photo in local contacts.
     if (!callerInfo.contactExists
         && callerInfo.contactDisplayPhotoUri == null
-        && cequintCallerIdContact.imageUrl != null) {
-      callerInfo.contactDisplayPhotoUri = Uri.parse(cequintCallerIdContact.imageUrl);
+        && cequintCallerIdContact.photoUri() != null) {
+      callerInfo.contactDisplayPhotoUri = Uri.parse(cequintCallerIdContact.photoUri());
       hasUpdate = true;
     }
     // Set contact to exist to avoid phone number service lookup.