erisu commented on code in PR #581:
URL: 
https://github.com/apache/cordova-plugin-file/pull/581#discussion_r1358419832


##########
src/android/FileUtils.java:
##########
@@ -593,14 +593,17 @@ private void getReadPermission(String rawArgs, int 
action, CallbackContext callb
         if (android.os.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 {
+        } else {
             PermissionHelper.requestPermission(this, requestCode, 
Manifest.permission.READ_EXTERNAL_STORAGE);
-          }
+        }
     }
 
     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);
+       int requestCode = pendingRequests.createRequest(rawArgs, action, 
callbackContext);
+        if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
+        } else {
+          PermissionHelper.requestPermission(this, requestCode, 
Manifest.permission.WRITE_EXTERNAL_STORAGE);
+        }

Review Comment:
   `getWritePermission` is already wrapped by a condition that requires 
`needPermission` to be `true`, before it is called.
   
   `needPermission` should then hit this condition:
   
   ```
   else if(permissionType == WRITE && hasWritePermission()) {
               return false;
           }
   ```
   
   Which should `return false` once the `hasWritePermission` method is fixed.
   
   I think the only changes needed in this PR should be:
   
   ```java
       private boolean hasWritePermission() {
           return android.os.Build.VERSION.SDK_INT >= 
Build.VERSION_CODES.TIRAMISU
               ? true
               : PermissionHelper.hasPermission(this, 
Manifest.permission.WRITE_EXTERNAL_STORAGE);
       }
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@cordova.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@cordova.apache.org
For additional commands, e-mail: issues-h...@cordova.apache.org

Reply via email to