Handle contacts whose account name is null

For some locally added contacts, their account name could be null.
This is for test purposes, especially on emulators.

Bug: 145166640
Test: Manually
Change-Id: Id8e0627719b5780efb6f5d7a76d4057fa945fe1b
diff --git a/car-telephony-common/src/com/android/car/telephony/common/Contact.java b/car-telephony-common/src/com/android/car/telephony/common/Contact.java
index 2f6212d..9c017b4 100644
--- a/car-telephony-common/src/com/android/car/telephony/common/Contact.java
+++ b/car-telephony-common/src/com/android/car/telephony/common/Contact.java
@@ -226,7 +226,8 @@
             contact.loadBasicInfo(cursor);
         }
 
-        if (!accountName.equals(contact.mAccountName) || !lookupKey.equals(contact.mLookupKey)) {
+        if (!TextUtils.equals(accountName, contact.mAccountName)
+                || !TextUtils.equals(lookupKey, contact.mLookupKey)) {
             Log.w(TAG, "A wrong contact is passed in. A new contact will be created.");
             contact = new Contact();
             contact.loadBasicInfo(cursor);
diff --git a/car-telephony-common/src/com/android/car/telephony/common/InMemoryPhoneBook.java b/car-telephony-common/src/com/android/car/telephony/common/InMemoryPhoneBook.java
index db95960..42345ff 100644
--- a/car-telephony-common/src/com/android/car/telephony/common/InMemoryPhoneBook.java
+++ b/car-telephony-common/src/com/android/car/telephony/common/InMemoryPhoneBook.java
@@ -158,11 +158,11 @@
     }
 
     /**
-     * Looks up a {@link Contact} by the given lookup key and account name. Returns null if can't
-     * find the contact entry.
+     * Looks up a {@link Contact} by the given lookup key and account name. Account name could be
+     * null for locally added contacts. Returns null if can't find the contact entry.
      */
     @Nullable
-    public Contact lookupContactByKey(String lookupKey, String accountName) {
+    public Contact lookupContactByKey(String lookupKey, @Nullable String accountName) {
         if (!isLoaded()) {
             Log.w(TAG, "looking up a contact while loading.");
         }
@@ -170,10 +170,6 @@
             Log.w(TAG, "looking up an empty lookup key.");
             return null;
         }
-        if (TextUtils.isEmpty(accountName)) {
-            Log.w(TAG, "looking up an empty lookup account");
-            return null;
-        }
 
         return mLookupKeyContactMap.get(getContactKey(lookupKey, accountName));
     }
@@ -213,9 +209,10 @@
     }
 
     /**
-     * Formats a key to identify a contact based the lookup key and the account name.
+     * Formats a key to identify a contact based the lookup key and the account name. Account Name
+     * could be null and it will be handled by String.format().
      */
-    private String getContactKey(String lookupKey, String accountName) {
+    private String getContactKey(String lookupKey, @Nullable String accountName) {
         String key = String.format(KEY_FORMAT, lookupKey, accountName);
         Log.d(TAG, "Contact key is: " + key);
         return key;