Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit baad7d84 authored by Jin Park's avatar Jin Park
Browse files

ExifInterface: Remove AssetInputStream dependency

ExifInterface calls native method to retrieve thumbnail data from an
AssetInputStream data. This CL removes that dependecy.

Bug: 29409358
Change-Id: I890b0e813733a5dcaa5480ee48e68c63fc079114
parent 04378566
Loading
Loading
Loading
Loading
+12 −4
Original line number Diff line number Diff line
@@ -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 {
+3 −4
Original line number Diff line number Diff line
@@ -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);