Include inserted calls for consideration in PhoneLookupDataSource.

If there is a new call with a number that hasn't been seen before, it should be considered the same as numbers that are already part of the call log.

Bug: 34672501
Test: unit
PiperOrigin-RevId: 179628789
Change-Id: I422c24c444958dd8842aa14cf8a8069da5cec2c1
diff --git a/java/com/android/dialer/calllog/datasources/phonelookup/PhoneLookupDataSource.java b/java/com/android/dialer/calllog/datasources/phonelookup/PhoneLookupDataSource.java
index fbb5831..042ff30 100644
--- a/java/com/android/dialer/calllog/datasources/phonelookup/PhoneLookupDataSource.java
+++ b/java/com/android/dialer/calllog/datasources/phonelookup/PhoneLookupDataSource.java
@@ -110,7 +110,9 @@
    * <p>This method uses the following algorithm:
    *
    * <ul>
-   *   <li>Selects the distinct DialerPhoneNumbers from the AnnotatedCallLog
+   *   <li>Finds the phone numbers of interest by taking the union of the distinct
+   *       DialerPhoneNumbers from the AnnotatedCallLog and the pending inserts provided in {@code
+   *       mutations}
    *   <li>Uses them to fetch the current information from PhoneLookupHistory, in order to construct
    *       a map from DialerPhoneNumber to PhoneLookupInfo
    *       <ul>
@@ -137,9 +139,10 @@
     phoneLookupHistoryRowsToUpdate.clear();
     phoneLookupHistoryRowsToDelete.clear();
 
-    // First query information from annotated call log.
+    // First query information from annotated call log (and include pending inserts).
     ListenableFuture<Map<DialerPhoneNumber, Set<Long>>> annotatedCallLogIdsByNumberFuture =
-        backgroundExecutorService.submit(() -> queryIdAndNumberFromAnnotatedCallLog(appContext));
+        backgroundExecutorService.submit(
+            () -> collectIdAndNumberFromAnnotatedCallLogAndPendingInserts(appContext, mutations));
 
     // Use it to create the original info map.
     ListenableFuture<ImmutableMap<DialerPhoneNumber, PhoneLookupInfo>> originalInfoMapFuture =
@@ -317,9 +320,28 @@
     return numbers.build();
   }
 
-  private Map<DialerPhoneNumber, Set<Long>> queryIdAndNumberFromAnnotatedCallLog(
-      Context appContext) {
+  private Map<DialerPhoneNumber, Set<Long>> collectIdAndNumberFromAnnotatedCallLogAndPendingInserts(
+      Context appContext, CallLogMutations mutations) {
     Map<DialerPhoneNumber, Set<Long>> idsByNumber = new ArrayMap<>();
+    // First add any pending inserts to the map.
+    for (Entry<Long, ContentValues> entry : mutations.getInserts().entrySet()) {
+      long id = entry.getKey();
+      ContentValues insertedContentValues = entry.getValue();
+      DialerPhoneNumber dialerPhoneNumber;
+      try {
+        dialerPhoneNumber =
+            DialerPhoneNumber.parseFrom(
+                insertedContentValues.getAsByteArray(AnnotatedCallLog.NUMBER));
+      } catch (InvalidProtocolBufferException e) {
+        throw new IllegalStateException(e);
+      }
+      Set<Long> ids = idsByNumber.get(dialerPhoneNumber);
+      if (ids == null) {
+        ids = new ArraySet<>();
+        idsByNumber.put(dialerPhoneNumber, ids);
+      }
+      ids.add(id);
+    }
 
     try (Cursor cursor =
         appContext
@@ -332,7 +354,9 @@
                 null)) {
 
       if (cursor == null) {
-        LogUtil.e("PhoneLookupDataSource.queryIdAndNumberFromAnnotatedCallLog", "null cursor");
+        LogUtil.e(
+            "PhoneLookupDataSource.collectIdAndNumberFromAnnotatedCallLogAndPendingInserts",
+            "null cursor");
         return ImmutableMap.of();
       }