From b29f58262aef174c0b51c14c7b764e5ee934c67f Mon Sep 17 00:00:00 2001 From: zachh Date: Mon, 4 Dec 2017 17:53:27 -0800 Subject: 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 --- .../dialer/phonelookup/cp2/Cp2PhoneLookup.java | 3 ++- .../PhoneLookupHistoryContentProvider.java | 30 ++++++++++++++-------- 2 files changed, 21 insertions(+), 12 deletions(-) (limited to 'java/com/android/dialer/phonelookup') 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 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) { -- cgit v1.2.3