summaryrefslogtreecommitdiff
path: root/java/com/android/dialer/common
diff options
context:
space:
mode:
authortwyen <twyen@google.com>2018-01-05 11:52:45 -0800
committerEric Erfanian <erfanian@google.com>2018-01-05 11:57:00 -0800
commitfb112d870c3a564d2dcb0e72dcdcabb6e0375520 (patch)
treedbda20e83cb3458fefec613b56d4b9d0a4814e66 /java/com/android/dialer/common
parent417be6a9e3482472cce238e0a51b6367b86aba1f (diff)
Implement dialer blocked number phone lookup
This CL implements looking up the dialer internal database for blocked numbers when the system database is not available yet. Data is only invalidated when dialer is alive since that is the only time blocked numbers can be set and removed. Bug: 70989538,70989547 Test: DialerBlockedNumberPhoneLookupTest PiperOrigin-RevId: 180956355 Change-Id: Ie7acf091bf58a074d0a1ee39613fad035d2e6e60
Diffstat (limited to 'java/com/android/dialer/common')
-rw-r--r--java/com/android/dialer/common/database/Selection.java28
1 files changed, 24 insertions, 4 deletions
diff --git a/java/com/android/dialer/common/database/Selection.java b/java/com/android/dialer/common/database/Selection.java
index b61472d2f..e449fd9f6 100644
--- a/java/com/android/dialer/common/database/Selection.java
+++ b/java/com/android/dialer/common/database/Selection.java
@@ -18,8 +18,11 @@ package com.android.dialer.common.database;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
+import android.text.TextUtils;
import com.android.dialer.common.Assert;
import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
import java.util.Collections;
import java.util.List;
@@ -106,7 +109,14 @@ public final class Selection {
* enclosed in a parenthesis.
*/
@NonNull
+ @SuppressWarnings("rawtypes")
public static Selection fromString(@Nullable String selection, @Nullable String... args) {
+ return new Builder(selection, args == null ? Collections.emptyList() : Arrays.asList(args))
+ .build();
+ }
+
+ @NonNull
+ public static Selection fromString(@Nullable String selection, Collection<String> args) {
return new Builder(selection, args).build();
}
@@ -149,6 +159,16 @@ public final class Selection {
public Selection is(@NonNull String condition) {
return fromString(column + " " + Assert.isNotNull(condition));
}
+
+ public Selection in(String... values) {
+ return in(values == null ? Collections.emptyList() : Arrays.asList(values));
+ }
+
+ public Selection in(Collection<String> values) {
+ return fromString(
+ column + " IN (" + TextUtils.join(",", Collections.nCopies(values.size(), "?")) + ")",
+ values);
+ }
}
/** Builder for {@link Selection} */
@@ -159,14 +179,14 @@ public final class Selection {
private Builder() {}
- private Builder(@Nullable String selection, @Nullable String... args) {
+ private Builder(@Nullable String selection, Collection<String> args) {
if (selection == null) {
return;
}
checkArgsCount(selection, args);
this.selection.append(parenthesized(selection));
if (args != null) {
- Collections.addAll(selectionArgs, args);
+ selectionArgs.addAll(args);
}
}
@@ -213,14 +233,14 @@ public final class Selection {
return this;
}
- private static void checkArgsCount(@NonNull String selection, @Nullable String... args) {
+ private static void checkArgsCount(@NonNull String selection, Collection<String> args) {
int argsInSelection = 0;
for (int i = 0; i < selection.length(); i++) {
if (selection.charAt(i) == '?') {
argsInSelection++;
}
}
- Assert.checkArgument(argsInSelection == (args == null ? 0 : args.length));
+ Assert.checkArgument(argsInSelection == (args == null ? 0 : args.size()));
}
}