diff options
| author | Dmitri Plotnikov <dplotnikov@google.com> | 2009-08-20 08:13:46 -0700 |
|---|---|---|
| committer | Dmitri Plotnikov <dplotnikov@google.com> | 2009-08-20 08:14:24 -0700 |
| commit | 1c1629da30bd1b125c59ab9bbcecff3bb3e74324 (patch) | |
| tree | a11288d98ba2cc8f4a12b11fba6d3ee99aeee121 | |
| parent | 41b379da57d3125de038636d72fba95e2255483d (diff) | |
| download | frameworks_base-1c1629da30bd1b125c59ab9bbcecff3bb3e74324.zip frameworks_base-1c1629da30bd1b125c59ab9bbcecff3bb3e74324.tar.gz frameworks_base-1c1629da30bd1b125c59ab9bbcecff3bb3e74324.tar.bz2 | |
Protecting access to the new Contacts API with a try/catch block.
| -rw-r--r-- | core/java/android/provider/ContactsContract.java | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/core/java/android/provider/ContactsContract.java b/core/java/android/provider/ContactsContract.java index 5932040..18b666c 100644 --- a/core/java/android/provider/ContactsContract.java +++ b/core/java/android/provider/ContactsContract.java @@ -312,23 +312,30 @@ public final class ContactsContract { * @param contactUri the contact whose photo should be used */ public static Uri getPhotoUri(ContentResolver cr, Uri contactUri) { - long photoId = -1; - Cursor cursor = cr.query(contactUri, new String[]{Contacts.PHOTO_ID}, null, null, null); + + // TODO remove try/catch block as soon as eclair-dev is merged in eclair try { - if (!cursor.moveToNext()) { - return null; - } + long photoId = -1; + Cursor cursor = cr.query(contactUri, new String[] {Contacts.PHOTO_ID}, + null, null, null); + try { + if (!cursor.moveToNext()) { + return null; + } - if (cursor.isNull(0)) { - return null; + if (cursor.isNull(0)) { + return null; + } + + photoId = cursor.getLong(0); + } finally { + cursor.close(); } - photoId = cursor.getLong(0); - } finally { - cursor.close(); + return ContentUris.withAppendedId(ContactsContract.Data.CONTENT_URI, photoId); + } catch (Exception e) { + return null; } - - return ContentUris.withAppendedId(ContactsContract.Data.CONTENT_URI, photoId); } /** @@ -339,6 +346,9 @@ public final class ContactsContract { */ public static InputStream openContactPhotoInputStream(ContentResolver cr, Uri contactUri) { Uri photoUri = getPhotoUri(cr, contactUri); + if (photoUri == null) { + return null; + } Cursor cursor = cr.query(photoUri, new String[]{ContactsContract.CommonDataKinds.Photo.PHOTO}, null, null, null); try { |
