From 0e24cb7fb5b2b1941d8340cbe577dbfcb624ccdb Mon Sep 17 00:00:00 2001 From: Marco Nelissen Date: Tue, 17 Feb 2015 14:31:33 -0800 Subject: Fix NPE Path can be null if sd card was ejected, and we shouldn't make a thumbnail in that case. Bug: 19380821 Change-Id: Iee69effdd321622de026ad7b57c74cf9da81a176 --- core/java/android/provider/MediaStore.java | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'core') diff --git a/core/java/android/provider/MediaStore.java b/core/java/android/provider/MediaStore.java index 736ec54..5afbd6d 100644 --- a/core/java/android/provider/MediaStore.java +++ b/core/java/android/provider/MediaStore.java @@ -638,7 +638,6 @@ public final class MediaStore { static Bitmap getThumbnail(ContentResolver cr, long origId, long groupId, int kind, BitmapFactory.Options options, Uri baseUri, boolean isVideo) { Bitmap bitmap = null; - String filePath = null; // Log.v(TAG, "getThumbnail: origId="+origId+", kind="+kind+", isVideo="+isVideo); // If the magic is non-zero, we simply return thumbnail if it does exist. // querying MediaProvider and simply return thumbnail. @@ -710,18 +709,18 @@ public final class MediaStore { Uri uri = Uri.parse( baseUri.buildUpon().appendPath(String.valueOf(origId)) .toString().replaceFirst("thumbnails", "media")); - if (filePath == null) { - if (c != null) c.close(); - c = cr.query(uri, PROJECTION, null, null, null); - if (c == null || !c.moveToFirst()) { - return null; - } - filePath = c.getString(1); + if (c != null) c.close(); + c = cr.query(uri, PROJECTION, null, null, null); + if (c == null || !c.moveToFirst()) { + return null; } - if (isVideo) { - bitmap = ThumbnailUtils.createVideoThumbnail(filePath, kind); - } else { - bitmap = ThumbnailUtils.createImageThumbnail(filePath, kind); + String filePath = c.getString(1); + if (filePath != null) { + if (isVideo) { + bitmap = ThumbnailUtils.createVideoThumbnail(filePath, kind); + } else { + bitmap = ThumbnailUtils.createImageThumbnail(filePath, kind); + } } } } catch (SQLiteException ex) { -- cgit v1.1