From fb112d870c3a564d2dcb0e72dcdcabb6e0375520 Mon Sep 17 00:00:00 2001 From: twyen Date: Fri, 5 Jan 2018 11:52:45 -0800 Subject: 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 --- .../android/dialer/common/database/Selection.java | 28 ++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) (limited to 'java/com/android/dialer/common') 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 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 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 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 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())); } } -- cgit v1.2.3