diff options
author | Jeff Sharkey <jsharkey@android.com> | 2009-09-27 17:11:49 -0700 |
---|---|---|
committer | Jeff Sharkey <jsharkey@android.com> | 2009-09-28 17:46:18 -0700 |
commit | f9aeb84d61c01a473819e9173f8311ca5d678a8d (patch) | |
tree | 9923d4b9b20f328f44a64059f2dd3ee1c36b9364 /src | |
parent | 0a185cdcb65d1beb2a295fffbe2ae11a6a2c097f (diff) | |
download | ContactsProvider-f9aeb84d61c01a473819e9173f8311ca5d678a8d.tar.gz |
Use separate API for vCards through openAssetFile().
This change fixes http://b/2138790 by providing a separate
Uri when providing vCard-formatted Contacts.
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/providers/contacts/ContactsProvider2.java | 27 | ||||
-rw-r--r-- | src/com/android/providers/contacts/OpenHelper.java | 4 |
2 files changed, 25 insertions, 6 deletions
diff --git a/src/com/android/providers/contacts/ContactsProvider2.java b/src/com/android/providers/contacts/ContactsProvider2.java index 0f34e5cd..953fa9d6 100644 --- a/src/com/android/providers/contacts/ContactsProvider2.java +++ b/src/com/android/providers/contacts/ContactsProvider2.java @@ -159,6 +159,7 @@ public class ContactsProvider2 extends SQLiteContentProvider implements OnAccoun private static final int CONTACTS_STREQUENT_FILTER = 1007; private static final int CONTACTS_GROUP = 1008; private static final int CONTACTS_PHOTO = 1009; + private static final int CONTACTS_AS_VCARD = 1010; private static final int RAW_CONTACTS = 2002; private static final int RAW_CONTACTS_ID = 2003; @@ -340,6 +341,8 @@ public class ContactsProvider2 extends SQLiteContentProvider implements OnAccoun private static final HashMap<String, String> sCountProjectionMap; /** Contains just the contacts columns */ private static final HashMap<String, String> sContactsProjectionMap; + /** Contains just the contacts vCard columns */ + private static final HashMap<String, String> sContactsVCardProjectionMap; /** Contains just the raw contacts columns */ private static final HashMap<String, String> sRawContactsProjectionMap; /** Contains columns from the data view */ @@ -395,6 +398,7 @@ public class ContactsProvider2 extends SQLiteContentProvider implements OnAccoun matcher.addURI(ContactsContract.AUTHORITY, "contacts/filter/*", CONTACTS_FILTER); matcher.addURI(ContactsContract.AUTHORITY, "contacts/lookup/*", CONTACTS_LOOKUP); matcher.addURI(ContactsContract.AUTHORITY, "contacts/lookup/*/#", CONTACTS_LOOKUP_ID); + matcher.addURI(ContactsContract.AUTHORITY, "contacts/as_vcard/*", CONTACTS_AS_VCARD); matcher.addURI(ContactsContract.AUTHORITY, "contacts/strequent/", CONTACTS_STREQUENT); matcher.addURI(ContactsContract.AUTHORITY, "contacts/strequent/filter/*", CONTACTS_STREQUENT_FILTER); @@ -470,9 +474,11 @@ public class ContactsProvider2 extends SQLiteContentProvider implements OnAccoun sContactsProjectionMap.put(Contacts.HAS_PHONE_NUMBER, Contacts.HAS_PHONE_NUMBER); sContactsProjectionMap.put(Contacts.SEND_TO_VOICEMAIL, Contacts.SEND_TO_VOICEMAIL); sContactsProjectionMap.put(Contacts.LOOKUP_KEY, Contacts.LOOKUP_KEY); - sContactsProjectionMap.put(OpenableColumns.DISPLAY_NAME, Contacts.DISPLAY_NAME + + sContactsVCardProjectionMap = Maps.newHashMap(); + sContactsVCardProjectionMap.put(OpenableColumns.DISPLAY_NAME, Contacts.DISPLAY_NAME + " || '.vcf' AS " + OpenableColumns.DISPLAY_NAME); - sContactsProjectionMap.put(OpenableColumns.SIZE, "0 AS " + OpenableColumns.SIZE); + sContactsVCardProjectionMap.put(OpenableColumns.SIZE, "0 AS " + OpenableColumns.SIZE); sContactsProjectionMap.put(Contacts.CONTACT_PRESENCE, Tables.AGGREGATED_PRESENCE + "." + StatusUpdates.PRESENCE + " AS " + Contacts.CONTACT_PRESENCE); @@ -3178,6 +3184,15 @@ public class ContactsProvider2 extends SQLiteContentProvider implements OnAccoun break; } + case CONTACTS_AS_VCARD: { + // When reading as vCard always use restricted view + final String lookupKey = uri.getPathSegments().get(2); + qb.setTables(mOpenHelper.getRestrictedContactView()); + qb.setProjectionMap(sContactsVCardProjectionMap); + qb.appendWhere(Contacts._ID + "=" + lookupContactIdByLookupKey(db, lookupKey)); + break; + } + case CONTACTS_FILTER: { setTablesAndProjectionMapForContacts(qb, projection); if (uri.getPathSegments().size() > 2) { @@ -3941,9 +3956,7 @@ public class ContactsProvider2 extends SQLiteContentProvider implements OnAccoun return SQLiteContentHelper.getBlobColumnAsAssetFile(db, sql, null); } - case CONTACTS_LOOKUP: - case CONTACTS_LOOKUP_ID: { - // TODO: optimize lookup when direct id provided + case CONTACTS_AS_VCARD: { final String lookupKey = uri.getPathSegments().get(2); final long contactId = lookupContactIdByLookupKey(mDb, lookupKey); final String selection = RawContacts.CONTACT_ID + "=" + contactId; @@ -3998,7 +4011,7 @@ public class ContactsProvider2 extends SQLiteContentProvider implements OnAccoun final VCardComposer composer = new VCardComposer(context, VCARD_TYPE_DEFAULT, false); composer.addHandler(composer.new HandlerForOutputStream(stream)); - // TODO: enforce the callers security clause is used + // No extra checks since composer always uses restricted views if (!composer.init(selection, selectionArgs)) return; @@ -4418,6 +4431,8 @@ public class ContactsProvider2 extends SQLiteContentProvider implements OnAccoun case CONTACTS_ID: case CONTACTS_LOOKUP_ID: return Contacts.CONTENT_ITEM_TYPE; + case CONTACTS_AS_VCARD: + return Contacts.CONTENT_VCARD_TYPE; case RAW_CONTACTS: return RawContacts.CONTENT_TYPE; case RAW_CONTACTS_ID: diff --git a/src/com/android/providers/contacts/OpenHelper.java b/src/com/android/providers/contacts/OpenHelper.java index 99b66c13..f78733fc 100644 --- a/src/com/android/providers/contacts/OpenHelper.java +++ b/src/com/android/providers/contacts/OpenHelper.java @@ -1668,6 +1668,10 @@ import java.util.HashMap; return hasRestrictedAccess() ? Views.CONTACTS_ALL : Views.CONTACTS_RESTRICTED; } + public String getRestrictedContactView() { + return Views.CONTACTS_RESTRICTED; + } + public String getGroupView() { return Views.GROUPS_ALL; } |