Commit 3153bedb authored by Finnur Thorarinsson's avatar Finnur Thorarinsson Committed by Commit Bot

Photo Picker: Fix crash when denying Storage permission.

Bug: 950024, 656015
Change-Id: Id0f9a491ab3e5260f41a01c0a5ace1ed66c0c97e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1572123
Auto-Submit: Finnur Thorarinsson <finnur@chromium.org>
Commit-Queue: Ted Choc <tedchoc@chromium.org>
Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#652165}
parent 44be77d3
...@@ -155,15 +155,12 @@ public class SelectFileDialog implements WindowAndroid.IntentCallback, PhotoPick ...@@ -155,15 +155,12 @@ public class SelectFileDialog implements WindowAndroid.IntentCallback, PhotoPick
new Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION)); new Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION));
List<String> missingPermissions = new ArrayList<>(); List<String> missingPermissions = new ArrayList<>();
if (shouldUsePhotoPicker()) { String storagePermission = BuildInfo.isAtLeastQ()
if (BuildInfo.isAtLeastQ()) { ? "android.permission.READ_MEDIA_IMAGES"
String newImagePermission = "android.permission.READ_MEDIA_IMAGES"; : Manifest.permission.READ_EXTERNAL_STORAGE;
if (!window.hasPermission(newImagePermission)) { boolean shouldUsePhotoPicker = shouldUsePhotoPicker();
missingPermissions.add(newImagePermission); if (shouldUsePhotoPicker) {
} if (!window.hasPermission(storagePermission)) missingPermissions.add(storagePermission);
} else if (!window.hasPermission(Manifest.permission.READ_EXTERNAL_STORAGE)) {
missingPermissions.add(Manifest.permission.READ_EXTERNAL_STORAGE);
}
} else { } else {
if (((mSupportsImageCapture && shouldShowImageTypes()) if (((mSupportsImageCapture && shouldShowImageTypes())
|| (mSupportsVideoCapture && shouldShowVideoTypes())) || (mSupportsVideoCapture && shouldShowVideoTypes()))
...@@ -183,9 +180,17 @@ public class SelectFileDialog implements WindowAndroid.IntentCallback, PhotoPick ...@@ -183,9 +180,17 @@ public class SelectFileDialog implements WindowAndroid.IntentCallback, PhotoPick
missingPermissions.toArray(new String[missingPermissions.size()]); missingPermissions.toArray(new String[missingPermissions.size()]);
window.requestPermissions(requestPermissions, (permissions, grantResults) -> { window.requestPermissions(requestPermissions, (permissions, grantResults) -> {
for (int i = 0; i < grantResults.length; i++) { for (int i = 0; i < grantResults.length; i++) {
if (grantResults[i] == PackageManager.PERMISSION_DENIED && mCapture) { if (grantResults[i] == PackageManager.PERMISSION_DENIED) {
onFileNotSelected(); if (mCapture) {
return; onFileNotSelected();
return;
}
if (shouldUsePhotoPicker
&& requestPermissions[i].equals(storagePermission)) {
onFileNotSelected();
return;
}
} }
} }
launchSelectFileIntent(); launchSelectFileIntent();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment