aboutsummaryrefslogtreecommitdiff
path: root/src/com/android
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android')
-rw-r--r--src/com/android/providers/contacts/ContactsProvider2.java38
-rw-r--r--src/com/android/providers/contacts/util/DbQueryUtils.java27
2 files changed, 62 insertions, 3 deletions
diff --git a/src/com/android/providers/contacts/ContactsProvider2.java b/src/com/android/providers/contacts/ContactsProvider2.java
index 08e26ef6..c9c7f2ff 100644
--- a/src/com/android/providers/contacts/ContactsProvider2.java
+++ b/src/com/android/providers/contacts/ContactsProvider2.java
@@ -513,12 +513,12 @@ public class ContactsProvider2 extends AbstractContactsProvider
*/
private static final String EMAIL_FILTER_SORT_ORDER =
Contacts.STARRED + " DESC, "
+ + Data.IS_SUPER_PRIMARY + " DESC, "
+ + Data.IS_PRIMARY + " DESC, "
+ SORT_BY_DATA_USAGE + ", "
+ Contacts.IN_VISIBLE_GROUP + " DESC, "
+ Contacts.DISPLAY_NAME + ", "
- + Data.CONTACT_ID + ", "
- + Data.IS_SUPER_PRIMARY + " DESC, "
- + Data.IS_PRIMARY + " DESC";
+ + Data.CONTACT_ID;
/** Currently same as {@link #EMAIL_FILTER_SORT_ORDER} */
private static final String PHONE_FILTER_SORT_ORDER = EMAIL_FILTER_SORT_ORDER;
@@ -5648,6 +5648,26 @@ public class ContactsProvider2 extends AbstractContactsProvider
} else {
sortOrder = EMAIL_FILTER_SORT_ORDER;
}
+
+ final String primaryAccountName =
+ uri.getQueryParameter(ContactsContract.PRIMARY_ACCOUNT_NAME);
+ if (!TextUtils.isEmpty(primaryAccountName)) {
+ final int index = primaryAccountName.indexOf('@');
+ if (index != -1) {
+ // Purposely include '@' in matching.
+ final String domain = primaryAccountName.substring(index);
+ final char escapeChar = '\\';
+
+ final StringBuilder likeValue = new StringBuilder();
+ likeValue.append('%');
+ DbQueryUtils.escapeLikeValue(likeValue, domain, escapeChar);
+ selectionArgs = appendSelectionArg(selectionArgs, likeValue.toString());
+
+ // similar email domains is the last sort preference.
+ sortOrder += ", (CASE WHEN " + Data.DATA1 + " like ? ESCAPE '" +
+ escapeChar + "' THEN 0 ELSE 1 END)";
+ }
+ }
}
break;
}
@@ -7860,6 +7880,18 @@ public class ContactsProvider2 extends AbstractContactsProvider
}
}
+ private String[] appendSelectionArg(String[] selectionArgs, String arg) {
+ if (selectionArgs == null) {
+ return new String[]{arg};
+ } else {
+ int newLength = selectionArgs.length + 1;
+ String[] newSelectionArgs = new String[newLength];
+ newSelectionArgs[newLength] = arg;
+ System.arraycopy(selectionArgs, 0, newSelectionArgs, 0, selectionArgs.length - 1);
+ return newSelectionArgs;
+ }
+ }
+
protected Account getDefaultAccount() {
AccountManager accountManager = AccountManager.get(getContext());
try {
diff --git a/src/com/android/providers/contacts/util/DbQueryUtils.java b/src/com/android/providers/contacts/util/DbQueryUtils.java
index c853a961..c184613f 100644
--- a/src/com/android/providers/contacts/util/DbQueryUtils.java
+++ b/src/com/android/providers/contacts/util/DbQueryUtils.java
@@ -94,4 +94,31 @@ public class DbQueryUtils {
}
}
}
+
+ /**
+ * Escape values to be used in LIKE sqlite clause.
+ *
+ * The LIKE clause has two special characters: '%' and '_'. If either of these
+ * characters need to be matched literally, then they must be escaped like so:
+ *
+ * WHERE value LIKE 'android\_%' ESCAPE '\'
+ *
+ * The ESCAPE clause is required and no default exists as the escape character in this context.
+ * Since the escape character needs to be defined as part of the sql string, it must be
+ * provided to this method so the escape characters match.
+ *
+ * @param sb The StringBuilder to append the escaped value to.
+ * @param value The value to be escaped.
+ * @param escapeChar The escape character to be defined in the sql ESCAPE clause.
+ */
+ public static void escapeLikeValue(StringBuilder sb, String value, char escapeChar) {
+ for (int i = 0; i < value.length(); i++) {
+ char ch = value.charAt(i);
+ if (ch == '%' || ch == '_') {
+ sb.append(escapeChar);
+ }
+ sb.append(ch);
+ }
+ }
+
}