summaryrefslogtreecommitdiffstats
path: root/src/com/android/providers/contacts/ContactsProvider2.java
diff options
context:
space:
mode:
authorMakoto Onuki <omakoto@google.com>2015-02-27 12:25:27 -0800
committerMakoto Onuki <omakoto@google.com>2015-02-27 15:31:53 -0800
commit2eb09524fc4b4afd061d30898dba30fab583545a (patch)
tree3a595b983096ee0e73a2f5997d56685b4a6217cc /src/com/android/providers/contacts/ContactsProvider2.java
parent3e2e34d46cca69ba09715b7d2e4c165d84d19ee5 (diff)
downloadpackages_providers_ContactsProvider-2eb09524fc4b4afd061d30898dba30fab583545a.zip
packages_providers_ContactsProvider-2eb09524fc4b4afd061d30898dba30fab583545a.tar.gz
packages_providers_ContactsProvider-2eb09524fc4b4afd061d30898dba30fab583545a.tar.bz2
Enterprise phone lookup should return consistent result...
regardless of requested projections. In order to rewrite the cursor returned from the corp CP2, certain columns are needed to compute other columns. (e.g. PHOTO_URI requires _ID and PHOTO_FILE_ID). This CL fixes that by always requesting all columns to the corp CP2. Now rewriteCorpPhoneLookup() shrinks down the projection. Bug 19545750 Change-Id: Id817d069554ebc89759303760effb557b152d58a
Diffstat (limited to 'src/com/android/providers/contacts/ContactsProvider2.java')
-rw-r--r--src/com/android/providers/contacts/ContactsProvider2.java31
1 files changed, 18 insertions, 13 deletions
diff --git a/src/com/android/providers/contacts/ContactsProvider2.java b/src/com/android/providers/contacts/ContactsProvider2.java
index e853833..130134b 100644
--- a/src/com/android/providers/contacts/ContactsProvider2.java
+++ b/src/com/android/providers/contacts/ContactsProvider2.java
@@ -6530,14 +6530,16 @@ public class ContactsProvider2 extends AbstractContactsProvider
if (VERBOSE_LOGGING) {
Log.v(TAG, "queryPhoneLookupEnterprise: corp query URI=" + remoteUri);
}
- final Cursor corp = getContext().getContentResolver().query(remoteUri, projection,
+ // Note in order to re-write the cursor correctly, we need all columns from the corp cp2.
+ final Cursor corp = getContext().getContentResolver().query(remoteUri, null,
/* selection */ null, /* args */ null, /* order */ null,
/* cancellationsignal*/ null);
try {
if (VERBOSE_LOGGING) {
MoreDatabaseUtils.dumpCursor(TAG, "corp raw", corp);
}
- final Cursor rewritten = rewriteCorpPhoneLookup(corp);
+ final Cursor rewritten = rewriteCorpPhoneLookup(
+ (projection != null ? projection : corp.getColumnNames()), corp);
if (VERBOSE_LOGGING) {
MoreDatabaseUtils.dumpCursor(TAG, "corp rewritten", rewritten);
}
@@ -6552,18 +6554,20 @@ public class ContactsProvider2 extends AbstractContactsProvider
* Rewrite a cursor from the corp profile for {@link PhoneLookup#ENTERPRISE_CONTENT_FILTER_URI}.
*/
@VisibleForTesting
- static Cursor rewriteCorpPhoneLookup(Cursor original) {
- final String[] columns = original.getColumnNames();
- final MatrixCursor ret = new MatrixCursor(columns);
+ static Cursor rewriteCorpPhoneLookup(String[] outputProjection, Cursor original) {
+ final MatrixCursor ret = new MatrixCursor(outputProjection);
original.moveToPosition(-1);
while (original.moveToNext()) {
+ // Note PhoneLookup._ID is a contact ID, not a data ID.
final int contactId = original.getInt(original.getColumnIndex(PhoneLookup._ID));
final MatrixCursor.RowBuilder builder = ret.newRow();
- for (int i = 0; i < columns.length; i++) {
- switch (columns[i]) {
+ for (int i = 0; i < outputProjection.length; i++) {
+ final String outputColumnName = outputProjection[i];
+ final int originalColumnIndex = original.getColumnIndex(outputColumnName);
+ switch (outputColumnName) {
// Set artificial photo URLs using Contacts.CORP_CONTENT_URI.
case PhoneLookup.PHOTO_THUMBNAIL_URI:
builder.add(getCorpThumbnailUri(contactId, original));
@@ -6572,7 +6576,8 @@ public class ContactsProvider2 extends AbstractContactsProvider
builder.add(getCorpDisplayPhotoUri(contactId, original));
break;
case PhoneLookup._ID:
- builder.add(original.getLong(i) + Contacts.ENTERPRISE_CONTACT_ID_BASE);
+ builder.add(original.getLong(originalColumnIndex)
+ + Contacts.ENTERPRISE_CONTACT_ID_BASE);
break;
// These columns are set to null.
@@ -6584,21 +6589,21 @@ public class ContactsProvider2 extends AbstractContactsProvider
break;
default:
// Copy the original value.
- switch (original.getType(i)) {
+ switch (original.getType(originalColumnIndex)) {
case Cursor.FIELD_TYPE_NULL:
builder.add(null);
break;
case Cursor.FIELD_TYPE_INTEGER:
- builder.add(original.getLong(i));
+ builder.add(original.getLong(originalColumnIndex));
break;
case Cursor.FIELD_TYPE_FLOAT:
- builder.add(original.getFloat(i));
+ builder.add(original.getFloat(originalColumnIndex));
break;
case Cursor.FIELD_TYPE_STRING:
- builder.add(original.getString(i));
+ builder.add(original.getString(originalColumnIndex));
break;
case Cursor.FIELD_TYPE_BLOB:
- builder.add(original.getBlob(i));
+ builder.add(original.getBlob(originalColumnIndex));
break;
}
}