[ 
https://issues.apache.org/jira/browse/CB-10977?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15216373#comment-15216373
 ] 

ASF GitHub Bot commented on CB-10977:
-------------------------------------

Github user riknoll commented on a diff in the pull request:

    https://github.com/apache/cordova-plugin-file/pull/174#discussion_r57762270
  
    --- Diff: src/android/FileUtils.java ---
    @@ -1151,51 +1140,55 @@ private long truncateFile(String srcURLstr, long 
size) throws FileNotFoundExcept
     
         public void onRequestPermissionResult(int requestCode, String[] 
permissions,
                                               int[] grantResults) throws 
JSONException {
    -        for(int r:grantResults)
    -        {
    -            if(r == PackageManager.PERMISSION_DENIED)
    +
    +        final PendingRequests.Request req = 
pendingRequests.getAndRemove(requestCode);
    +        if (req != null) {
    +            for(int r:grantResults)
                 {
    -                callback.sendPluginResult(new 
PluginResult(PluginResult.Status.ERROR, SECURITY_ERR));
    +                if(r == PackageManager.PERMISSION_DENIED)
    +                {
    +                    req.getCallbackContext().sendPluginResult(new 
PluginResult(PluginResult.Status.ERROR, SECURITY_ERR));
    --- End diff --
    
    Ha, yep! Good catch! It doesn't look like there was a return there before 
either so I wonder how that worked.


> Overlapping permission requests in Android can cause errors
> -----------------------------------------------------------
>
>                 Key: CB-10977
>                 URL: https://issues.apache.org/jira/browse/CB-10977
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: Plugin File
>         Environment: Marshmallow
>            Reporter: Richard B Knoll
>            Assignee: Richard B Knoll
>            Priority: Critical
>              Labels: android, mustfix, reproduced, triaged
>
> We use global state for permission requests in the file plugin that gets 
> overwritten on each call to the plugin. That means that if multiple 
> writes/reads are performed while the permission request is pending, the 
> global state will get overwritten and callbacks will not be returned 
> correctly. For example,
> {code}
> getFile('test1', {create:true}, function(){}, function(){});
> getDirectory('test2', {create:true}, function(){}, function(){});
> {code}
> In the above code block, only the second call ({{getDirectory}}) would get a 
> success or error callback. Furthermore, this code will attempt to create both 
> a directory and a file named {{test1}} because the permission callback for 
> the first call will be executed using the arguments from the second call.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

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

Reply via email to