Skip to content

Commit

Permalink
Merge pull request #2 from ath0mas/allowed-app-dirs-external-sdcards
Browse files Browse the repository at this point in the history
Android: allow read-write to app dirs on external sdcards too
  • Loading branch information
ath0mas authored Aug 25, 2023
2 parents 8059d26 + c4c380b commit e61036e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ the `cordova.file.*` properties map to physical paths on a real device.
| Device Path | `cordova.file.*` | `AndroidExtraFileSystems` | r/w? | persistent? | OS clears | private |
|:------------------------------------------------|:----------------------------|:--------------------------|:----:|:-----------:|:---------:|:-------:|
| `file:///android_asset/` | applicationDirectory | assets | r | N/A | N/A | Yes |
| `/data/data/<app-id>/` | applicationStorageDirectory | - | r/w | N/A | N/A | Yes |
| `<internal>/Android/data/<app-id>/` | applicationStorageDirectory | - | r/w | N/A | N/A | Yes |
| &nbsp;&nbsp;&nbsp;`cache` | cacheDirectory | cache | r/w | Yes | Yes\* | Yes |
| &nbsp;&nbsp;&nbsp;`files` | dataDirectory | files | r/w | Yes | No | Yes |
| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;`Documents` | | documents | r/w | Yes | No | Yes |
Expand Down
8 changes: 8 additions & 0 deletions src/android/FileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,9 @@ private boolean needPermission(String nativeURL, int permissionType) throws JSON
if (j.has("externalApplicationStorageDirectory")) {
allowedStorageDirectories.add(j.getString("externalApplicationStorageDirectory"));
}
ArrayList<String> allowedExtraPatternStorageDirectories = new ArrayList<String>();
// basic pattern for usual application storage directory, to extend the allowed list to external SD cards for example
allowedExtraPatternStorageDirectories.add("/Android/data/" + cordova.getActivity().getPackageName() + "/");

if (permissionType == READ && hasReadPermission()) {
return false;
Expand All @@ -588,6 +591,11 @@ private boolean needPermission(String nativeURL, int permissionType) throws JSON
return false;
}
}
for (String extraPatternDirectory : allowedExtraPatternStorageDirectories) {
if (nativeURL.contains(extraPatternDirectory)) {
return false;
}
}
return true;
}

Expand Down

0 comments on commit e61036e

Please sign in to comment.