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

fix(android): hasWritePermission for SDK 33 #608

Merged
merged 7 commits into from
Oct 17, 2023
11 changes: 8 additions & 3 deletions src/android/FileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -543,8 +543,10 @@ private void getReadPermission(String rawArgs, int action, CallbackContext callb
}

private void getWritePermission(String rawArgs, int action, CallbackContext callbackContext) {
int requestCode = pendingRequests.createRequest(rawArgs, action, callbackContext);
PermissionHelper.requestPermission(this, requestCode, Manifest.permission.WRITE_EXTERNAL_STORAGE);
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);
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is happening here in the else case?
Mostly asking because getWritePermission is always called providing a callbackContext.
Are we sure it does not wait indefinitely?
Is doing nothing really fine, or should callbackContext be called in every case, to guarantee the execution flow continues?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I "found" my own answer:
in current code, in the case of Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU, getWritePermission is never called ...
So my question does not really mater, even if strictly speaking it is probably a problem for the execution flow, indefinitely waiting for the callbackContext.

Details:
getWritePermission calls are always preceded by a check for needPermission(nativeURL, WRITE), that will return false in this same given versions condition, because hasWritePermission was changed to always return true for it.
So, the if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) { added in getWritePermission is mostly useless, and should whether be removed or be fixed.

}

/**
Expand All @@ -567,7 +569,10 @@ private boolean hasReadPermission() {
}

private boolean hasWritePermission() {
return PermissionHelper.hasPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
// 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);
}

private boolean needPermission(String nativeURL, int permissionType) throws JSONException {
Expand Down
Loading