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 1 commit
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,10 @@ public static boolean isMediaStoreUri(Uri uri) {
&& MediaStore.AUTHORITY.equals(uri.getAuthority());
}

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,25 @@
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_identifiesAndroidPickerUris() {
Uri mediaStoreUri = Uri.withAppendedPath(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, "123");
Uri androidPickerUri =
Uri.parse("content://media/picker/0/com.android.providers.media.photopicker/media/123");

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