alexisGandar opened a new issue, #586:
URL: https://github.com/apache/cordova-plugin-file/issues/586

   # Bug Report
   When writing file in this path " window.cordova.file.externalRootDirectory + 
'Download' " it always throws a permission error on getFile action. The bug 
occur when upgrading on cordova-plugin-file V8 and cordova-android V12 and only 
on device with Android 10 and bellow. It does work on cordova-plugin-file V7 
and cordova-android V11
   
   ## Problem
   The modal that request user authorisation for writing 
(WRITE_EXTERNAL_STORAGE) does not pop on screen witch lead to an 
INVALID_MODIFICATION_ERR (code 9) because the permission is not granted
   
   ### What is expected to happen?
   The modal that request the permission is displayed.
   
   
   ### What does actually happen?
   The modal does not appear
   
   
   ## Information
   I found out that when writing a file the following action are executed in 
FileUtils.java : 
   - ResolveLocalFileSystemURI
   - RequestAllFileSystem
   - GetFile
   - GetFileMetaData
   - Write
   
   The permission is checked on the "Write" step but on Android 10 (for reasons 
that I can't explain) the permission seems to be required at the GetFile steps.
   
   I did patch this issus by editing the GetFile steps in order to always ask 
for permission if needed on this step but I am not sure of the concequencies of 
this edit.
   
   `else if (action.equals("getFile")) {
               threadhelper( new FileOp( ){
                   public void run(JSONArray args) throws FileExistsException, 
IOException, TypeMismatchException, EncodingException, JSONException {
                       String dirname = args.getString(0);
                       String path = args.getString(1);
   
                       String nativeURL = 
resolveLocalFileSystemURI(dirname).getString("nativeURL");
                       boolean containsCreate = (args.isNull(2)) ? false : 
args.getJSONObject(2).optBoolean("create", false);
   
                       if(containsCreate && needPermission(nativeURL, WRITE)) {
                         getWritePermission(rawArgs, ACTION_GET_FILE, 
callbackContext);
                       }
                       else if(!containsCreate && needPermission(nativeURL, 
READ)) {
                         getReadPermission(rawArgs, ACTION_GET_FILE, 
callbackContext);
                       }
                       else {
                         JSONObject obj = getFile(dirname, path, 
args.optJSONObject(2), false);
                         callbackContext.success(obj);
                       }
                   }
               }, rawArgs, callbackContext);
           }`
   
   ### Command or Code
   <!-- What command or code is needed to reproduce the problem? -->
   To reproduce the problem try to save a file with "writeFile" to " 
window.cordova.file.externalRootDirectory + 'Download'
   
   ### Environment, Platform, Device
   <!-- In what environment, on what platform or on which device are you 
experiencing the issue? -->
   Android 10 with cordova-plugin-file V8 and cordova-android V12
   
   ## Checklist
   <!-- Please check the boxes by putting an x in the [ ] like so: [x] -->
   
   - [x] I searched for existing GitHub issues
   - [x] I updated all Cordova tooling to most recent version
   - [x] I included all the necessary information above
   


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to