Merge changes from topic "cherrypicker-L08900000961397789:N72700001380319289" into udc-dev
* changes: Revert "ExifInterface: Use FileDescriptors whenever we can." Revert "Use a ExifInterface ctor with a file descriptor as a parameter"
This commit is contained in:
@@ -1566,7 +1566,7 @@ public class ExifInterface {
|
|||||||
FileInputStream in = null;
|
FileInputStream in = null;
|
||||||
try {
|
try {
|
||||||
in = new FileInputStream(fileDescriptor);
|
in = new FileInputStream(fileDescriptor);
|
||||||
loadAttributes(in, fileDescriptor);
|
loadAttributes(in);
|
||||||
} finally {
|
} finally {
|
||||||
closeQuietly(in);
|
closeQuietly(in);
|
||||||
if (isFdDuped) {
|
if (isFdDuped) {
|
||||||
@@ -1637,7 +1637,7 @@ public class ExifInterface {
|
|||||||
mSeekableFileDescriptor = null;
|
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
|
* This function decides which parser to read the image data according to the given input stream
|
||||||
* type and the content of the 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) {
|
if (in == null) {
|
||||||
throw new NullPointerException("inputstream shouldn't be null");
|
throw new NullPointerException("inputstream shouldn't be null");
|
||||||
}
|
}
|
||||||
@@ -1993,7 +1993,7 @@ public class ExifInterface {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case IMAGE_TYPE_HEIF: {
|
case IMAGE_TYPE_HEIF: {
|
||||||
getHeifAttributes(inputStream, fd);
|
getHeifAttributes(inputStream);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case IMAGE_TYPE_ORF: {
|
case IMAGE_TYPE_ORF: {
|
||||||
@@ -2580,7 +2580,7 @@ public class ExifInterface {
|
|||||||
} else if (isSeekableFD(in.getFD())) {
|
} else if (isSeekableFD(in.getFD())) {
|
||||||
mSeekableFileDescriptor = in.getFD();
|
mSeekableFileDescriptor = in.getFD();
|
||||||
}
|
}
|
||||||
loadAttributes(in, null);
|
loadAttributes(in);
|
||||||
} finally {
|
} finally {
|
||||||
closeQuietly(in);
|
closeQuietly(in);
|
||||||
if (modernFd != null) {
|
if (modernFd != null) {
|
||||||
@@ -3068,13 +3068,9 @@ public class ExifInterface {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getHeifAttributes(ByteOrderedDataInputStream in, @Nullable FileDescriptor fd)
|
private void getHeifAttributes(ByteOrderedDataInputStream in) throws IOException {
|
||||||
throws IOException {
|
|
||||||
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
|
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
|
||||||
try {
|
try {
|
||||||
if (fd != null) {
|
|
||||||
retriever.setDataSource(fd);
|
|
||||||
} else {
|
|
||||||
retriever.setDataSource(new MediaDataSource() {
|
retriever.setDataSource(new MediaDataSource() {
|
||||||
long mPosition;
|
long mPosition;
|
||||||
|
|
||||||
@@ -3115,9 +3111,7 @@ public class ExifInterface {
|
|||||||
mPosition += bytesRead;
|
mPosition += bytesRead;
|
||||||
return bytesRead;
|
return bytesRead;
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {}
|
||||||
// absorb the exception and fall through to the 'failed read' path below
|
|
||||||
}
|
|
||||||
mPosition = -1; // need to seek on next read
|
mPosition = -1; // need to seek on next read
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -3127,7 +3121,6 @@ public class ExifInterface {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
String exifOffsetStr = retriever.extractMetadata(
|
String exifOffsetStr = retriever.extractMetadata(
|
||||||
MediaMetadataRetriever.METADATA_KEY_EXIF_OFFSET);
|
MediaMetadataRetriever.METADATA_KEY_EXIF_OFFSET);
|
||||||
|
|||||||
@@ -49,7 +49,6 @@ import com.android.internal.util.ArrayUtils;
|
|||||||
import libcore.io.IoUtils;
|
import libcore.io.IoUtils;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
@@ -256,8 +255,7 @@ public class ThumbnailUtils {
|
|||||||
|
|
||||||
// get orientation
|
// get orientation
|
||||||
if (MediaFile.isExifMimeType(mimeType)) {
|
if (MediaFile.isExifMimeType(mimeType)) {
|
||||||
try (FileInputStream is = new FileInputStream(file)) {
|
exif = new ExifInterface(file);
|
||||||
exif = new ExifInterface(is.getFD());
|
|
||||||
switch (exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 0)) {
|
switch (exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 0)) {
|
||||||
case ExifInterface.ORIENTATION_ROTATE_90:
|
case ExifInterface.ORIENTATION_ROTATE_90:
|
||||||
orientation = 90;
|
orientation = 90;
|
||||||
@@ -270,7 +268,6 @@ public class ThumbnailUtils {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (mimeType.equals("image/heif")
|
if (mimeType.equals("image/heif")
|
||||||
|| mimeType.equals("image/heif-sequence")
|
|| mimeType.equals("image/heif-sequence")
|
||||||
|
|||||||
Reference in New Issue
Block a user