ionic-team / capacitor

Build cross-platform Native Progressive Web Apps for iOS, Android, and the Web ⚡️
https://capacitorjs.com
MIT License
11.47k stars 977 forks source link

bug: Filesystem.read crash my app on Android 10 #3744

Closed cyril-colin closed 3 years ago

cyril-colin commented 3 years ago

Hi, and thank you for your work !

Bug Report

Capacitor Version

💊   Capacitor Doctor  💊 

Latest Dependencies:

  @capacitor/cli: 2.4.2
  @capacitor/core: 2.4.2
  @capacitor/android: 2.4.2
  @capacitor/electron: 2.4.2
  @capacitor/ios: 2.4.2

Installed Dependencies:

  @capacitor/cli 2.3.0
  @capacitor/android 2.3.0
  @capacitor/ios 2.3.0
  @capacitor/core 2.3.0
  @capacitor/electron not installed

[success] Android looking great! 👌
  Found 14 Capacitor plugins for ios:
    @capacitor-community/apple-sign-in (0.0.12)
    @capacitor-community/contacts (0.0.3)
    capacitor-fcm (1.0.1)
    capacitor-jitsi-meet (1.5.3)
    com-darryncampbell-cordova-plugin-intent (2.0.0)
    cordova-plugin-badge (0.8.8)
    cordova-plugin-contacts (3.0.1)
    cordova-plugin-email-composer (0.9.2)
    cordova-plugin-facebook4 (6.2.0)
    cordova-plugin-file (6.0.2)
    cordova-plugin-filepath (1.5.8)
    cordova-plugin-google-analytics (1.8.6)
    cordova-sms-plugin (1.0.0)
    cordova-sqlite-storage (4.0.0)
[success] iOS looking great! 👌

Platform(s)

android

Current Behavior

I try to implement a native share feature on android. So, first of all, I use WebIntent to get my shared image from a SEND or SEND_MULTIPLE intent action.

Then, I pass the URI from intent clip items to my function using Filesystem official plugin :

// Code from a service in my Angular project
    public getData(path: string): Observable<HttpPacket> {
        return from(Filesystem.requestPermissions()).pipe(
            switchMap(_ => from(Filesystem.readFile({path}))), // My app crashes here !!!
        );
    }

Then, when I try to share an image from Google Photo application on a virtual device running Android 10 / SDK 29, I have this java error :

020-10-29 11:21:21.758 26987-27004/? E/DatabaseUtils: Writing exception to parcel
    java.lang.SecurityException: Permission Denial: reading com.google.android.apps.photos.contentprovider.impl.MediaContentProvider uri content://com.google.android.apps.photos.contentprovider/-1/1/content:/media/external/images/media/25/REQUIRE_ORIGINAL/NONE/1614158544 from pid=21631, uid=10140 requires the provider be exported, or grantUriPermission()
        at android.content.ContentProvider.enforceReadPermissionInner(ContentProvider.java:729)
        at android.content.ContentProvider$Transport.enforceReadPermission(ContentProvider.java:602)
        at android.content.ContentProvider$Transport.enforceFilePermission(ContentProvider.java:593)
        at android.content.ContentProvider$Transport.openTypedAssetFile(ContentProvider.java:507)
        at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:307)
        at android.os.Binder.execTransactInternal(Binder.java:1021)
        at android.os.Binder.execTransact(Binder.java:994)
2020-10-29 11:21:21.766 21631-21749/com.myApp.dev E/AndroidRuntime: FATAL EXCEPTION: CapacitorPlugins
    Process: com.myApp.dev, PID: 21631
    java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
        at com.getcapacitor.Bridge$1.run(Bridge.java:530)
        at android.os.Handler.handleCallback(Handler.java:883)
        at android.os.Handler.dispatchMessage(Handler.java:100)
        at android.os.Looper.loop(Looper.java:214)
        at android.os.HandlerThread.run(HandlerThread.java:67)
     Caused by: java.lang.reflect.InvocationTargetException
        at java.lang.reflect.Method.invoke(Native Method)
        at com.getcapacitor.PluginHandle.invoke(PluginHandle.java:99)
        at com.getcapacitor.Bridge$1.run(Bridge.java:521)
        at android.os.Handler.handleCallback(Handler.java:883)
        at android.os.Handler.dispatchMessage(Handler.java:100)
        at android.os.Looper.loop(Looper.java:214)
        at android.os.HandlerThread.run(HandlerThread.java:67)
     Caused by: java.lang.SecurityException: Permission Denial: reading com.google.android.apps.photos.contentprovider.impl.MediaContentProvider uri content://com.google.android.apps.photos.contentprovider/-1/1/content:/media/external/images/media/25/REQUIRE_ORIGINAL/NONE/1614158544 from pid=21631, uid=10140 requires the provider be exported, or grantUriPermission()
        at android.os.Parcel.createException(Parcel.java:2071)
        at android.os.Parcel.readException(Parcel.java:2039)
        at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:188)
        at android.database.DatabaseUtils.readExceptionWithFileNotFoundExceptionFromParcel(DatabaseUtils.java:151)
        at android.content.ContentProviderProxy.openTypedAssetFile(ContentProviderNative.java:705)
        at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1687)
        at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:1503)
        at android.content.ContentResolver.openInputStream(ContentResolver.java:1187)
        at com.getcapacitor.plugin.Filesystem.getInputStream(Filesystem.java:114)
        at com.getcapacitor.plugin.Filesystem.readFile(Filesystem.java:174)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.getcapacitor.PluginHandle.invoke(PluginHandle.java:99)
        at com.getcapacitor.Bridge$1.run(Bridge.java:521)
        at android.os.Handler.handleCallback(Handler.java:883)
        at android.os.Handler.dispatchMessage(Handler.java:100)
        at android.os.Looper.loop(Looper.java:214)
        at android.os.HandlerThread.run(HandlerThread.java:67)

Expected Behavior

The expected behavior is : when I use this method : Filesystem.readFile({path}).then(console.log) the application doesn't stop/

Code Reproduction

Sorry, I will try later to make "working" project with this bug

Other Technical Details

npm --version 6.14.8:

node --version v12.18.2:

Additional Context

This seems to be an Android 10+ issue since they have implemented the scoped storage https://developer.android.com/training/data-storage#scoped-storage and I think my version of Filesystem plugin is not up to date with this mecanism, or I have to do some stuff before requesting the file...

Otherwise, I have these permissions in my AndroidManifest.xml :

cyril-colin commented 3 years ago

I had a problem with my build process... I fact all was working ! Sorry for useless issue !

ionitron-bot[bot] commented 1 year ago

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Capacitor, please create a new issue and ensure the template is fully filled out.