diff options
author | zachh <zachh@google.com> | 2017-12-19 17:54:37 -0800 |
---|---|---|
committer | Eric Erfanian <erfanian@google.com> | 2017-12-22 08:52:37 -0800 |
commit | b05a2b45c37ebc2f4f9fcb36907177c5211622d4 (patch) | |
tree | 0f0f4870e8eaf1f253b433944ee3626a57270608 | |
parent | 0ca01853cb89666578261f31b58ce80061029a56 (diff) |
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
-rw-r--r-- | java/com/android/dialer/calllog/datasources/phonelookup/PhoneLookupDataSource.java | 36 |
1 files changed, 30 insertions, 6 deletions
diff --git a/java/com/android/dialer/calllog/datasources/phonelookup/PhoneLookupDataSource.java b/java/com/android/dialer/calllog/datasources/phonelookup/PhoneLookupDataSource.java index fbb58312a..042ff30a2 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 @@ 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(); } |