summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Bird <sbird@cyngn.com>2015-10-19 13:50:01 -0700
committerRichard MacGregor <rmacgregor@cyngn.com>2016-04-07 13:34:41 -0700
commit22eeaf50aa43112156d11b665857cc867d21ae63 (patch)
treee99e179859c5aad2e2e15306aec2021504882417
parentb25f3757676188caa76c9851c952eaa1bd048a0d (diff)
downloadpackages_providers_ContactsProvider-22eeaf50aa43112156d11b665857cc867d21ae63.zip
packages_providers_ContactsProvider-22eeaf50aa43112156d11b665857cc867d21ae63.tar.gz
packages_providers_ContactsProvider-22eeaf50aa43112156d11b665857cc867d21ae63.tar.bz2
(1/2) Call Lookup: Update call log handler to query usernames
Change-Id: Ie5b5f035d5c4fc5c35a2b3b0b2233353127c468a
-rw-r--r--src/com/android/providers/contacts/ContactsDatabaseHelper.java13
-rw-r--r--src/com/android/providers/contacts/ContactsProvider2.java49
2 files changed, 45 insertions, 17 deletions
diff --git a/src/com/android/providers/contacts/ContactsDatabaseHelper.java b/src/com/android/providers/contacts/ContactsDatabaseHelper.java
index a60d6cf..31d3764 100644
--- a/src/com/android/providers/contacts/ContactsDatabaseHelper.java
+++ b/src/com/android/providers/contacts/ContactsDatabaseHelper.java
@@ -5253,6 +5253,12 @@ public class ContactsDatabaseHelper extends SQLiteOpenHelper {
qb.appendWhere(sb.toString());
}
+ public void buildDataLookupAndContactQuery(SQLiteQueryBuilder qb, String data) {
+ StringBuilder sb = new StringBuilder();
+ buildDataQuery(sb, data);
+ qb.setTables(sb.toString());
+ }
+
/**
* Phone lookup method that uses the custom SQLite function phone_number_compare_loose
* that serves as a fallback in case the regular lookup does not return any results.
@@ -5329,6 +5335,13 @@ public class ContactsDatabaseHelper extends SQLiteOpenHelper {
sb.append("')) AS lookup, " + Tables.DATA);
}
+ private void buildDataQuery(StringBuilder sb, String lookupData) {
+ // Todo: make more performant
+ sb.append(Tables.RAW_CONTACTS +
+ " JOIN " + Views.DATA + " data_view ON (data_view.raw_contact_id = "
+ + Tables.RAW_CONTACTS + ".contact_id) WHERE data1 = '" + lookupData + "'");
+ }
+
private void appendPhoneLookupSelection(StringBuilder sb, String number, String numberE164) {
sb.append("lookup.data_id=data._id AND data.raw_contact_id=raw_contacts._id");
boolean hasNumberE164 = !TextUtils.isEmpty(numberE164);
diff --git a/src/com/android/providers/contacts/ContactsProvider2.java b/src/com/android/providers/contacts/ContactsProvider2.java
index 3ec15c1..e8c1891 100644
--- a/src/com/android/providers/contacts/ContactsProvider2.java
+++ b/src/com/android/providers/contacts/ContactsProvider2.java
@@ -6382,23 +6382,34 @@ public class ContactsProvider2 extends AbstractContactsProvider
String number =
uri.getPathSegments().size() > 1 ? uri.getLastPathSegment() : "";
- String numberE164 = PhoneNumberUtils.formatNumberToE164(
- number, mDbHelper.get().getCurrentCountryIso());
- String normalizedNumber = PhoneNumberUtils.normalizeNumber(number);
- mDbHelper.get().buildPhoneLookupAndContactQuery(
- qb, normalizedNumber, numberE164);
- qb.setProjectionMap(sPhoneLookupProjectionMap);
-
- // removeNonStarMatchesFromCursor() requires the cursor to contain
- // PhoneLookup.NUMBER. Therefore, if the projection explicitly omits it, extend
- // the projection.
- String[] projectionWithNumber = projection;
- if (projection != null
- && !ArrayUtils.contains(projection,PhoneLookup.NUMBER)) {
- projectionWithNumber = ArrayUtils.appendElement(
- String.class, projection, PhoneLookup.NUMBER);
+
+ boolean isPhoneNumber = isPhoneNumber(number);
+
+ String[] projectionWithNumber;
+ if (isPhoneNumber) {
+ String numberE164 = PhoneNumberUtils.formatNumberToE164(
+ number, mDbHelper.get().getCurrentCountryIso());
+ String normalizedNumber = PhoneNumberUtils.normalizeNumber(number);
+ mDbHelper.get().buildPhoneLookupAndContactQuery(
+ qb, normalizedNumber, numberE164);
+ qb.setProjectionMap(sPhoneLookupProjectionMap);
+
+ // removeNonStarMatchesFromCursor() requires the cursor to contain
+ // PhoneLookup.NUMBER. Therefore, if the projection explicitly omits it, extend
+ // the projection.
+ projectionWithNumber = projection;
+ if (projection != null
+ && !ArrayUtils.contains(projection,PhoneLookup.NUMBER)) {
+ projectionWithNumber = ArrayUtils.appendElement(
+ String.class, projection, PhoneLookup.NUMBER);
+ }
+ } else {
+ mDbHelper.get().buildDataLookupAndContactQuery(qb, number);
+ projectionWithNumber = new String[0];
+ sortOrder = null;
}
+
// Peek at the results of the first query (which attempts to use fully
// normalized and internationalized numbers for comparison). If no results
// were returned, fall back to using the SQLite function
@@ -6410,8 +6421,12 @@ public class ContactsProvider2 extends AbstractContactsProvider
try {
if (cursor.getCount() > 0) {
foundResult = true;
- return PhoneLookupWithStarPrefix
- .removeNonStarMatchesFromCursor(number, cursor);
+ if (isPhoneNumber) {
+ return PhoneLookupWithStarPrefix
+ .removeNonStarMatchesFromCursor(number, cursor);
+ } else {
+ return cursor;
+ }
}
// Use the fall-back lookup method.