Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Request external permission when listing external directories #487

Merged
merged 1 commit into from
Mar 17, 2022

Conversation

breautek
Copy link
Contributor

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

  • I've run the tests to see all new and existing tests pass
  • I added automated test coverage as appropriate for this change
  • Commit is prefixed with (platform) if this change only applies to one platform (e.g. (android))
  • If this Pull Request resolves an issue, I linked to the issue in the text above (and used the correct keyword to close issues using keywords)
  • I've updated the documentation if necessary

Copy link

@PieterVanPoyer PieterVanPoyer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks very good!

@breautek
Copy link
Contributor Author

Thanks for the review.

iOS is failing because of

resolveLocalFileSystemURL on cdvfile://
✗ file.spec.147 should be able to resolve cdvfile applicationDirectory fs root
- Expected [object Event] not to be defined.

This test case was failing since WKWebView was enforced, when cordova-ios@6 was released. So I don't consider this a blocker.

Android is failing because of

Failed to install 'cordova-plugin-paramedic': Error: There was a conflict trying to modify attributes with in plugin cordova-plugin-paramedic. The conflicting plugin, undefined, already modified the same attributes. The conflict must be resolved before cordova-plugin-paramedic can be added. You may use --force to add the plugin and overwrite the conflicting attributes.

Based on my local and manual testing using my test app, I believe that this PR is still an improvement over what is currently in master.

I'll merge in approximately 24 hours if there are no objections.

@peitschie
Copy link
Contributor

Is this still going to merge sometime @breautek ? 😸

@breautek breautek merged commit a56ab1e into apache:master Mar 17, 2022
@breautek breautek deleted the feat/api30 branch March 17, 2022 13:07
@breautek
Copy link
Contributor Author

Is this still going to merge sometime @breautek ? smile_cat

I suppose it's been well over 24 hours without objections. 😄

tmrkk added a commit to tinymobilerobots/cordova-plugin-file that referenced this pull request Mar 25, 2022
pmcquay pushed a commit to BetterImpact/cordova-plugin-file that referenced this pull request Sep 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants