diff options
author | zachh <zachh@google.com> | 2017-12-04 17:53:27 -0800 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2017-12-07 11:00:47 -0800 |
commit | b29f58262aef174c0b51c14c7b764e5ee934c67f (patch) | |
tree | a11bbc9272eaf4e69e0f61b6384c11b43e7b5187 /java/com/android/dialer/phonelookup | |
parent | 47aa39c7ea423722254b5a70b50dc6c1513b9ee5 (diff) |
Added PhoneLookupHistoryRecorder.
When a call is added in InCallUi, it fetches the current PhoneLookupInfo for the call and writes it to PhoneLookupHistory.
Required updating PhoneLookupHistoryContentProvider#update to use "replace" to (presumably) atomically insert when a row is missing.
Bug: 34672501
Test: unit
PiperOrigin-RevId: 177896892
Change-Id: I43f9ded240a81156722be816a9635d586de642a1
Diffstat (limited to 'java/com/android/dialer/phonelookup')
-rw-r--r-- | java/com/android/dialer/phonelookup/cp2/Cp2PhoneLookup.java | 3 | ||||
-rw-r--r-- | java/com/android/dialer/phonelookup/database/PhoneLookupHistoryContentProvider.java | 30 |
2 files changed, 21 insertions, 12 deletions
diff --git a/java/com/android/dialer/phonelookup/cp2/Cp2PhoneLookup.java b/java/com/android/dialer/phonelookup/cp2/Cp2PhoneLookup.java index 307f998ea..cfb8fb7b8 100644 --- a/java/com/android/dialer/phonelookup/cp2/Cp2PhoneLookup.java +++ b/java/com/android/dialer/phonelookup/cp2/Cp2PhoneLookup.java @@ -82,7 +82,8 @@ public final class Cp2PhoneLookup implements PhoneLookup { @Override public ListenableFuture<PhoneLookupInfo> lookup(@NonNull Call call) { - throw new UnsupportedOperationException(); + // TODO(zachh): Implementation. + return MoreExecutors.newDirectExecutorService().submit(PhoneLookupInfo::getDefaultInstance); } @Override diff --git a/java/com/android/dialer/phonelookup/database/PhoneLookupHistoryContentProvider.java b/java/com/android/dialer/phonelookup/database/PhoneLookupHistoryContentProvider.java index 27041e746..e85654e99 100644 --- a/java/com/android/dialer/phonelookup/database/PhoneLookupHistoryContentProvider.java +++ b/java/com/android/dialer/phonelookup/database/PhoneLookupHistoryContentProvider.java @@ -201,6 +201,12 @@ public class PhoneLookupHistoryContentProvider extends ContentProvider { return rows; } + /** + * Note: If the normalized number is included as part of the URI (for example, + * "content://com.android.dialer.phonelookuphistory/PhoneLookupHistory/+123") then the update + * operation will actually be a "replace" operation, inserting a new row if one does not already + * exist. + */ @Override public int update( @NonNull Uri uri, @@ -214,7 +220,13 @@ public class PhoneLookupHistoryContentProvider extends ContentProvider { int match = uriMatcher.match(uri); switch (match) { case PHONE_LOOKUP_HISTORY_TABLE_CODE: - break; + int rows = database.update(PhoneLookupHistory.TABLE, values, selection, selectionArgs); + if (rows == 0) { + LogUtil.w("PhoneLookupHistoryContentProvider.update", "no rows updated"); + return rows; + } + notifyChange(uri); + return rows; case PHONE_LOOKUP_HISTORY_TABLE_ID_CODE: Assert.checkArgument( !values.containsKey(PhoneLookupHistory.NORMALIZED_NUMBER), @@ -222,19 +234,15 @@ public class PhoneLookupHistoryContentProvider extends ContentProvider { Assert.checkArgument(selection == null, "Do not specify selection when updating by ID"); Assert.checkArgument( selectionArgs == null, "Do not specify selection args when updating by ID"); - selection = PhoneLookupHistory.NORMALIZED_NUMBER + "= ?"; - selectionArgs = new String[] {uri.getLastPathSegment()}; - break; + + String normalizedNumber = uri.getLastPathSegment(); + values.put(PhoneLookupHistory.NORMALIZED_NUMBER, normalizedNumber); + database.replace(PhoneLookupHistory.TABLE, null, values); + notifyChange(uri); + return 1; default: throw new IllegalArgumentException("Unknown uri: " + uri); } - int rows = database.update(PhoneLookupHistory.TABLE, values, selection, selectionArgs); - if (rows == 0) { - LogUtil.w("PhoneLookupHistoryContentProvider.update", "no rows updated"); - return rows; - } - notifyChange(uri); - return rows; } private void notifyChange(Uri uri) { |