apache / cordova-plugin-file

Apache Cordova File Plugin
https://cordova.apache.org/
Apache License 2.0
740 stars 757 forks source link

Android : Added write permission check for Android devices of platfor… #611

Closed hrp03 closed 6 months ago

hrp03 commented 6 months ago

Platforms affected

Android

Motivation and Context

When writing a file on Android devices where version is >= 13 getting false as permission while checking runtime write permission.

Description

On Android devices >= 13 the write permission has not been checked and it always returns as false. This is happening in FileUtils.java file in getWritePermission method.

The same issue also has been raised and it this pull request will solve that

https://github.com/apache/cordova-plugin-file/issues/610

Testing

Tested the code on real devices where android versions are 11, 12, and 13 respectively. Able to write files now.

Checklist

erisu commented 6 months ago

Those are read permissions and has nothing to do with write.

https://developer.android.com/reference/android/Manifest.permission#READ_MEDIA_AUDIO

https://developer.android.com/reference/android/Manifest.permission#READ_MEDIA_IMAGES

https://developer.android.com/reference/android/Manifest.permission#READ_MEDIA_VIDEO

Doc for each permission say:

Allows an application to read <...> files from external storage.

breautek commented 6 months ago

With scoped storage you don't need permissions to write to external storage, however it's forbidden to modify files that isn't owned by you. Android offers no permission to allow modifying other app's external files. (e.g. there is no WRITE_MEDIA_IMAGES). This is documented here, in short if you want to modify another app's external file, you'll need a plugin that interfaces with the MediaStore API.

The hasWritePermission will always return true to allow you to write to your own external files.

This change isn't in a stable release yet, but a release that contains this patch is being voted on and assuming there are no objections, we should have a release soon and it should address the concern that you're attempting to address.