Skip to content

Commit

Permalink
[media-library] fix permission not granted on android api < 29 (#14570)
Browse files Browse the repository at this point in the history
# Why

[versioned qa][android] test-suite "MediaLibrary" show `Tests were skipped - not enough permissions to run them.` on android 8 device

# How

requesting `ACCESS_MEDIA_LOCATION` permission only on android 10+

# Test Plan

bare-expo test-suite "MediaLibrary" on android 8 device
for android 10 emulator, which is expected failed as #14413 mentioned.

(cherry picked from commit 35d639f)
  • Loading branch information
Kudo committed Sep 30, 2021
1 parent 30d65e5 commit 403b9b7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
2 changes: 2 additions & 0 deletions packages/expo-media-library/CHANGELOG.md
Expand Up @@ -8,6 +8,8 @@

### 🐛 Bug fixes

- Fix permissions always returning denied on android api < 29. ([#14570](https://github.com/expo/expo/pull/14570) by [@kudo](https://github.com/kudo))

### 💡 Others

## 13.0.0 — 2021-09-28
Expand Down
Expand Up @@ -28,6 +28,7 @@
import expo.modules.core.interfaces.services.UIManager;

import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -451,17 +452,15 @@ private boolean isMissingWritePermission() {
}

private String[] getManifestPermissions(boolean writeOnly) {
if (writeOnly) {
return new String[]{
WRITE_EXTERNAL_STORAGE,
ACCESS_MEDIA_LOCATION
};
final List<String> permissions = new ArrayList<>();
permissions.add(WRITE_EXTERNAL_STORAGE);
if (!writeOnly) {
permissions.add(READ_EXTERNAL_STORAGE);
}
return new String[]{
READ_EXTERNAL_STORAGE,
WRITE_EXTERNAL_STORAGE,
ACCESS_MEDIA_LOCATION,
};
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
permissions.add(ACCESS_MEDIA_LOCATION);
}
return permissions.toArray(new String[0]);
}

private void runActionWithPermissions(List<String> assetsId, Action action, Promise promise) {
Expand Down

0 comments on commit 403b9b7

Please sign in to comment.