Loading media/java/android/mtp/MtpDatabase.java +15 −3 Original line number Diff line number Diff line Loading @@ -821,8 +821,10 @@ public class MtpDatabase implements AutoCloseable { ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, byteStream); if (byteStream.size() > MAX_THUMB_SIZE) if (byteStream.size() > MAX_THUMB_SIZE) { Log.w(TAG, "getThumbnailProcess: size=" + byteStream.size()); return null; } byte[] byteArray = byteStream.toByteArray(); Loading Loading @@ -852,7 +854,15 @@ public class MtpDatabase implements AutoCloseable { outLongs[0] = thumbOffsetAndSize != null ? thumbOffsetAndSize[1] : 0; outLongs[1] = exif.getAttributeInt(ExifInterface.TAG_PIXEL_X_DIMENSION, 0); outLongs[2] = exif.getAttributeInt(ExifInterface.TAG_PIXEL_Y_DIMENSION, 0); if (exif.getThumbnailRange() != null) { if ((outLongs[0] == 0) || (outLongs[1] == 0) || (outLongs[2] == 0)) { Log.d(TAG, "getThumbnailInfo: check thumb info:" + thumbOffsetAndSize[0] + "," + thumbOffsetAndSize[1] + "," + outLongs[1] + "," + outLongs[2]); } return true; } } catch (IOException e) { // ignore and fall through } Loading Loading @@ -885,6 +895,8 @@ public class MtpDatabase implements AutoCloseable { case MtpConstants.FORMAT_JFIF: try { ExifInterface exif = new ExifInterface(path); if (exif.getThumbnailRange() != null) return exif.getThumbnail(); } catch (IOException e) { // ignore and fall through Loading media/tests/MtpTests/res/raw/test_bad_thumb.jpg +8.41 KiB (8.41 KiB) File changed.No diff preview for this file type. View original file View changed file media/tests/MtpTests/src/android/mtp/MtpDatabaseTest.java +3 −2 Original line number Diff line number Diff line Loading @@ -271,9 +271,10 @@ public class MtpDatabaseTest { Log.d(TAG, "testMtpDatabaseThumbnail: Test bad JPG"); testThumbnail(handleJpgBadThumb, jpgfileBadThumb, false); // Now we support to generate thumbnail if embedded thumbnail is corrupted or not existed testThumbnail(handleJpgBadThumb, jpgfileBadThumb, true); testThumbnail(handleJpgNoThumb, jpgFileNoThumb, false); testThumbnail(handleJpgNoThumb, jpgFileNoThumb, true); testThumbnail(handleJpgBad, jpgfileBad, false); Loading Loading
media/java/android/mtp/MtpDatabase.java +15 −3 Original line number Diff line number Diff line Loading @@ -821,8 +821,10 @@ public class MtpDatabase implements AutoCloseable { ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, byteStream); if (byteStream.size() > MAX_THUMB_SIZE) if (byteStream.size() > MAX_THUMB_SIZE) { Log.w(TAG, "getThumbnailProcess: size=" + byteStream.size()); return null; } byte[] byteArray = byteStream.toByteArray(); Loading Loading @@ -852,7 +854,15 @@ public class MtpDatabase implements AutoCloseable { outLongs[0] = thumbOffsetAndSize != null ? thumbOffsetAndSize[1] : 0; outLongs[1] = exif.getAttributeInt(ExifInterface.TAG_PIXEL_X_DIMENSION, 0); outLongs[2] = exif.getAttributeInt(ExifInterface.TAG_PIXEL_Y_DIMENSION, 0); if (exif.getThumbnailRange() != null) { if ((outLongs[0] == 0) || (outLongs[1] == 0) || (outLongs[2] == 0)) { Log.d(TAG, "getThumbnailInfo: check thumb info:" + thumbOffsetAndSize[0] + "," + thumbOffsetAndSize[1] + "," + outLongs[1] + "," + outLongs[2]); } return true; } } catch (IOException e) { // ignore and fall through } Loading Loading @@ -885,6 +895,8 @@ public class MtpDatabase implements AutoCloseable { case MtpConstants.FORMAT_JFIF: try { ExifInterface exif = new ExifInterface(path); if (exif.getThumbnailRange() != null) return exif.getThumbnail(); } catch (IOException e) { // ignore and fall through Loading
media/tests/MtpTests/res/raw/test_bad_thumb.jpg +8.41 KiB (8.41 KiB) File changed.No diff preview for this file type. View original file View changed file
media/tests/MtpTests/src/android/mtp/MtpDatabaseTest.java +3 −2 Original line number Diff line number Diff line Loading @@ -271,9 +271,10 @@ public class MtpDatabaseTest { Log.d(TAG, "testMtpDatabaseThumbnail: Test bad JPG"); testThumbnail(handleJpgBadThumb, jpgfileBadThumb, false); // Now we support to generate thumbnail if embedded thumbnail is corrupted or not existed testThumbnail(handleJpgBadThumb, jpgfileBadThumb, true); testThumbnail(handleJpgNoThumb, jpgFileNoThumb, false); testThumbnail(handleJpgNoThumb, jpgFileNoThumb, true); testThumbnail(handleJpgBad, jpgfileBad, false); Loading