Refactor ContactPreference
Moving it outside contacts.commons reduces dependency to legacy code. Also removed redundant implementations such as caching SharedPreferences (it is already cached), custom ListPreferences (standard ListPreferences already have what we want), and corrected preference storage location (allow standard ListPreferences to work)
TEST=TAP
Test: TAP
PiperOrigin-RevId: 202000393
Change-Id: I45374e610b3510784b5a4da92e5d8462cbfc92bb
diff --git a/java/com/android/incallui/ExternalCallNotifier.java b/java/com/android/incallui/ExternalCallNotifier.java
index 10c4a64..160e250 100644
--- a/java/com/android/incallui/ExternalCallNotifier.java
+++ b/java/com/android/incallui/ExternalCallNotifier.java
@@ -38,10 +38,9 @@
import android.util.ArrayMap;
import com.android.contacts.common.ContactsUtils;
import com.android.contacts.common.compat.CallCompat;
-import com.android.contacts.common.preference.ContactsPreferences;
-import com.android.contacts.common.util.ContactDisplayUtils;
import com.android.dialer.common.Assert;
import com.android.dialer.contactphoto.BitmapUtil;
+import com.android.dialer.contacts.ContactsComponent;
import com.android.dialer.notification.DialerNotificationManager;
import com.android.dialer.notification.NotificationChannelId;
import com.android.dialer.telecom.TelecomCallUtil;
@@ -78,13 +77,11 @@
private final ContactInfoCache contactInfoCache;
private Map<Call, NotificationInfo> notifications = new ArrayMap<>();
private int nextUniqueNotificationId;
- private ContactsPreferences contactsPreferences;
/** Initializes a new instance of the external call notifier. */
public ExternalCallNotifier(
@NonNull Context context, @NonNull ContactInfoCache contactInfoCache) {
this.context = context;
- contactsPreferences = ContactsPreferencesFactory.newContactsPreferences(this.context);
this.contactInfoCache = contactInfoCache;
}
@@ -216,7 +213,7 @@
* notification to the notification manager.
*/
private void saveContactInfo(NotificationInfo info, ContactInfoCache.ContactCacheEntry entry) {
- info.setContentTitle(getContentTitle(context, contactsPreferences, entry, info.getCall()));
+ info.setContentTitle(getContentTitle(context, entry, info.getCall()));
info.setPersonReference(getPersonReference(entry, info.getCall()));
postNotification(info);
}
@@ -342,17 +339,12 @@
* number.
*
* @param context The context.
- * @param contactsPreferences Contacts preferences, used to determine the preferred formatting for
- * contact names.
* @param contactInfo The contact info which was looked up in the contact cache.
* @param call The call to generate a title for.
* @return The content title.
*/
private @Nullable String getContentTitle(
- Context context,
- @Nullable ContactsPreferences contactsPreferences,
- ContactInfoCache.ContactCacheEntry contactInfo,
- android.telecom.Call call) {
+ Context context, ContactInfoCache.ContactCacheEntry contactInfo, android.telecom.Call call) {
if (call.getDetails().hasProperty(android.telecom.Call.Details.PROPERTY_CONFERENCE)) {
return CallerInfoUtils.getConferenceString(
@@ -361,8 +353,9 @@
}
String preferredName =
- ContactDisplayUtils.getPreferredDisplayName(
- contactInfo.namePrimary, contactInfo.nameAlternative, contactsPreferences);
+ ContactsComponent.get(context)
+ .contactDisplayPreferences()
+ .getDisplayName(contactInfo.namePrimary, contactInfo.nameAlternative);
if (TextUtils.isEmpty(preferredName)) {
return TextUtils.isEmpty(contactInfo.number)
? null