Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scoped storage #2521

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
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