summaryrefslogtreecommitdiffstats
path: root/src/com/android/providers/contacts/util
diff options
context:
space:
mode:
authorDebashish Chatterjee <debashishc@google.com>2011-06-20 17:03:26 +0100
committerDebashish Chatterjee <debashishc@google.com>2011-06-28 15:04:46 +0100
commitaafbe295d67686870c64c74a59e589d1dfb506fa (patch)
treef413f2484f7cb4e1fe534ee35ba456deb150aad6 /src/com/android/providers/contacts/util
parent836bbd3dc178f94bb674733b8ad57c765fff311a (diff)
downloadpackages_providers_ContactsProvider-aafbe295d67686870c64c74a59e589d1dfb506fa.zip
packages_providers_ContactsProvider-aafbe295d67686870c64c74a59e589d1dfb506fa.tar.gz
packages_providers_ContactsProvider-aafbe295d67686870c64c74a59e589d1dfb506fa.tar.bz2
Introduced query param 'include_voicemails' for call_log uri.
- by default only call entries (i.e. no voicemails) are returned. - if include_voicemails is set to true then also include voicemail records, but only if the caller has full voicemail permission. - voicemail record can only be inserted through call_log provider if include_voicemails is set. Change-Id: I98f6778ace64fa752dc0525c5ce4e5eb83b2e689
Diffstat (limited to 'src/com/android/providers/contacts/util')
-rw-r--r--src/com/android/providers/contacts/util/DbQueryUtils.java11
-rw-r--r--src/com/android/providers/contacts/util/SelectionBuilder.java63
2 files changed, 73 insertions, 1 deletions
diff --git a/src/com/android/providers/contacts/util/DbQueryUtils.java b/src/com/android/providers/contacts/util/DbQueryUtils.java
index 0045c59..58c8bb1 100644
--- a/src/com/android/providers/contacts/util/DbQueryUtils.java
+++ b/src/com/android/providers/contacts/util/DbQueryUtils.java
@@ -31,10 +31,19 @@ public class DbQueryUtils {
/** Returns a WHERE clause asserting equality of a field to a value. */
public static String getEqualityClause(String field, String value) {
+ return getClauseWithOperator(field, "=", value);
+ }
+
+ /** Returns a WHERE clause asserting in-equality of a field to a value. */
+ public static String getInequalityClause(String field, String value) {
+ return getClauseWithOperator(field, "!=", value);
+ }
+
+ private static String getClauseWithOperator(String field, String operator, String value) {
StringBuilder clause = new StringBuilder();
clause.append("(");
clause.append(field);
- clause.append(" = ");
+ clause.append(" ").append(operator).append(" ");
DatabaseUtils.appendEscapedSQLString(clause, value);
clause.append(")");
return clause.toString();
diff --git a/src/com/android/providers/contacts/util/SelectionBuilder.java b/src/com/android/providers/contacts/util/SelectionBuilder.java
new file mode 100644
index 0000000..14499e8
--- /dev/null
+++ b/src/com/android/providers/contacts/util/SelectionBuilder.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+
+package com.android.providers.contacts.util;
+
+import android.text.TextUtils;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Builds a selection clause by concatenating several clauses with AND.
+ */
+public class SelectionBuilder {
+ private static final String[] EMPTY_STRING_ARRAY = new String[0];
+ private final List<String> mWhereClauses;
+
+ /**
+ * @param baseSelection The base selection to start with. This is typically
+ * the user supplied selection arg. Pass null if no base selection is
+ * required.
+ */
+ public SelectionBuilder(String baseSelection) {
+ mWhereClauses = new ArrayList<String>();
+ addClause(baseSelection);
+ }
+
+ /**
+ * Adds a new clause to the selection. Nothing is added if the supplied clause
+ * is null or empty.
+ */
+ public SelectionBuilder addClause(String clause) {
+ if (!TextUtils.isEmpty(clause)) {
+ mWhereClauses.add(clause);
+ }
+ return this;
+ }
+
+ /**
+ * Returns a combined selection clause with AND of all clauses added using
+ * {@link #addClause(String)}. Returns null if no clause has been added or
+ * only null/empty clauses have been added till now.
+ */
+ public String build() {
+ if (mWhereClauses.size() == 0) {
+ return null;
+ }
+ return DbQueryUtils.concatenateClauses(mWhereClauses.toArray(EMPTY_STRING_ARRAY));
+ }
+}