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

Android: restore getWritePermission, but check can have permission #617

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
32 changes: 20 additions & 12 deletions src/android/FileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ public void run(JSONArray args) throws FileNotFoundException, JSONException, Mal

private void getReadPermission(String rawArgs, int action, CallbackContext callbackContext) {
int requestCode = pendingRequests.createRequest(rawArgs, action, callbackContext);
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
PermissionHelper.requestPermissions(this, requestCode,
new String[]{Manifest.permission.READ_MEDIA_IMAGES, Manifest.permission.READ_MEDIA_VIDEO, Manifest.permission.READ_MEDIA_AUDIO});
} else {
Expand All @@ -543,10 +543,8 @@ private void getReadPermission(String rawArgs, int action, CallbackContext callb
}

private void getWritePermission(String rawArgs, int action, CallbackContext callbackContext) {
if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {
int requestCode = pendingRequests.createRequest(rawArgs, action, callbackContext);
PermissionHelper.requestPermission(this, requestCode, Manifest.permission.WRITE_EXTERNAL_STORAGE);
}
int requestCode = pendingRequests.createRequest(rawArgs, action, callbackContext);
PermissionHelper.requestPermission(this, requestCode, Manifest.permission.WRITE_EXTERNAL_STORAGE);
}

/**
Expand All @@ -559,7 +557,7 @@ private void getWritePermission(String rawArgs, int action, CallbackContext call
* @return
*/
private boolean hasReadPermission() {
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
return PermissionHelper.hasPermission(this, Manifest.permission.READ_MEDIA_IMAGES)
&& PermissionHelper.hasPermission(this, Manifest.permission.READ_MEDIA_VIDEO)
&& PermissionHelper.hasPermission(this, Manifest.permission.READ_MEDIA_AUDIO);
Expand All @@ -568,11 +566,21 @@ private boolean hasReadPermission() {
}
}

private boolean canHaveReadPermission() {
return true;
}

/**
* Starting with API 33, requesting WRITE_EXTERNAL_STORAGE is an auto permission rejection.
*
* @return
*/
private boolean hasWritePermission() {
// Starting with API 33, requesting WRITE_EXTERNAL_STORAGE is an auto permission rejection
return android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU
? true
: PermissionHelper.hasPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
return PermissionHelper.hasPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
}

private boolean canHaveWritePermission() {
return Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU;
}

private boolean needPermission(String nativeURL, int permissionType) throws JSONException {
Expand All @@ -584,9 +592,9 @@ private boolean needPermission(String nativeURL, int permissionType) throws JSON
allowedStorageDirectories.add(j.getString("externalApplicationStorageDirectory"));
}

if (permissionType == READ && hasReadPermission()) {
if (permissionType == READ && (!canHaveReadPermission() || hasReadPermission())) {
return false;
} else if (permissionType == WRITE && hasWritePermission()) {
} else if (permissionType == WRITE && (!canHaveWritePermission() || hasWritePermission())) {
return false;
}

Expand Down
Loading