Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b05a2b45 authored by zachh's avatar zachh Committed by Eric Erfanian
Browse files

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
parent 0ca01853
Loading
Loading
Loading
Loading
+30 −6
Original line number Diff line number Diff line
@@ -110,7 +110,9 @@ public final class PhoneLookupDataSource implements CallLogDataSource {
   * <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 @@ public final class PhoneLookupDataSource implements CallLogDataSource {
    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 @@ public final class PhoneLookupDataSource implements CallLogDataSource {
    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 @@ public final class PhoneLookupDataSource implements CallLogDataSource {
                null)) {

      if (cursor == null) {
        LogUtil.e("PhoneLookupDataSource.queryIdAndNumberFromAnnotatedCallLog", "null cursor");
        LogUtil.e(
            "PhoneLookupDataSource.collectIdAndNumberFromAnnotatedCallLogAndPendingInserts",
            "null cursor");
        return ImmutableMap.of();
      }