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

Commit c938e597 authored by Ray Essick's avatar Ray Essick
Browse files

Revert "ExifInterface: Use FileDescriptors whenever we can."

This reverts commit e69a12f3.

Reason for revert: OEM reports regressions
Bug: 199822700
Bug: 283908789
Change-Id: Icd62dc912938b01015b902d2a072f3b758e6084a
parent e69a12f3
Loading
Loading
Loading
Loading
+49 −56
Original line number Diff line number Diff line
@@ -1566,7 +1566,7 @@ public class ExifInterface {
        FileInputStream in = null;
        try {
            in = new FileInputStream(fileDescriptor);
            loadAttributes(in, fileDescriptor);
            loadAttributes(in);
        } finally {
            closeQuietly(in);
            if (isFdDuped) {
@@ -1637,7 +1637,7 @@ public class ExifInterface {
                mSeekableFileDescriptor = null;
            }
        }
        loadAttributes(inputStream, null);
        loadAttributes(inputStream);
    }

    /**
@@ -1963,7 +1963,7 @@ public class ExifInterface {
     * This function decides which parser to read the image data according to the given input stream
     * type and the content of the input stream.
     */
    private void loadAttributes(@NonNull InputStream in, @Nullable FileDescriptor fd) {
    private void loadAttributes(@NonNull InputStream in) {
        if (in == null) {
            throw new NullPointerException("inputstream shouldn't be null");
        }
@@ -1993,7 +1993,7 @@ public class ExifInterface {
                        break;
                    }
                    case IMAGE_TYPE_HEIF: {
                        getHeifAttributes(inputStream, fd);
                        getHeifAttributes(inputStream);
                        break;
                    }
                    case IMAGE_TYPE_ORF: {
@@ -2580,7 +2580,7 @@ public class ExifInterface {
            } else if (isSeekableFD(in.getFD())) {
                mSeekableFileDescriptor = in.getFD();
            }
            loadAttributes(in, null);
            loadAttributes(in);
        } finally {
            closeQuietly(in);
            if (modernFd != null) {
@@ -3068,13 +3068,9 @@ public class ExifInterface {
        }
    }

    private void getHeifAttributes(ByteOrderedDataInputStream in, @Nullable FileDescriptor fd)
            throws IOException {
    private void getHeifAttributes(ByteOrderedDataInputStream in) throws IOException {
        MediaMetadataRetriever retriever = new MediaMetadataRetriever();
        try {
            if (fd != null) {
                retriever.setDataSource(fd);
            } else {
            retriever.setDataSource(new MediaDataSource() {
                long mPosition;

@@ -3115,9 +3111,7 @@ public class ExifInterface {
                            mPosition += bytesRead;
                            return bytesRead;
                        }
                        } catch (IOException e) {
                            // absorb the exception and fall through to the 'failed read' path below
                        }
                    } catch (IOException e) {}
                    mPosition = -1; // need to seek on next read
                    return -1;
                }
@@ -3127,7 +3121,6 @@ public class ExifInterface {
                    return -1;
                }
            });
            }

            String exifOffsetStr = retriever.extractMetadata(
                    MediaMetadataRetriever.METADATA_KEY_EXIF_OFFSET);