Look up contacts in the local enterprise directory in the new call log.

Bug: 73547944
Test: Cp2ExtendedDirectoryPhoneLookupTest
PiperOrigin-RevId: 187064655
Change-Id: Icb468e0867248f097a77134dd67a53352f7c80b0
diff --git a/java/com/android/dialer/calllog/ui/RealtimeRowProcessor.java b/java/com/android/dialer/calllog/ui/RealtimeRowProcessor.java
index 22c3a3c..b7cb6d7 100644
--- a/java/com/android/dialer/calllog/ui/RealtimeRowProcessor.java
+++ b/java/com/android/dialer/calllog/ui/RealtimeRowProcessor.java
@@ -96,7 +96,7 @@
    */
   @MainThread
   ListenableFuture<CoalescedRow> applyRealtimeProcessing(final CoalescedRow row) {
-    // Cp2LocalPhoneLookup can not always efficiently process all rows.
+    // Cp2DefaultDirectoryPhoneLookup can not always efficiently process all rows.
     if (!row.numberAttributes().getIsCp2InfoIncomplete()) {
       return Futures.immediateFuture(row);
     }
diff --git a/java/com/android/dialer/calllogutils/NumberAttributesConverter.java b/java/com/android/dialer/calllogutils/NumberAttributesConverter.java
index efd1d72..ceb8d57 100644
--- a/java/com/android/dialer/calllogutils/NumberAttributesConverter.java
+++ b/java/com/android/dialer/calllogutils/NumberAttributesConverter.java
@@ -56,6 +56,6 @@
         .setIsBlocked(phoneLookupInfoConsolidator.isBlocked())
         .setIsSpam(phoneLookupInfoConsolidator.isSpam())
         .setCanReportAsInvalidNumber(phoneLookupInfoConsolidator.canReportAsInvalidNumber())
-        .setIsCp2InfoIncomplete(phoneLookupInfoConsolidator.isCp2LocalInfoIncomplete());
+        .setIsCp2InfoIncomplete(phoneLookupInfoConsolidator.isDefaultCp2InfoIncomplete());
   }
 }
diff --git a/java/com/android/dialer/phonelookup/PhoneLookupModule.java b/java/com/android/dialer/phonelookup/PhoneLookupModule.java
index 3e21e7c..a4cc5c7 100644
--- a/java/com/android/dialer/phonelookup/PhoneLookupModule.java
+++ b/java/com/android/dialer/phonelookup/PhoneLookupModule.java
@@ -18,8 +18,8 @@
 
 import com.android.dialer.phonelookup.blockednumber.DialerBlockedNumberPhoneLookup;
 import com.android.dialer.phonelookup.blockednumber.SystemBlockedNumberPhoneLookup;
-import com.android.dialer.phonelookup.cp2.Cp2LocalPhoneLookup;
-import com.android.dialer.phonelookup.cp2.Cp2RemotePhoneLookup;
+import com.android.dialer.phonelookup.cp2.Cp2DefaultDirectoryPhoneLookup;
+import com.android.dialer.phonelookup.cp2.Cp2ExtendedDirectoryPhoneLookup;
 import com.android.dialer.phonelookup.spam.SpamPhoneLookup;
 import com.google.common.collect.ImmutableList;
 import dagger.Module;
@@ -32,14 +32,14 @@
   @Provides
   @SuppressWarnings({"unchecked", "rawtype"})
   static ImmutableList<PhoneLookup> providePhoneLookupList(
-      Cp2LocalPhoneLookup cp2LocalPhoneLookup,
-      Cp2RemotePhoneLookup cp2RemotePhoneLookup,
+      Cp2DefaultDirectoryPhoneLookup cp2DefaultDirectoryPhoneLookup,
+      Cp2ExtendedDirectoryPhoneLookup cp2ExtendedDirectoryPhoneLookup,
       DialerBlockedNumberPhoneLookup dialerBlockedNumberPhoneLookup,
       SystemBlockedNumberPhoneLookup systemBlockedNumberPhoneLookup,
       SpamPhoneLookup spamPhoneLookup) {
     return ImmutableList.of(
-        cp2LocalPhoneLookup,
-        cp2RemotePhoneLookup,
+        cp2DefaultDirectoryPhoneLookup,
+        cp2ExtendedDirectoryPhoneLookup,
         dialerBlockedNumberPhoneLookup,
         systemBlockedNumberPhoneLookup,
         spamPhoneLookup);
diff --git a/java/com/android/dialer/phonelookup/consolidator/PhoneLookupInfoConsolidator.java b/java/com/android/dialer/phonelookup/consolidator/PhoneLookupInfoConsolidator.java
index 9c54110..3a48fd5 100644
--- a/java/com/android/dialer/phonelookup/consolidator/PhoneLookupInfoConsolidator.java
+++ b/java/com/android/dialer/phonelookup/consolidator/PhoneLookupInfoConsolidator.java
@@ -40,11 +40,16 @@
 
   /** Integers representing {@link PhoneLookup} implementations that can provide a contact's name */
   @Retention(RetentionPolicy.SOURCE)
-  @IntDef({NameSource.NONE, NameSource.CP2_LOCAL, NameSource.CP2_REMOTE, NameSource.PEOPLE_API})
+  @IntDef({
+    NameSource.NONE,
+    NameSource.CP2_DEFAULT_DIRECTORY,
+    NameSource.CP2_EXTENDED_DIRECTORY,
+    NameSource.PEOPLE_API
+  })
   @interface NameSource {
     int NONE = 0; // used when none of the other sources can provide the name
-    int CP2_LOCAL = 1;
-    int CP2_REMOTE = 2;
+    int CP2_DEFAULT_DIRECTORY = 1;
+    int CP2_EXTENDED_DIRECTORY = 2;
     int PEOPLE_API = 3;
   }
 
@@ -53,31 +58,35 @@
    *
    * <p>Each source is one of the values in NameSource, as defined above.
    *
-   * <p>Sources are sorted in the order of priority. For example, if source CP2_LOCAL can provide
-   * the name, we will use that name in the UI and ignore all the other sources. If source CP2_LOCAL
-   * can't provide the name, source CP2_REMOTE will be consulted.
+   * <p>Sources are sorted in the order of priority. For example, if source CP2_DEFAULT_DIRECTORY
+   * can provide the name, we will use that name in the UI and ignore all the other sources. If
+   * source CP2_DEFAULT_DIRECTORY can't provide the name, source CP2_EXTENDED_DIRECTORY will be
+   * consulted.
    *
    * <p>The reason for defining a name source is to avoid mixing info from different sub-messages in
    * PhoneLookupInfo proto when we are supposed to stick with only one sub-message. For example, if
-   * a PhoneLookupInfo proto has both cp2_local_info and cp2_remote_info but only cp2_remote_info
-   * has a photo URI, PhoneLookupInfoConsolidator should provide an empty photo URI as CP2_LOCAL has
-   * higher priority and we should not use cp2_remote_info's photo URI to display the contact's
-   * photo.
+   * a PhoneLookupInfo proto has both default_cp2_info and extended_cp2_info but only
+   * extended_cp2_info has a photo URI, PhoneLookupInfoConsolidator should provide an empty photo
+   * URI as CP2_DEFAULT_DIRECTORY has higher priority and we should not use extended_cp2_info's
+   * photo URI to display the contact's photo.
    */
   private static final ImmutableList<Integer> NAME_SOURCES_IN_PRIORITY_ORDER =
-      ImmutableList.of(NameSource.CP2_LOCAL, NameSource.CP2_REMOTE, NameSource.PEOPLE_API);
+      ImmutableList.of(
+          NameSource.CP2_DEFAULT_DIRECTORY,
+          NameSource.CP2_EXTENDED_DIRECTORY,
+          NameSource.PEOPLE_API);
 
   private final @NameSource int nameSource;
   private final PhoneLookupInfo phoneLookupInfo;
 
-  @Nullable private final Cp2ContactInfo firstCp2LocalContact;
-  @Nullable private final Cp2ContactInfo firstCp2RemoteContact;
+  @Nullable private final Cp2ContactInfo firstDefaultCp2Contact;
+  @Nullable private final Cp2ContactInfo firstExtendedCp2Contact;
 
   public PhoneLookupInfoConsolidator(PhoneLookupInfo phoneLookupInfo) {
     this.phoneLookupInfo = phoneLookupInfo;
 
-    this.firstCp2LocalContact = getFirstLocalContact();
-    this.firstCp2RemoteContact = getFirstRemoteContact();
+    this.firstDefaultCp2Contact = getFirstContactInDefaultDirectory();
+    this.firstExtendedCp2Contact = getFirstContactInExtendedDirectories();
     this.nameSource = selectNameSource();
   }
 
@@ -92,10 +101,10 @@
    */
   public String getName() {
     switch (nameSource) {
-      case NameSource.CP2_LOCAL:
-        return Assert.isNotNull(firstCp2LocalContact).getName();
-      case NameSource.CP2_REMOTE:
-        return Assert.isNotNull(firstCp2RemoteContact).getName();
+      case NameSource.CP2_DEFAULT_DIRECTORY:
+        return Assert.isNotNull(firstDefaultCp2Contact).getName();
+      case NameSource.CP2_EXTENDED_DIRECTORY:
+        return Assert.isNotNull(firstExtendedCp2Contact).getName();
       case NameSource.PEOPLE_API:
         return phoneLookupInfo.getPeopleApiInfo().getDisplayName();
       case NameSource.NONE:
@@ -115,10 +124,10 @@
    */
   public String getPhotoThumbnailUri() {
     switch (nameSource) {
-      case NameSource.CP2_LOCAL:
-        return Assert.isNotNull(firstCp2LocalContact).getPhotoThumbnailUri();
-      case NameSource.CP2_REMOTE:
-        return Assert.isNotNull(firstCp2RemoteContact).getPhotoThumbnailUri();
+      case NameSource.CP2_DEFAULT_DIRECTORY:
+        return Assert.isNotNull(firstDefaultCp2Contact).getPhotoThumbnailUri();
+      case NameSource.CP2_EXTENDED_DIRECTORY:
+        return Assert.isNotNull(firstExtendedCp2Contact).getPhotoThumbnailUri();
       case NameSource.PEOPLE_API:
       case NameSource.NONE:
         return "";
@@ -137,10 +146,10 @@
    */
   public String getPhotoUri() {
     switch (nameSource) {
-      case NameSource.CP2_LOCAL:
-        return Assert.isNotNull(firstCp2LocalContact).getPhotoUri();
-      case NameSource.CP2_REMOTE:
-        return Assert.isNotNull(firstCp2RemoteContact).getPhotoUri();
+      case NameSource.CP2_DEFAULT_DIRECTORY:
+        return Assert.isNotNull(firstDefaultCp2Contact).getPhotoUri();
+      case NameSource.CP2_EXTENDED_DIRECTORY:
+        return Assert.isNotNull(firstExtendedCp2Contact).getPhotoUri();
       case NameSource.PEOPLE_API:
       case NameSource.NONE:
         return "";
@@ -156,10 +165,10 @@
    */
   public long getPhotoId() {
     switch (nameSource) {
-      case NameSource.CP2_LOCAL:
-        return Math.max(Assert.isNotNull(firstCp2LocalContact).getPhotoId(), 0);
-      case NameSource.CP2_REMOTE:
-        return Math.max(Assert.isNotNull(firstCp2RemoteContact).getPhotoId(), 0);
+      case NameSource.CP2_DEFAULT_DIRECTORY:
+        return Math.max(Assert.isNotNull(firstDefaultCp2Contact).getPhotoId(), 0);
+      case NameSource.CP2_EXTENDED_DIRECTORY:
+        return Math.max(Assert.isNotNull(firstExtendedCp2Contact).getPhotoId(), 0);
       case NameSource.PEOPLE_API:
       case NameSource.NONE:
         return 0;
@@ -176,10 +185,10 @@
    */
   public String getLookupUri() {
     switch (nameSource) {
-      case NameSource.CP2_LOCAL:
-        return Assert.isNotNull(firstCp2LocalContact).getLookupUri();
-      case NameSource.CP2_REMOTE:
-        return Assert.isNotNull(firstCp2RemoteContact).getLookupUri();
+      case NameSource.CP2_DEFAULT_DIRECTORY:
+        return Assert.isNotNull(firstDefaultCp2Contact).getLookupUri();
+      case NameSource.CP2_EXTENDED_DIRECTORY:
+        return Assert.isNotNull(firstExtendedCp2Contact).getLookupUri();
       case NameSource.PEOPLE_API:
         return Assert.isNotNull(phoneLookupInfo.getPeopleApiInfo().getLookupUri());
       case NameSource.NONE:
@@ -200,10 +209,10 @@
    */
   public String getNumberLabel() {
     switch (nameSource) {
-      case NameSource.CP2_LOCAL:
-        return Assert.isNotNull(firstCp2LocalContact).getLabel();
-      case NameSource.CP2_REMOTE:
-        return Assert.isNotNull(firstCp2RemoteContact).getLabel();
+      case NameSource.CP2_DEFAULT_DIRECTORY:
+        return Assert.isNotNull(firstDefaultCp2Contact).getLabel();
+      case NameSource.CP2_EXTENDED_DIRECTORY:
+        return Assert.isNotNull(firstExtendedCp2Contact).getLabel();
       case NameSource.PEOPLE_API:
       case NameSource.NONE:
         return "";
@@ -259,11 +268,11 @@
   }
 
   /**
-   * Returns true if the {@link PhoneLookupInfo} passed to the constructor has incomplete CP2 local
-   * info.
+   * Returns true if the {@link PhoneLookupInfo} passed to the constructor has incomplete default
+   * CP2 info (info from the default directory).
    */
-  public boolean isCp2LocalInfoIncomplete() {
-    return phoneLookupInfo.getCp2LocalInfo().getIsIncomplete();
+  public boolean isDefaultCp2InfoIncomplete() {
+    return phoneLookupInfo.getDefaultCp2Info().getIsIncomplete();
   }
 
   /**
@@ -275,8 +284,8 @@
    */
   public boolean canReportAsInvalidNumber() {
     switch (nameSource) {
-      case NameSource.CP2_LOCAL:
-      case NameSource.CP2_REMOTE:
+      case NameSource.CP2_DEFAULT_DIRECTORY:
+      case NameSource.CP2_EXTENDED_DIRECTORY:
         return false;
       case NameSource.PEOPLE_API:
         PeopleApiInfo peopleApiInfo = phoneLookupInfo.getPeopleApiInfo();
@@ -291,26 +300,26 @@
   }
 
   /**
-   * Arbitrarily select the first local CP2 contact. In the future, it may make sense to display
-   * contact information from all contacts with the same number (for example show the name as "Mom,
-   * Dad" or show a synthesized photo containing photos of both "Mom" and "Dad").
+   * Arbitrarily select the first CP2 contact in the default directory. In the future, it may make
+   * sense to display contact information from all contacts with the same number (for example show
+   * the name as "Mom, Dad" or show a synthesized photo containing photos of both "Mom" and "Dad").
    */
   @Nullable
-  private Cp2ContactInfo getFirstLocalContact() {
-    return phoneLookupInfo.getCp2LocalInfo().getCp2ContactInfoCount() > 0
-        ? phoneLookupInfo.getCp2LocalInfo().getCp2ContactInfo(0)
+  private Cp2ContactInfo getFirstContactInDefaultDirectory() {
+    return phoneLookupInfo.getDefaultCp2Info().getCp2ContactInfoCount() > 0
+        ? phoneLookupInfo.getDefaultCp2Info().getCp2ContactInfo(0)
         : null;
   }
 
   /**
-   * Arbitrarily select the first remote CP2 contact. In the future, it may make sense to display
-   * contact information from all contacts with the same number (for example show the name as "Mom,
-   * Dad" or show a synthesized photo containing photos of both "Mom" and "Dad").
+   * Arbitrarily select the first CP2 contact in extended directories. In the future, it may make
+   * sense to display contact information from all contacts with the same number (for example show
+   * the name as "Mom, Dad" or show a synthesized photo containing photos of both "Mom" and "Dad").
    */
   @Nullable
-  private Cp2ContactInfo getFirstRemoteContact() {
-    return phoneLookupInfo.getCp2RemoteInfo().getCp2ContactInfoCount() > 0
-        ? phoneLookupInfo.getCp2RemoteInfo().getCp2ContactInfo(0)
+  private Cp2ContactInfo getFirstContactInExtendedDirectories() {
+    return phoneLookupInfo.getExtendedCp2Info().getCp2ContactInfoCount() > 0
+        ? phoneLookupInfo.getExtendedCp2Info().getCp2ContactInfo(0)
         : null;
   }
 
@@ -318,14 +327,14 @@
   private @NameSource int selectNameSource() {
     for (int nameSource : NAME_SOURCES_IN_PRIORITY_ORDER) {
       switch (nameSource) {
-        case NameSource.CP2_LOCAL:
-          if (firstCp2LocalContact != null && !firstCp2LocalContact.getName().isEmpty()) {
-            return NameSource.CP2_LOCAL;
+        case NameSource.CP2_DEFAULT_DIRECTORY:
+          if (firstDefaultCp2Contact != null && !firstDefaultCp2Contact.getName().isEmpty()) {
+            return NameSource.CP2_DEFAULT_DIRECTORY;
           }
           break;
-        case NameSource.CP2_REMOTE:
-          if (firstCp2RemoteContact != null && !firstCp2RemoteContact.getName().isEmpty()) {
-            return NameSource.CP2_REMOTE;
+        case NameSource.CP2_EXTENDED_DIRECTORY:
+          if (firstExtendedCp2Contact != null && !firstExtendedCp2Contact.getName().isEmpty()) {
+            return NameSource.CP2_EXTENDED_DIRECTORY;
           }
           break;
         case NameSource.PEOPLE_API:
diff --git a/java/com/android/dialer/phonelookup/cp2/Cp2LocalPhoneLookup.java b/java/com/android/dialer/phonelookup/cp2/Cp2DefaultDirectoryPhoneLookup.java
similarity index 95%
rename from java/com/android/dialer/phonelookup/cp2/Cp2LocalPhoneLookup.java
rename to java/com/android/dialer/phonelookup/cp2/Cp2DefaultDirectoryPhoneLookup.java
index 8db3088..a79eb19 100644
--- a/java/com/android/dialer/phonelookup/cp2/Cp2LocalPhoneLookup.java
+++ b/java/com/android/dialer/phonelookup/cp2/Cp2DefaultDirectoryPhoneLookup.java
@@ -58,11 +58,11 @@
 import java.util.concurrent.Callable;
 import javax.inject.Inject;
 
-/** PhoneLookup implementation for local contacts. */
-public final class Cp2LocalPhoneLookup implements PhoneLookup<Cp2Info> {
+/** PhoneLookup implementation for contacts in the default directory. */
+public final class Cp2DefaultDirectoryPhoneLookup implements PhoneLookup<Cp2Info> {
 
   private static final String PREF_LAST_TIMESTAMP_PROCESSED =
-      "cp2LocalPhoneLookupLastTimestampProcessed";
+      "cp2DefaultDirectoryPhoneLookupLastTimestampProcessed";
 
   // We cannot efficiently process invalid numbers because batch queries cannot be constructed which
   // accomplish the necessary loose matching. We'll attempt to process a limited number of them,
@@ -77,7 +77,7 @@
   @Nullable private Long currentLastTimestampProcessed;
 
   @Inject
-  Cp2LocalPhoneLookup(
+  Cp2DefaultDirectoryPhoneLookup(
       @ApplicationContext Context appContext,
       @Unencrypted SharedPreferences sharedPreferences,
       @BackgroundExecutor ListeningExecutorService backgroundExecutorService,
@@ -121,7 +121,7 @@
                 Iterables.getOnlyElement(partitionedNumbers.invalidNumbers()));
       }
       if (cursor == null) {
-        LogUtil.w("Cp2LocalPhoneLookup.lookupInternal", "null cursor");
+        LogUtil.w("Cp2DefaultDirectoryPhoneLookup.lookupInternal", "null cursor");
         return Cp2Info.getDefaultInstance();
       }
       while (cursor.moveToNext()) {
@@ -144,7 +144,7 @@
       // check, simply return true. The expectation is that this should rarely be the case as the
       // vast majority of numbers in call logs should be valid.
       LogUtil.v(
-          "Cp2LocalPhoneLookup.isDirty",
+          "Cp2DefaultDirectoryPhoneLookup.isDirty",
           "returning true because too many invalid numbers (%d)",
           partitionedNumbers.invalidNumbers().size());
       return Futures.immediateFuture(true);
@@ -164,7 +164,8 @@
               anyContactsDeleted -> {
                 if (anyContactsDeleted) {
                   LogUtil.v(
-                      "Cp2LocalPhoneLookup.isDirty", "returning true because contacts deleted");
+                      "Cp2DefaultDirectoryPhoneLookup.isDirty",
+                      "returning true because contacts deleted");
                   return Futures.immediateFuture(true);
                 }
                 // Hopefully the most common case is there are no contacts updated; we can detect
@@ -176,7 +177,7 @@
                     noContactsModifiedSince -> {
                       if (noContactsModifiedSince) {
                         LogUtil.v(
-                            "Cp2LocalPhoneLookup.isDirty",
+                            "Cp2DefaultDirectoryPhoneLookup.isDirty",
                             "returning false because no contacts modified since last run");
                         return Futures.immediateFuture(false);
                       }
@@ -194,7 +195,7 @@
                           contactsUpdated -> {
                             if (contactsUpdated) {
                               LogUtil.v(
-                                  "Cp2LocalPhoneLookup.isDirty",
+                                  "Cp2DefaultDirectoryPhoneLookup.isDirty",
                                   "returning true because a previously called contact was updated");
                               return Futures.immediateFuture(true);
                             }
@@ -267,7 +268,9 @@
                       null)) {
 
             if (cursor == null) {
-              LogUtil.w("Cp2LocalPhoneLookup.queryPhoneLookupHistoryForContactIds", "null cursor");
+              LogUtil.w(
+                  "Cp2DefaultDirectoryPhoneLookup.queryPhoneLookupHistoryForContactIds",
+                  "null cursor");
               return contactIds;
             }
 
@@ -283,7 +286,7 @@
                   throw new IllegalStateException(e);
                 }
                 for (Cp2ContactInfo info :
-                    phoneLookupInfo.getCp2LocalInfo().getCp2ContactInfoList()) {
+                    phoneLookupInfo.getDefaultCp2Info().getCp2ContactInfoList()) {
                   contactIds.add(info.getContactId());
                 }
               } while (cursor.moveToNext());
@@ -305,7 +308,8 @@
               queryPhoneTableBasedOnE164(new String[] {Phone.CONTACT_ID}, validE164Numbers)) {
             if (cursor == null) {
               LogUtil.w(
-                  "Cp2LocalPhoneLookup.queryPhoneTableForContactIdsBasedOnE164", "null cursor");
+                  "Cp2DefaultDirectoryPhoneLookup.queryPhoneTableForContactIdsBasedOnE164",
+                  "null cursor");
               return contactIds;
             }
             while (cursor.moveToNext()) {
@@ -328,7 +332,7 @@
               queryPhoneLookup(new String[] {ContactsContract.PhoneLookup.CONTACT_ID}, rawNumber)) {
             if (cursor == null) {
               LogUtil.w(
-                  "Cp2LocalPhoneLookup.queryPhoneLookupTableForContactIdsBasedOnRawNumber",
+                  "Cp2DefaultDirectoryPhoneLookup.queryPhoneLookupTableForContactIdsBasedOnRawNumber",
                   "null cursor");
               return contactIds;
             }
@@ -391,7 +395,7 @@
                       new String[] {Long.toString(lastModified)},
                       Contacts._ID + " limit 1")) {
             if (cursor == null) {
-              LogUtil.w("Cp2LocalPhoneLookup.noContactsModifiedSince", "null cursor");
+              LogUtil.w("Cp2DefaultDirectoryPhoneLookup.noContactsModifiedSince", "null cursor");
               return false;
             }
             return cursor.getCount() == 0;
@@ -413,7 +417,7 @@
                       new String[] {Long.toString(lastModified)},
                       DeletedContacts.CONTACT_DELETED_TIMESTAMP + " limit 1")) {
             if (cursor == null) {
-              LogUtil.w("Cp2LocalPhoneLookup.anyContactsDeletedSince", "null cursor");
+              LogUtil.w("Cp2DefaultDirectoryPhoneLookup.anyContactsDeletedSince", "null cursor");
               return false;
             }
             return cursor.getCount() > 0;
@@ -423,12 +427,12 @@
 
   @Override
   public void setSubMessage(PhoneLookupInfo.Builder destination, Cp2Info subMessage) {
-    destination.setCp2LocalInfo(subMessage);
+    destination.setDefaultCp2Info(subMessage);
   }
 
   @Override
   public Cp2Info getSubMessage(PhoneLookupInfo phoneLookupInfo) {
-    return phoneLookupInfo.getCp2LocalInfo();
+    return phoneLookupInfo.getDefaultCp2Info();
   }
 
   @Override
@@ -712,7 +716,7 @@
                   map.put(dialerPhoneNumber, ImmutableSet.of());
                 }
                 LogUtil.v(
-                    "Cp2LocalPhoneLookup.buildMapForUpdatedOrAddedContacts",
+                    "Cp2DefaultDirectoryPhoneLookup.buildMapForUpdatedOrAddedContacts",
                     "found %d numbers that may need updating",
                     updatedNumbers.size());
                 return map;
@@ -735,7 +739,7 @@
               queryPhoneTableBasedOnE164(
                   Cp2Projections.getProjectionForPhoneTable(), validE164Numbers)) {
             if (cursor == null) {
-              LogUtil.w("Cp2LocalPhoneLookup.batchQueryForValidNumbers", "null cursor");
+              LogUtil.w("Cp2DefaultDirectoryPhoneLookup.batchQueryForValidNumbers", "null cursor");
             } else {
               while (cursor.moveToNext()) {
                 String validE164Number = Cp2Projections.getNormalizedNumberFromCursor(cursor);
@@ -764,7 +768,8 @@
           try (Cursor cursor =
               queryPhoneLookup(Cp2Projections.getProjectionForPhoneLookupTable(), invalidNumber)) {
             if (cursor == null) {
-              LogUtil.w("Cp2LocalPhoneLookup.individualQueryForInvalidNumber", "null cursor");
+              LogUtil.w(
+                  "Cp2DefaultDirectoryPhoneLookup.individualQueryForInvalidNumber", "null cursor");
             } else {
               while (cursor.moveToNext()) {
                 cp2ContactInfos.add(
diff --git a/java/com/android/dialer/phonelookup/cp2/Cp2RemotePhoneLookup.java b/java/com/android/dialer/phonelookup/cp2/Cp2ExtendedDirectoryPhoneLookup.java
similarity index 75%
rename from java/com/android/dialer/phonelookup/cp2/Cp2RemotePhoneLookup.java
rename to java/com/android/dialer/phonelookup/cp2/Cp2ExtendedDirectoryPhoneLookup.java
index 7efe039..df164bd 100644
--- a/java/com/android/dialer/phonelookup/cp2/Cp2RemotePhoneLookup.java
+++ b/java/com/android/dialer/phonelookup/cp2/Cp2ExtendedDirectoryPhoneLookup.java
@@ -42,15 +42,20 @@
 import java.util.List;
 import javax.inject.Inject;
 
-/** PhoneLookup implementation for remote contacts. */
-public final class Cp2RemotePhoneLookup implements PhoneLookup<Cp2Info> {
+/**
+ * PhoneLookup implementation for contacts in both local and remote directories other than the
+ * default directory.
+ *
+ * <p>Contacts in these directories are accessible only by specifying a directory ID.
+ */
+public final class Cp2ExtendedDirectoryPhoneLookup implements PhoneLookup<Cp2Info> {
 
   private final Context appContext;
   private final ListeningExecutorService backgroundExecutorService;
   private final ListeningExecutorService lightweightExecutorService;
 
   @Inject
-  Cp2RemotePhoneLookup(
+  Cp2ExtendedDirectoryPhoneLookup(
       @ApplicationContext Context appContext,
       @BackgroundExecutor ListeningExecutorService backgroundExecutorService,
       @LightweightExecutor ListeningExecutorService lightweightExecutorService) {
@@ -62,15 +67,15 @@
   @Override
   public ListenableFuture<Cp2Info> lookup(DialerPhoneNumber dialerPhoneNumber) {
     return Futures.transformAsync(
-        queryCp2ForRemoteDirectoryIds(),
-        remoteDirectoryIds -> queryCp2ForRemoteContact(dialerPhoneNumber, remoteDirectoryIds),
+        queryCp2ForExtendedDirectoryIds(),
+        directoryIds -> queryCp2ForDirectoryContact(dialerPhoneNumber, directoryIds),
         lightweightExecutorService);
   }
 
-  private ListenableFuture<List<Long>> queryCp2ForRemoteDirectoryIds() {
+  private ListenableFuture<List<Long>> queryCp2ForExtendedDirectoryIds() {
     return backgroundExecutorService.submit(
         () -> {
-          List<Long> remoteDirectoryIds = new ArrayList<>();
+          List<Long> directoryIds = new ArrayList<>();
           try (Cursor cursor =
               appContext
                   .getContentResolver()
@@ -81,34 +86,34 @@
                       /* selectionArgs = */ null,
                       /* sortOrder = */ ContactsContract.Directory._ID)) {
             if (cursor == null) {
-              LogUtil.e("Cp2RemotePhoneLookup.queryCp2ForDirectoryIds", "null cursor");
-              return remoteDirectoryIds;
+              LogUtil.e(
+                  "Cp2ExtendedDirectoryPhoneLookup.queryCp2ForExtendedDirectoryIds", "null cursor");
+              return directoryIds;
             }
 
             if (!cursor.moveToFirst()) {
-              LogUtil.i("Cp2RemotePhoneLookup.queryCp2ForDirectoryIds", "empty cursor");
-              return remoteDirectoryIds;
+              LogUtil.i(
+                  "Cp2ExtendedDirectoryPhoneLookup.queryCp2ForExtendedDirectoryIds",
+                  "empty cursor");
+              return directoryIds;
             }
 
             int idColumnIndex = cursor.getColumnIndexOrThrow(ContactsContract.Directory._ID);
             do {
               long directoryId = cursor.getLong(idColumnIndex);
 
-              // Note that IDs of non-remote directories will be included in the result, such as
-              // android.provider.ContactsContract.Directory.DEFAULT (the default directory that
-              // represents locally stored contacts).
-              if (isRemoteDirectory(directoryId)) {
-                remoteDirectoryIds.add(cursor.getLong(idColumnIndex));
+              if (isExtendedDirectory(directoryId)) {
+                directoryIds.add(cursor.getLong(idColumnIndex));
               }
             } while (cursor.moveToNext());
-            return remoteDirectoryIds;
+            return directoryIds;
           }
         });
   }
 
-  private ListenableFuture<Cp2Info> queryCp2ForRemoteContact(
-      DialerPhoneNumber dialerPhoneNumber, List<Long> remoteDirectoryIds) {
-    if (remoteDirectoryIds.isEmpty()) {
+  private ListenableFuture<Cp2Info> queryCp2ForDirectoryContact(
+      DialerPhoneNumber dialerPhoneNumber, List<Long> directoryIds) {
+    if (directoryIds.isEmpty()) {
       return Futures.immediateFuture(Cp2Info.getDefaultInstance());
     }
 
@@ -116,8 +121,8 @@
     String number = dialerPhoneNumber.getNormalizedNumber();
 
     List<ListenableFuture<Cp2Info>> cp2InfoFutures = new ArrayList<>();
-    for (long remoteDirectoryId : remoteDirectoryIds) {
-      cp2InfoFutures.add(queryCp2ForRemoteContact(number, remoteDirectoryId));
+    for (long directoryId : directoryIds) {
+      cp2InfoFutures.add(queryCp2ForDirectoryContact(number, directoryId));
     }
 
     return Futures.transform(
@@ -132,8 +137,7 @@
         lightweightExecutorService);
   }
 
-  private ListenableFuture<Cp2Info> queryCp2ForRemoteContact(
-      String number, long remoteDirectoryId) {
+  private ListenableFuture<Cp2Info> queryCp2ForDirectoryContact(String number, long directoryId) {
     return backgroundExecutorService.submit(
         () -> {
           Cp2Info.Builder cp2InfoBuilder = Cp2Info.newBuilder();
@@ -141,24 +145,24 @@
               appContext
                   .getContentResolver()
                   .query(
-                      getContentUriForContacts(number, remoteDirectoryId),
+                      getContentUriForContacts(number, directoryId),
                       Cp2Projections.getProjectionForPhoneLookupTable(),
                       /* selection = */ null,
                       /* selectionArgs = */ null,
                       /* sortOrder = */ null)) {
             if (cursor == null) {
               LogUtil.e(
-                  "Cp2RemotePhoneLookup.queryCp2ForRemoteContact",
+                  "Cp2ExtendedDirectoryPhoneLookup.queryCp2ForDirectoryContact",
                   "null cursor returned when querying directory %d",
-                  remoteDirectoryId);
+                  directoryId);
               return cp2InfoBuilder.build();
             }
 
             if (!cursor.moveToFirst()) {
               LogUtil.i(
-                  "Cp2RemotePhoneLookup.queryCp2ForRemoteContact",
+                  "Cp2ExtendedDirectoryPhoneLookup.queryCp2ForDirectoryContact",
                   "empty cursor returned when querying directory %d",
-                  remoteDirectoryId);
+                  directoryId);
               return cp2InfoBuilder.build();
             }
 
@@ -199,14 +203,13 @@
     return builder.build();
   }
 
-  private static boolean isRemoteDirectory(long directoryId) {
+  private static boolean isExtendedDirectory(long directoryId) {
+    // TODO(a bug): Moving the logic to utility shared with the search fragment.
     return VERSION.SDK_INT >= VERSION_CODES.N
         ? Directory.isRemoteDirectoryId(directoryId)
+            || Directory.isEnterpriseDirectoryId(directoryId)
         : (directoryId != Directory.DEFAULT
             && directoryId != Directory.LOCAL_INVISIBLE
-            // Directory.ENTERPRISE_DEFAULT is the default work profile directory for locally stored
-            // contacts
-            && directoryId != Directory.ENTERPRISE_DEFAULT
             && directoryId != Directory.ENTERPRISE_LOCAL_INVISIBLE);
   }
 
@@ -223,12 +226,12 @@
 
   @Override
   public void setSubMessage(PhoneLookupInfo.Builder destination, Cp2Info subMessage) {
-    destination.setCp2RemoteInfo(subMessage);
+    destination.setExtendedCp2Info(subMessage);
   }
 
   @Override
   public Cp2Info getSubMessage(PhoneLookupInfo phoneLookupInfo) {
-    return phoneLookupInfo.getCp2RemoteInfo();
+    return phoneLookupInfo.getExtendedCp2Info();
   }
 
   @Override
@@ -238,6 +241,8 @@
 
   @Override
   public void registerContentObservers(Context appContext) {
-    // No content observer needed for remote contacts
+    // For contacts in remote directories, no content observer can be registered.
+    // For contacts in local (but not default) directories (e.g., the local work directory), we
+    // don't register a content observer for now.
   }
 }
diff --git a/java/com/android/dialer/phonelookup/phone_lookup_info.proto b/java/com/android/dialer/phonelookup/phone_lookup_info.proto
index dd6bf66..44c237b 100644
--- a/java/com/android/dialer/phonelookup/phone_lookup_info.proto
+++ b/java/com/android/dialer/phonelookup/phone_lookup_info.proto
@@ -10,59 +10,58 @@
 // Contains information about a phone number, possibly from many sources.
 //
 // This message is organized into sub-message fields where each one corresponds
-// to an implementation of PhoneLookup. For example, field "cp2_local_info"
-// corresponds to class Cp2LocalPhoneLookup, and class Cp2LocalPhoneLookup
-// alone is responsible for populating it.
-// Next ID: 7
+// to an implementation of PhoneLookup. For example, field
+// "cp2_info_in_default_directory" corresponds to class
+// Cp2DefaultDirectoryPhoneLookup, and class Cp2DefaultDirectoryPhoneLookup
+// alone is responsible for populating it. Next ID: 7
 message PhoneLookupInfo {
   // Information about a PhoneNumber retrieved from CP2.
   message Cp2Info {
-    // Information about a single contact, which can be a local contact or a
-    // remote one.
+    // Information about a single contact.
     // Next ID: 8
     message Cp2ContactInfo {
-      // For a local contact:
+      // For a contact in the default directory:
       //   android.provider.ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME_PRIMARY
-      // For a remote contact:
+      // For a contact in other directories:
       //   android.provider.ContactsContract.PhoneLookup.DISPLAY_NAME_PRIMARY
       optional string name = 1;
 
-      // For a local contact:
+      // For a contact in the default directory:
       //   android.provider.ContactsContract.CommonDataKinds.Phone.PHOTO_THUMBNAIL_URI
-      // For a remote contact:
+      // For a contact in other directories:
       //   android.provider.ContactsContract.PhoneLookup.PHOTO_THUMBNAIL_URI
       optional string photo_thumbnail_uri = 2;
 
-      // For a local contact:
+      // For a contact in the default directory:
       //   android.provider.ContactsContract.CommonDataKinds.Phone.PHOTO_URI
-      // For a remote contact:
+      // For a contact in other directories:
       //   android.provider.ContactsContract.PhoneLookup.PHOTO_URI
       optional string photo_uri = 3;
 
-      // For a local contact:
+      // For a contact in the default directory:
       //   android.provider.ContactsContract.CommonDataKinds.Phone.PHOTO_ID
-      // For a remote contact:
+      // For a contact in other directories:
       //   android.provider.ContactsContract.PhoneLookup.PHOTO_ID
       optional fixed64 photo_id = 4;
 
-      // For a local contact:
+      // For a contact in the default directory:
       //   android.provider.ContactsContract.CommonDataKinds.Phone.LABEL
-      // For a remote contact:
+      // For a contact in other directories:
       //   android.provider.ContactsContract.PhoneLookup.LABEL
       //
       // The value can be "Home", "Mobile", ect.
       optional string label = 5;
 
-      // For a local contact:
+      // For a contact in the default directory:
       //   android.provider.ContactsContract.CommonDataKinds.Phone.CONTACT_ID
-      // For a remote contact:
+      // For a contact in other directories:
       //   android.provider.ContactsContract.PhoneLookup.CONTACT_ID
       optional fixed64 contact_id = 6;
 
-      // For a local contact:
+      // For a contact in the default directory:
       //   constructed based on
       //   android.provider.ContactsContract.CommonDataKinds.Phone.LOOKUP_KEY
-      // For a remote contact:
+      // For a contact in other directories:
       //   constructed based on
       //   android.provider.ContactsContract.PhoneLookup.LOOKUP_KEY
       optional string lookup_uri = 7;
@@ -80,13 +79,13 @@
     optional bool is_incomplete = 2;
   }
 
-  // Information about a local contact retrieved via CP2.
-  // Cp2LocalPhoneLookup is responsible for populating this field.
-  optional Cp2Info cp2_local_info = 1;
+  // Information about a contact in the default directory, retrieved via CP2.
+  // Cp2DefaultDirectoryPhoneLookup is responsible for populating this field.
+  optional Cp2Info default_cp2_info = 1;
 
-  // Information about a remote contact retrieved via CP2.
-  // Cp2RemotePhoneLookup is responsible for populating this field.
-  optional Cp2Info cp2_remote_info = 6;
+  // Information about a contact in other directories, retrieved via CP2.
+  // Cp2ExtendedDirectoryPhoneLookup is responsible for populating this field.
+  optional Cp2Info extended_cp2_info = 6;
 
   // Message for spam info.
   // SpamPhoneLookup is responsible for populating this message.
diff --git a/java/com/android/dialer/searchfragment/directories/DirectoryContactViewHolder.java b/java/com/android/dialer/searchfragment/directories/DirectoryContactViewHolder.java
index ff321fc..fc5bce1 100644
--- a/java/com/android/dialer/searchfragment/directories/DirectoryContactViewHolder.java
+++ b/java/com/android/dialer/searchfragment/directories/DirectoryContactViewHolder.java
@@ -79,6 +79,8 @@
     nameView.setText(QueryBoldingUtil.getNameWithQueryBolded(query, name, context));
     numberView.setText(QueryBoldingUtil.getNameWithQueryBolded(query, secondaryInfo, context));
     workBadge.setVisibility(
+        // TODO(a bug): Consider moving DirectoryCompat out of "contacts/common" and share it
+        // with PhoneLookups.
         DirectoryCompat.isOnlyEnterpriseDirectoryId(cursor.getDirectoryId())
             ? View.VISIBLE
             : View.GONE);
diff --git a/java/com/android/dialer/searchfragment/directories/DirectoryContactsCursor.java b/java/com/android/dialer/searchfragment/directories/DirectoryContactsCursor.java
index bf0bdc0..8f9ab0e 100644
--- a/java/com/android/dialer/searchfragment/directories/DirectoryContactsCursor.java
+++ b/java/com/android/dialer/searchfragment/directories/DirectoryContactsCursor.java
@@ -101,6 +101,8 @@
 
   private static MatrixCursor createHeaderCursor(Context context, String name, long id) {
     MatrixCursor headerCursor = new MatrixCursor(PROJECTION, 1);
+    // TODO(a bug): Consider moving DirectoryCompat out of "contacts/common" and share it
+    // with PhoneLookups.
     if (DirectoryCompat.isOnlyEnterpriseDirectoryId(id)) {
       headerCursor.addRow(
           new Object[] {context.getString(R.string.directory_search_label_work), id});
diff --git a/java/com/android/dialer/searchfragment/directories/DirectoryContactsCursorLoader.java b/java/com/android/dialer/searchfragment/directories/DirectoryContactsCursorLoader.java
index fc36f59..a948785 100644
--- a/java/com/android/dialer/searchfragment/directories/DirectoryContactsCursorLoader.java
+++ b/java/com/android/dialer/searchfragment/directories/DirectoryContactsCursorLoader.java
@@ -71,7 +71,8 @@
     for (int i = 0; i < directories.size(); i++) {
       Directory directory = directories.get(i);
 
-      // Only load contacts in the enterprise directory & remote directories.
+      // TODO(a bug): Consider moving DirectoryCompat out of "contacts/common" and share it
+      // with PhoneLookups.
       if (!DirectoryCompat.isRemoteDirectoryId(directory.getId())
           && !DirectoryCompat.isEnterpriseDirectoryId(directory.getId())) {
         cursors[i] = null;