Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class LocalContentUriFetchProducer extends LocalFetchProducer {
public static final String PRODUCER_NAME = "LocalContentUriFetchProducer";

private static final String[] PROJECTION =
new String[] {MediaStore.Images.Media._ID, MediaStore.Images.ImageColumns.DATA};
new String[] {MediaStore.Images.Media._ID};

private final ContentResolver mContentResolver;

Expand Down Expand Up @@ -67,44 +67,9 @@ protected EncodedImage getEncodedImage(ImageRequest imageRequest) throws IOExcep
// If a Contact URI is provided, use the special helper to open that contact's photo.
return getEncodedImage(inputStream, EncodedImage.UNKNOWN_STREAM_SIZE);
}

if (UriUtil.isLocalCameraUri(uri)) {
EncodedImage cameraImage = getCameraImage(uri);
if (cameraImage != null) {
return cameraImage;
}
}

return getEncodedImage(mContentResolver.openInputStream(uri), EncodedImage.UNKNOWN_STREAM_SIZE);
}

private @Nullable EncodedImage getCameraImage(Uri uri) throws IOException {
Cursor cursor = mContentResolver.query(uri, PROJECTION, null, null, null);
if (cursor == null) {
return null;
}
try {
if (cursor.getCount() == 0) {
return null;
}
cursor.moveToFirst();
final String pathname =
cursor.getString(cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA));
if (pathname != null) {
ParcelFileDescriptor parcelFileDescriptor = mContentResolver.openFileDescriptor(uri, "r");
FileDescriptor fd = parcelFileDescriptor.getFileDescriptor();
return getEncodedImage(new FileInputStream(fd), getLength(pathname));
}
} finally {
cursor.close();
}
return null;
}

private static int getLength(String pathname) {
return pathname == null ? -1 : (int) new File(pathname).length();
}

@Override
protected String getProducerName() {
return PRODUCER_NAME;
Expand Down