[jira] [Commented] (CB-10977) Overlapping permission requests in Android can cause errors

2016-03-30 Thread ASF GitHub Bot (JIRA)

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

ASF GitHub Bot commented on CB-10977:
-

Github user asfgit closed the pull request at:

https://github.com/apache/cordova-plugin-file/pull/174


> 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: issues-unsubscr...@cordova.apache.org
For additional commands, e-mail: issues-h...@cordova.apache.org



[jira] [Commented] (CB-10977) Overlapping permission requests in Android can cause errors

2016-03-30 Thread ASF subversion and git services (JIRA)

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

ASF subversion and git services commented on CB-10977:
--

Commit 6aeb9d9d1a91c2657218e6c81dfe2b57bd46f7d7 in cordova-plugin-file's branch 
refs/heads/master from Richard Knoll
[ https://git-wip-us.apache.org/repos/asf?p=cordova-plugin-file.git;h=6aeb9d9 ]

CB-10977 android: Removing global state used for permission requests

This closes #174


> 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: issues-unsubscr...@cordova.apache.org
For additional commands, e-mail: issues-h...@cordova.apache.org



[jira] [Commented] (CB-10977) Overlapping permission requests in Android can cause errors

2016-03-29 Thread ASF GitHub Bot (JIRA)

[ 
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: issues-unsubscr...@cordova.apache.org
For additional commands, e-mail: issues-h...@cordova.apache.org



[jira] [Commented] (CB-10977) Overlapping permission requests in Android can cause errors

2016-03-29 Thread ASF GitHub Bot (JIRA)

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

ASF GitHub Bot commented on CB-10977:
-

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

https://github.com/apache/cordova-plugin-file/pull/174#discussion_r57761716
  
--- 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 --

Should there be a return after this line?


> 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: issues-unsubscr...@cordova.apache.org
For additional commands, e-mail: issues-h...@cordova.apache.org



[jira] [Commented] (CB-10977) Overlapping permission requests in Android can cause errors

2016-03-28 Thread ASF GitHub Bot (JIRA)

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

ASF GitHub Bot commented on CB-10977:
-

Github user riknoll commented on the pull request:


https://github.com/apache/cordova-plugin-file/pull/174#issuecomment-202582415
  
@infil00p @jasongin @rakatyal please review when you have a moment. Also, 
should I add manual tests for this? It requires interacting with permission 
dialogs, so we can't really do any auto tests.


> 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: issues-unsubscr...@cordova.apache.org
For additional commands, e-mail: issues-h...@cordova.apache.org



[jira] [Commented] (CB-10977) Overlapping permission requests in Android can cause errors

2016-03-28 Thread ASF GitHub Bot (JIRA)

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

ASF GitHub Bot commented on CB-10977:
-

GitHub user riknoll opened a pull request:

https://github.com/apache/cordova-plugin-file/pull/174

CB-10977 android: Removing global state used for permission requests

The associated JIRA is 
[CB-10977](https://issues.apache.org/jira/browse/CB-10977). Check out the 
description on the issue for an explanation of the problem. I also added some 
JS that reproduces it in the comments. This fix is contingent on 
https://github.com/apache/cordova-android/pull/285 to work properly (I plan to 
merge that PR soon).

This will also change the behavior when used with older versions of 
cordova-android (i.e. without 
https://github.com/apache/cordova-android/pull/285) and should prevent some of 
the weirder bugs. The behavior will still be broken, but less so.

You can merge this pull request into a Git repository by running:

$ git pull https://github.com/MSOpenTech/cordova-plugin-file CB-10977

Alternatively you can review and apply these changes as the patch at:

https://github.com/apache/cordova-plugin-file/pull/174.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

This closes #174


commit 91fe4a3111447af4878554b4a824abc52978e26a
Author: Richard Knoll 
Date:   2016-03-28T19:09:21Z

CB-10977 android: Removing global state used for permission requests




> 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, 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



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

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



[jira] [Commented] (CB-10977) Overlapping permission requests in Android can cause errors

2016-03-28 Thread Richard B Knoll (JIRA)

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

Richard B Knoll commented on CB-10977:
--

To reproduce:

{code:javascript}
window.resolveLocalFileSystemURL(cordova.file.externalRootDirectory, 
function(dirEntry) {

// Create a directory before runtime write permission has been granted
dirEntry.getDirectory('test1', {create: true}, function(createdDir) {
createdDir.remove(function(){
alert('Removed test1')
}, function(){});
}, function(){});

// Create a second directory before the first permission request is 
allowed/denied
dirEntry.getDirectory('test2', {create: true}, function(createdDir) {
createdDir.remove(function(){
alert('Removed test2')
}, function(){});
}, function(){});

}, function(){});
{code}

The user will be asked to grant permission twice but the app will only display 
'Removed test2'. The Android logs will show that a second result is sent to the 
callback context

> 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, 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



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

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



[jira] [Commented] (CB-10977) Overlapping permission requests in Android can cause errors

2016-03-28 Thread Richard B Knoll (JIRA)

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

Richard B Knoll commented on CB-10977:
--

I've got a fix for this, will open a PR

> 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, 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



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

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