Use a ExifInterface ctor with a file descriptor as a parameter

To avoid a binder circular dependency, ExifInterface is changed to use
a file descriptor for getting HEIF attributes (when available).

Bug: 199822700
Test: manual
Change-Id: I1b0762fd91f89bfb739b47467a685149309dd157
This commit is contained in:
Hyoungho Choi 2023-03-02 22:05:30 +09:00 committed by Ray Essick
parent 627b64593d
commit e106aa909b

View File

@ -49,6 +49,7 @@ 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;
@ -255,17 +256,19 @@ public class ThumbnailUtils {
// get orientation // get orientation
if (MediaFile.isExifMimeType(mimeType)) { if (MediaFile.isExifMimeType(mimeType)) {
exif = new ExifInterface(file); try (FileInputStream is = new FileInputStream(file)) {
switch (exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 0)) { exif = new ExifInterface(is.getFD());
case ExifInterface.ORIENTATION_ROTATE_90: switch (exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 0)) {
orientation = 90; case ExifInterface.ORIENTATION_ROTATE_90:
break; orientation = 90;
case ExifInterface.ORIENTATION_ROTATE_180: break;
orientation = 180; case ExifInterface.ORIENTATION_ROTATE_180:
break; orientation = 180;
case ExifInterface.ORIENTATION_ROTATE_270: break;
orientation = 270; case ExifInterface.ORIENTATION_ROTATE_270:
break; orientation = 270;
break;
}
} }
} }