feat: Request external permission when listing external directories #487
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Platforms affected
Android
Motivation and Context
Progresses #426 but unsure if it completely resolves it
Description
Code changes includes checking to see the file path on reading directory listings (for listing directories and files) and if the file path happens to be an "external" file path, then assert/request READ_EXTERNAL_STORAGE permission.
There have been a couple of documentation changes as well, including the fact that some directories that were previously writable in earlier API versions are no longer writable starting in API 30.
requestLegacyExternalStorage
flag is removed because that was an API 29 only flag. This flag is not honoured on API 30 and is forcefully false.Testing
Npm test and manual testing using a test app: https://github.com/breautek/cordova-file-api30-test-app
I'm not sure if my test app is an exhaustive list, but the basic directory listing, reading and writing all appear to work properly assuming the app has the READ/WRITE_EXTERNAL_STORAGE permission granted.
CDVFILE urls however don't quite work as expected and is not covered in this PR. If a cdvfile url leads to an external directory source and the app does not have the proper permissions, the webview does not wait for the permission response and the request will fail. From what I can tell, cdvfile-based urls do work if the app already has the permission granted.
Checklist
(platform)
if this change only applies to one platform (e.g.(android)
)