summaryrefslogtreecommitdiff
path: root/java/com/android/dialer/calllog/database
diff options
context:
space:
mode:
authorzachh <zachh@google.com>2017-11-14 11:13:46 -0800
committerzachh <zachh@google.com>2017-11-18 07:24:52 +0000
commite8dab7ef42ba99e002db2160c6ccfff72cd5100b (patch)
tree0cec4909e3ca58c6731f6caf27f75d35dbc6bbed /java/com/android/dialer/calllog/database
parent04a21f6195203227fb102dc55b3eb88b89e9c232 (diff)
Added URI for selecting distinct phone numbers from AnnotatedCallLog.
This will be used in the PhoneLookupDataSource. A separate URI is necessary because the content provider APIs do not provide a mechanism for querying using the "distinct" keyword. Bug: 34672501 Test: unit PiperOrigin-RevId: 175706603 Change-Id: Ia455a18d10afb116d26f69e8b0c7493f4f877d0b
Diffstat (limited to 'java/com/android/dialer/calllog/database')
-rw-r--r--java/com/android/dialer/calllog/database/AnnotatedCallLogContentProvider.java45
-rw-r--r--java/com/android/dialer/calllog/database/contract/AnnotatedCallLogContract.java5
2 files changed, 46 insertions, 4 deletions
diff --git a/java/com/android/dialer/calllog/database/AnnotatedCallLogContentProvider.java b/java/com/android/dialer/calllog/database/AnnotatedCallLogContentProvider.java
index 68298e356..825e84f91 100644
--- a/java/com/android/dialer/calllog/database/AnnotatedCallLogContentProvider.java
+++ b/java/com/android/dialer/calllog/database/AnnotatedCallLogContentProvider.java
@@ -38,6 +38,7 @@ import com.android.dialer.calllog.database.contract.AnnotatedCallLogContract.Coa
import com.android.dialer.common.Assert;
import com.android.dialer.common.LogUtil;
import java.util.ArrayList;
+import java.util.Arrays;
/** {@link ContentProvider} for the annotated call log. */
public class AnnotatedCallLogContentProvider extends ContentProvider {
@@ -51,7 +52,8 @@ public class AnnotatedCallLogContentProvider extends ContentProvider {
private static final int ANNOTATED_CALL_LOG_TABLE_CODE = 1;
private static final int ANNOTATED_CALL_LOG_TABLE_ID_CODE = 2;
- private static final int COALESCED_ANNOTATED_CALL_LOG_TABLE_CODE = 3;
+ private static final int ANNOTATED_CALL_LOG_TABLE_DISTINCT_NUMBER_CODE = 3;
+ private static final int COALESCED_ANNOTATED_CALL_LOG_TABLE_CODE = 4;
private static final UriMatcher uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
@@ -64,6 +66,10 @@ public class AnnotatedCallLogContentProvider extends ContentProvider {
ANNOTATED_CALL_LOG_TABLE_ID_CODE);
uriMatcher.addURI(
AnnotatedCallLogContract.AUTHORITY,
+ AnnotatedCallLog.DISTINCT_PHONE_NUMBERS,
+ ANNOTATED_CALL_LOG_TABLE_DISTINCT_NUMBER_CODE);
+ uriMatcher.addURI(
+ AnnotatedCallLogContract.AUTHORITY,
CoalescedAnnotatedCallLog.TABLE,
COALESCED_ANNOTATED_CALL_LOG_TABLE_CODE);
}
@@ -101,8 +107,6 @@ public class AnnotatedCallLogContentProvider extends ContentProvider {
switch (match) {
case ANNOTATED_CALL_LOG_TABLE_ID_CODE:
queryBuilder.appendWhere(AnnotatedCallLog._ID + "=" + ContentUris.parseId(uri));
- // fall through
- case ANNOTATED_CALL_LOG_TABLE_CODE:
Cursor cursor =
queryBuilder.query(db, projection, selection, selectionArgs, null, null, sortOrder);
if (cursor != null) {
@@ -112,6 +116,31 @@ public class AnnotatedCallLogContentProvider extends ContentProvider {
LogUtil.w("AnnotatedCallLogContentProvider.query", "cursor was null");
}
return cursor;
+ case ANNOTATED_CALL_LOG_TABLE_CODE:
+ cursor =
+ queryBuilder.query(db, projection, selection, selectionArgs, null, null, sortOrder);
+ if (cursor != null) {
+ cursor.setNotificationUri(
+ getContext().getContentResolver(), AnnotatedCallLog.CONTENT_URI);
+ } else {
+ LogUtil.w("AnnotatedCallLogContentProvider.query", "cursor was null");
+ }
+ return cursor;
+ case ANNOTATED_CALL_LOG_TABLE_DISTINCT_NUMBER_CODE:
+ Assert.checkArgument(
+ Arrays.equals(projection, new String[] {AnnotatedCallLog.NUMBER}),
+ "only NUMBER supported for projection for distinct phone number query, got: %s",
+ Arrays.toString(projection));
+ queryBuilder.setDistinct(true);
+ cursor =
+ queryBuilder.query(db, projection, selection, selectionArgs, null, null, sortOrder);
+ if (cursor != null) {
+ cursor.setNotificationUri(
+ getContext().getContentResolver(), AnnotatedCallLog.CONTENT_URI);
+ } else {
+ LogUtil.w("AnnotatedCallLogContentProvider.query", "cursor was null");
+ }
+ return cursor;
case COALESCED_ANNOTATED_CALL_LOG_TABLE_CODE:
Assert.checkArgument(
projection == CoalescedAnnotatedCallLog.ALL_COLUMNS,
@@ -170,6 +199,8 @@ public class AnnotatedCallLogContentProvider extends ContentProvider {
values.put(AnnotatedCallLog._ID, idFromUri);
}
break;
+ case ANNOTATED_CALL_LOG_TABLE_DISTINCT_NUMBER_CODE:
+ throw new UnsupportedOperationException();
case COALESCED_ANNOTATED_CALL_LOG_TABLE_CODE:
throw new UnsupportedOperationException("coalesced call log does not support inserting");
default:
@@ -206,6 +237,8 @@ public class AnnotatedCallLogContentProvider extends ContentProvider {
Assert.checkArgument(id != -1, "error parsing id from uri %s", uri);
selection = getSelectionWithId(id);
break;
+ case ANNOTATED_CALL_LOG_TABLE_DISTINCT_NUMBER_CODE:
+ throw new UnsupportedOperationException();
case COALESCED_ANNOTATED_CALL_LOG_TABLE_CODE:
throw new UnsupportedOperationException("coalesced call log does not support deleting");
default:
@@ -244,8 +277,10 @@ public class AnnotatedCallLogContentProvider extends ContentProvider {
selectionArgs == null, "Do not specify selection args when updating by ID");
selection = getSelectionWithId(ContentUris.parseId(uri));
break;
+ case ANNOTATED_CALL_LOG_TABLE_DISTINCT_NUMBER_CODE:
+ throw new UnsupportedOperationException();
case COALESCED_ANNOTATED_CALL_LOG_TABLE_CODE:
- throw new UnsupportedOperationException("coalesced call log does not support updating");
+ throw new UnsupportedOperationException();
default:
throw new IllegalArgumentException("Unknown uri: " + uri);
}
@@ -287,6 +322,8 @@ public class AnnotatedCallLogContentProvider extends ContentProvider {
case ANNOTATED_CALL_LOG_TABLE_ID_CODE:
// These are allowed values, continue.
break;
+ case ANNOTATED_CALL_LOG_TABLE_DISTINCT_NUMBER_CODE:
+ throw new UnsupportedOperationException();
case COALESCED_ANNOTATED_CALL_LOG_TABLE_CODE:
throw new UnsupportedOperationException(
"coalesced call log does not support applyBatch");
diff --git a/java/com/android/dialer/calllog/database/contract/AnnotatedCallLogContract.java b/java/com/android/dialer/calllog/database/contract/AnnotatedCallLogContract.java
index 4f26f0cc9..d3318d125 100644
--- a/java/com/android/dialer/calllog/database/contract/AnnotatedCallLogContract.java
+++ b/java/com/android/dialer/calllog/database/contract/AnnotatedCallLogContract.java
@@ -211,11 +211,16 @@ public class AnnotatedCallLogContract {
public static final class AnnotatedCallLog implements CommonColumns {
public static final String TABLE = "AnnotatedCallLog";
+ public static final String DISTINCT_PHONE_NUMBERS = "DistinctPhoneNumbers";
/** The content URI for this table. */
public static final Uri CONTENT_URI =
Uri.withAppendedPath(AnnotatedCallLogContract.CONTENT_URI, TABLE);
+ /** Content URI for selecting the distinct phone numbers from the AnnotatedCallLog. */
+ public static final Uri DISTINCT_NUMBERS_CONTENT_URI =
+ Uri.withAppendedPath(AnnotatedCallLogContract.CONTENT_URI, DISTINCT_PHONE_NUMBERS);
+
/** The MIME type of a {@link android.content.ContentProvider#getType(Uri)} single entry. */
public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/annotated_call_log";