From 82953530c1db1ed497c1166e2e6c2b5b04282f8a Mon Sep 17 00:00:00 2001 From: linyuh Date: Tue, 24 Apr 2018 16:06:06 -0700 Subject: Convert CequintCallerIdContact into an @AutoValue Bug: 70989584 Test: None PiperOrigin-RevId: 194161852 Change-Id: I35e0748ab634a84f6b6a19b790bfc55090026a35 --- .../android/dialer/oem/CequintCallerIdManager.java | 56 +++++++++++++++------- .../dialer/phonenumbercache/ContactInfoHelper.java | 12 ++--- java/com/android/incallui/ContactInfoCache.java | 12 ++--- 3 files changed, 51 insertions(+), 29 deletions(-) diff --git a/java/com/android/dialer/oem/CequintCallerIdManager.java b/java/com/android/dialer/oem/CequintCallerIdManager.java index ee865bc14..55cafc15e 100644 --- a/java/com/android/dialer/oem/CequintCallerIdManager.java +++ b/java/com/android/dialer/oem/CequintCallerIdManager.java @@ -30,6 +30,7 @@ import android.text.TextUtils; 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 @@ public class CequintCallerIdManager { // TODO(wangqi): Revisit it and maybe remove it if it's not necessary. private final ConcurrentHashMap 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 @@ public class CequintCallerIdManager { 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 @@ public class CequintCallerIdManager { 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 777175e00..4302436a7 100644 --- a/java/com/android/dialer/phonenumbercache/ContactInfoHelper.java +++ b/java/com/android/dialer/phonenumbercache/ContactInfoHelper.java @@ -625,16 +625,16 @@ public class ContactInfoHelper { 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 165ec13bf..eefd4833c 100644 --- a/java/com/android/incallui/ContactInfoCache.java +++ b/java/com/android/incallui/ContactInfoCache.java @@ -522,20 +522,20 @@ public class ContactInfoCache implements OnImageLoadCompleteListener { } 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. -- cgit v1.2.3