summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--media/java/android/media/ExifInterface.java16
-rw-r--r--media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/ExifInterfaceTest.java7
2 files changed, 15 insertions, 8 deletions
diff --git a/media/java/android/media/ExifInterface.java b/media/java/android/media/ExifInterface.java
index b675afe70199..15cf761c344b 100644
--- a/media/java/android/media/ExifInterface.java
+++ b/media/java/android/media/ExifInterface.java
@@ -1876,11 +1876,16 @@ public class ExifInterface {
}
// Read the thumbnail.
- FileInputStream in = null;
+ InputStream in = null;
try {
if (mAssetInputStream != null) {
- return nativeGetThumbnailFromAsset(
- mAssetInputStream.getNativeAsset(), mThumbnailOffset, mThumbnailLength);
+ in = mAssetInputStream;
+ if (in.markSupported()) {
+ in.reset();
+ } else {
+ Log.d(TAG, "Cannot read thumbnail from inputstream without mark/reset support");
+ return null;
+ }
} else if (mFilename != null) {
in = new FileInputStream(mFilename);
} else if (mSeekableFileDescriptor != null) {
@@ -1903,6 +1908,7 @@ public class ExifInterface {
return buffer;
} catch (IOException | ErrnoException e) {
// Couldn't get a thumbnail image.
+ Log.d(TAG, "Encountered exception while getting thumbnail", e);
} finally {
IoUtils.closeQuietly(in);
}
@@ -3052,7 +3058,8 @@ public class ExifInterface {
thumbnailOffset += mOrfMakerNoteOffset;
}
if (DEBUG) {
- Log.d(TAG, "Setting thumbnail attributes with offset: " + thumbnailOffset);
+ Log.d(TAG, "Setting thumbnail attributes with offset: " + thumbnailOffset
+ + ", length: " + thumbnailLength);
}
if (thumbnailOffset > 0 && thumbnailLength > 0) {
mHasThumbnail = true;
@@ -3122,6 +3129,7 @@ public class ExifInterface {
mHasThumbnail = true;
mThumbnailBytes = totalStripBytes;
+ mThumbnailLength = totalStripBytes.length;
}
}
} else {
diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/ExifInterfaceTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/ExifInterfaceTest.java
index 7ee36340694e..0cc154516ff6 100644
--- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/ExifInterfaceTest.java
+++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/ExifInterfaceTest.java
@@ -196,11 +196,10 @@ public class ExifInterfaceTest extends AndroidTestCase {
private void printExifTagsAndValues(String fileName, ExifInterface exifInterface) {
// Prints thumbnail information.
if (exifInterface.hasThumbnail()) {
- byte[] thumbnailBytes = exifInterface.getThumbnail();
+ byte[] thumbnailBytes = exifInterface.getThumbnailBytes();
if (thumbnailBytes != null) {
Log.v(TAG, fileName + " Thumbnail size = " + thumbnailBytes.length);
- Bitmap bitmap = BitmapFactory.decodeByteArray(
- thumbnailBytes, 0, thumbnailBytes.length);
+ Bitmap bitmap = exifInterface.getThumbnailBitmap();
if (bitmap == null) {
Log.e(TAG, fileName + " Corrupted thumbnail!");
} else {
@@ -265,7 +264,7 @@ public class ExifInterfaceTest extends AndroidTestCase {
// Checks a thumbnail image.
assertEquals(expectedValue.hasThumbnail, exifInterface.hasThumbnail());
if (expectedValue.hasThumbnail) {
- byte[] thumbnailBytes = exifInterface.getThumbnail();
+ byte[] thumbnailBytes = exifInterface.getThumbnailBytes();
assertNotNull(thumbnailBytes);
Bitmap thumbnailBitmap = exifInterface.getThumbnailBitmap();
assertNotNull(thumbnailBitmap);