Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
None
-
None
Description
Line 582 in FileUtils.java has:
String[] allowedStorageDirectories =
;
This would cause an JSON exception when "externalApplicationStorageDirectory" is not present, which happens when the external storage is not mounted in the device/emulator.
Attachments
Activity
GitHub user rakatyal opened a pull request:
https://github.com/apache/cordova-plugin-file/pull/179
CB-11142: Fix the NeedPermission code for the case when external medi…
…a is not mounted in Android
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/MSOpenTech/cordova-plugin-file raghav/fixpermission
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/cordova-plugin-file/pull/179.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 #179
commit c3aad57c2e7848157365f9cce8bd90dcaba8e0e9
Author: Raghav Katyal <rakatyal@microsoft.com>
Date: 2016-04-25T20:51:31Z
CB-11142: Fix the NeedPermission code for the case when external media is not mounted in Android
Github user rakatyal commented on the pull request:
https://github.com/apache/cordova-plugin-file/pull/179#issuecomment-214520604
@riknoll, @jasongin : Please review.
Github user riknoll commented on a diff in the pull request:
https://github.com/apache/cordova-plugin-file/pull/179#discussion_r60988953
— Diff: README.md —
@@ -273,6 +273,15 @@ Listing asset directories is really slow on Android. You can speed it up though,
adding `src/android/build-extras.gradle` to the root of your android project (also
requires cordova-android@4.0.0 or greater).
+### Permisson to write to external storage when it's not mounted
+
+Marshmallow requires the apps to ask for permissions when reading/writing to external locations. By default, your app has permission to write to
— End diff –
Link to [this](http://developer.android.com/guide/topics/data/data-storage.html#filesExternal) maybe?
Github user riknoll commented on a diff in the pull request:
https://github.com/apache/cordova-plugin-file/pull/179#discussion_r60990249
— Diff: README.md —
@@ -273,6 +273,15 @@ Listing asset directories is really slow on Android. You can speed it up though,
adding `src/android/build-extras.gradle` to the root of your android project (also
requires cordova-android@4.0.0 or greater).
+### Permisson to write to external storage when it's not mounted
+
+Marshmallow requires the apps to ask for permissions when reading/writing to external locations. By default, your app has permission to write to
+`cordova.file.applicationStorageDirectory` and `cordova.file.externalApplicationStorageDirectory`, with the latter becoming available when the external storage
+is mounted and available to use. When the external storage is mounted, the plugin would check if the path of the file being handled falls within these
+directories and would ask for permission if it's not so. However when the external storage is not mounted, `cordova.file.externalApplicationStorageDirectory`
+is not available and the plugin would only be able to check the file path wrt `cordova.file.applicationStorageDirectory`. So if your app tries to write to
+externalApplicationStorageDirectory when the external storage is not mounted, the plugin would still ask for permission and then fail since that path is not available.
— End diff –
Don't bother explaining why it fails. Just state the behavior and say that it is "due to a limitation in Android". That is, we never request runtime permission for those two directories unless external storage is not mounted. Also, clarify that this is only on Marshmallow.
Github user rakatyal commented on a diff in the pull request:
https://github.com/apache/cordova-plugin-file/pull/179#discussion_r60991619
— Diff: README.md —
@@ -273,6 +273,15 @@ Listing asset directories is really slow on Android. You can speed it up though,
adding `src/android/build-extras.gradle` to the root of your android project (also
requires cordova-android@4.0.0 or greater).
+### Permisson to write to external storage when it's not mounted
+
+Marshmallow requires the apps to ask for permissions when reading/writing to external locations. By default, your app has permission to write to
+`cordova.file.applicationStorageDirectory` and `cordova.file.externalApplicationStorageDirectory`, with the latter becoming available when the external storage
+is mounted and available to use. When the external storage is mounted, the plugin would check if the path of the file being handled falls within these
+directories and would ask for permission if it's not so. However when the external storage is not mounted, `cordova.file.externalApplicationStorageDirectory`
+is not available and the plugin would only be able to check the file path wrt `cordova.file.applicationStorageDirectory`. So if your app tries to write to
+externalApplicationStorageDirectory when the external storage is not mounted, the plugin would still ask for permission and then fail since that path is not available.
— End diff –
Fixed.
Github user jasongin commented on the pull request:
https://github.com/apache/cordova-plugin-file/pull/179#issuecomment-214543607
LGTM
Commit e9cc506ef3215054895b0441197f85baf7ed5046 in cordova-plugin-file's branch refs/heads/master from rakatyal
[ https://git-wip-us.apache.org/repos/asf?p=cordova-plugin-file.git;h=e9cc506 ]
CB-11142: Fix the NeedPermission code for the case when external media is not mounted in Android
This closes #179
rakatyal It will be great to describe what's broken and how to reproduce it.