Skip to content

Commit

Permalink
Do not set requireOriginal on Android photo picker uris. (#5162)
Browse files Browse the repository at this point in the history
* Do not set requireOriginal on Android Picker uris.

Android Picker (https://developer.android.com/training/data-storage/shared/photopicker) uris have MediaStore authority but does not accept requireOriginal.
  • Loading branch information
phoenixli authored Jun 9, 2023
1 parent 028f83c commit b4ae9f3
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
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");
}

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
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();
}
}

0 comments on commit b4ae9f3

Please sign in to comment.