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

Do not set requireOriginal on Android photo picker uris. #5162

Merged
merged 5 commits into from
Jun 9, 2023
Merged
Show file tree
Hide file tree
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 @@ -20,6 +20,12 @@ public static boolean isMediaStoreUri(Uri uri) {
&& MediaStore.AUTHORITY.equals(uri.getAuthority());
}

// Android picker uris contain a "picker" segment:
// https://android.googlesource.com/platform/packages/providers/MediaProvider/+/refs/heads/master/src/com/android/providers/media/PickerUriResolver.java#58
public static boolean isAndroidPickerUri(Uri uri) {
return isMediaStoreUri(uri) && uri.getPathSegments().contains("picker");
phoenixli marked this conversation as resolved.
Show resolved Hide resolved
}

private static boolean isVideoUri(Uri uri) {
return uri.getPathSegments().contains("video");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,11 @@ private LoadData<DataT> buildDelegateData() throws FileNotFoundException {
if (Environment.isExternalStorageLegacy()) {
return fileDelegate.buildLoadData(queryForFilePath(uri), width, height, options);
} else {
// Android Picker uris have MediaStore authority and does not accept requireOriginal.
if (MediaStoreUtil.isAndroidPickerUri(uri)) {
return uriDelegate.buildLoadData(uri, width, height, options);
}

Uri toLoad = isAccessMediaLocationGranted() ? MediaStore.setRequireOriginal(uri) : uri;
return uriDelegate.buildLoadData(toLoad, width, height, options);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.bumptech.glide.load.data.mediastore;

import static com.google.common.truth.Truth.assertThat;

import android.net.Uri;
import android.provider.MediaStore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;

@RunWith(RobolectricTestRunner.class)
@Config(sdk = 18)
public class MediaStoreUtilTest {

@Test
phoenixli marked this conversation as resolved.
Show resolved Hide resolved
public void isAndroidPickerUri_notAndroidPickerUri_returnsFalse() {
Uri mediaStoreUri = Uri.withAppendedPath(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, "123");

assertThat(MediaStoreUtil.isAndroidPickerUri(mediaStoreUri)).isFalse();
}

@Test
public void isAndroidPickerUri_identifiesAndroidPickerUri_returnsTrue() {
Uri androidPickerUri =
Uri.parse("content://media/picker/0/com.android.providers.media.photopicker/media/123");

assertThat(MediaStoreUtil.isAndroidPickerUri(androidPickerUri)).isTrue();
}
}