diff options
| author | Jay Shrauner <shrauner@google.com> | 2014-11-25 15:00:28 -0800 |
|---|---|---|
| committer | Natiq Ahmed <mnatiq@codeaurora.org> | 2015-03-13 14:00:03 +0530 |
| commit | 670a786dba56f386ea45c6bae9678f25b8d4d07b (patch) | |
| tree | a4f98b7fba5a4fceeab78d0795adb571caf64e24 | |
| parent | 53965e477b2477f8b4a1729c7f7e6567942ad710 (diff) | |
| download | packages_apps_ContactsCommon-670a786dba56f386ea45c6bae9678f25b8d4d07b.tar.gz packages_apps_ContactsCommon-670a786dba56f386ea45c6bae9678f25b8d4d07b.tar.bz2 packages_apps_ContactsCommon-670a786dba56f386ea45c6bae9678f25b8d4d07b.zip | |
Fix cursor exception in getThumbnailSize
Check for null cursor and check return value of moveToFirst before reading.
Bug:18527155
Change-Id: Id2fc5ff8e22c59968443a1e66d59f24480f045b2
| -rw-r--r-- | src/com/android/contacts/common/ContactsUtils.java | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/src/com/android/contacts/common/ContactsUtils.java b/src/com/android/contacts/common/ContactsUtils.java index 857450d9..a6e0e0e8 100644 --- a/src/com/android/contacts/common/ContactsUtils.java +++ b/src/com/android/contacts/common/ContactsUtils.java @@ -41,6 +41,8 @@ public class ContactsUtils { public static final String SCHEME_MAILTO = "mailto"; public static final String SCHEME_SMSTO = "smsto"; + private static final int DEFAULT_THUMBNAIL_SIZE = 96; + private static int sThumbnailSize = -1; // TODO find a proper place for the canonical version of these @@ -139,14 +141,17 @@ public class ContactsUtils { final Cursor c = context.getContentResolver().query( DisplayPhoto.CONTENT_MAX_DIMENSIONS_URI, new String[] { DisplayPhoto.THUMBNAIL_MAX_DIM }, null, null, null); - try { - c.moveToFirst(); - sThumbnailSize = c.getInt(0); - } finally { - c.close(); + if (c != null) { + try { + if (c.moveToFirst()) { + sThumbnailSize = c.getInt(0); + } + } finally { + c.close(); + } } } - return sThumbnailSize; + return sThumbnailSize != -1 ? sThumbnailSize : DEFAULT_THUMBNAIL_SIZE; } private static Intent getCustomImIntent(ImDataItem im, int protocol) { |
