diff options
author | Bobby Georgescu <georgescu@google.com> | 2013-04-01 13:48:29 -0700 |
---|---|---|
committer | Bobby Georgescu <georgescu@google.com> | 2013-04-01 14:38:05 -0700 |
commit | 6058af443b087ba50741cc3e61ec70e830e498fa (patch) | |
tree | ed4348b5311a2313f7a87f34be54988a04388806 /src/com/android/gallery3d/ingest/data | |
parent | bb746823c1b966562ed4f0f170289cd133f6ff6c (diff) | |
download | android_packages_apps_Gallery2-6058af443b087ba50741cc3e61ec70e830e498fa.tar.gz android_packages_apps_Gallery2-6058af443b087ba50741cc3e61ec70e830e498fa.tar.bz2 android_packages_apps_Gallery2-6058af443b087ba50741cc3e61ec70e830e498fa.zip |
Enforce bmp type in pool, handle MTP image decode failure
- GalleryBitmapPool didn't reject bitmap types other than
ARGB_8888 which could lead to problems when a different type
is used for recycling.
- BitmapFactory throws an exception rather than returning null
when image decoding fails and an existing bitmap was supplied
for recycling, even if the failure was not caused by the use
of that bitmap. When decoding things from an MTP device, we
need to handle this since unsupported formats may be returned.
Change-Id: I8cc8aa46f5a741b360e806814991f74a131e9039
Diffstat (limited to 'src/com/android/gallery3d/ingest/data')
-rw-r--r-- | src/com/android/gallery3d/ingest/data/MtpBitmapFetch.java | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/src/com/android/gallery3d/ingest/data/MtpBitmapFetch.java b/src/com/android/gallery3d/ingest/data/MtpBitmapFetch.java index 5e1fb34fd..30868c22b 100644 --- a/src/com/android/gallery3d/ingest/data/MtpBitmapFetch.java +++ b/src/com/android/gallery3d/ingest/data/MtpBitmapFetch.java @@ -38,16 +38,28 @@ public class MtpBitmapFetch { public static Bitmap getThumbnail(MtpDevice device, MtpObjectInfo info) { byte[] imageBytes = device.getThumbnail(info.getObjectHandle()); - if (imageBytes == null) return null; + if (imageBytes == null) { + return null; + } BitmapFactory.Options o = new BitmapFactory.Options(); o.inJustDecodeBounds = true; BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.length, o); - if (o.outWidth == 0 || o.outHeight == 0) return null; + if (o.outWidth == 0 || o.outHeight == 0) { + return null; + } o.inBitmap = GalleryBitmapPool.getInstance().get(o.outWidth, o.outHeight); o.inMutable = true; o.inJustDecodeBounds = false; o.inSampleSize = 1; - return BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.length, o); + try { + return BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.length, o); + } catch (IllegalArgumentException e) { + // BitmapFactory throws an exception rather than returning null + // when image decoding fails and an existing bitmap was supplied + // for recycling, even if the failure was not caused by the use + // of that bitmap. + return BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.length); + } } public static BitmapWithMetadata getFullsize(MtpDevice device, MtpObjectInfo info) { @@ -56,7 +68,9 @@ public class MtpBitmapFetch { public static BitmapWithMetadata getFullsize(MtpDevice device, MtpObjectInfo info, int maxSide) { byte[] imageBytes = device.getObject(info.getObjectHandle(), info.getCompressedSize()); - if (imageBytes == null) return null; + if (imageBytes == null) { + return null; + } Bitmap created; if (maxSide > 0) { BitmapFactory.Options o = new BitmapFactory.Options(); @@ -76,7 +90,9 @@ public class MtpBitmapFetch { } else { created = BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.length); } - if (created == null) return null; + if (created == null) { + return null; + } return new BitmapWithMetadata(created, Exif.getOrientation(imageBytes)); } |