react-native-share: Odd exception logged (but still works)

Steps to reproduce

I’m getting the following logged into logcat:

2019-10-26 14:51:47.334 12395-12415/com.zinspector3.dev E/DatabaseUtils: Writing exception to parcel
    java.lang.SecurityException: Permission Denial: reading androidx.core.content.FileProvider uri content://com.zinspector3.dev.provider/files-path/thumbnails/sketch_4663036438425913034a7b74ddc-0579-4400-8c6c-5b00f2b12ffb.png from pid=17727, uid=1000 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)

Share still works, but I’m not sure why this is getting logged. This happens when sharing a file from the app’s storage. It’s curious that this happens even if grantUriPermissions is set to true.

I also have the following config:

Manifest:

<provider
          android:name="androidx.core.content.FileProvider"
          android:authorities="${applicationId}.provider"
          android:exported="false"
          android:grantUriPermissions="true">
          <meta-data
              android:name="android.support.FILE_PROVIDER_PATHS"
              android:resource="@xml/provider_paths"
            />
      </provider>

provider_paths:

<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
    <cache-path name="cache-path" path="" />
    <external-path
        name="external_files"
        path="." />
    <files-path
        name="files-path"
        path="." /> <!-- Used to access into application data files -->
</paths>

Did I miss anything?

Environment

  • React Native version: 0.60.5
  • React Native platform + platform version: Android 10

react-native-share

Version: 2.0.0

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 15 (3 by maintainers)

Most upvoted comments

I’m seeing this error as well. If I’m sharing a base64-encoded URL then it seems to work regardless. However if I’m sharing a PDF stored in files then when I see this error I can’t share the file.

Weirdly enough, it works sometimes. To me this suggests a race condition in how the permissions are granted on the intent. I don’t know enough about Android to debug this further, however.

I’ve been using master, currently at https://github.com/react-native-community/react-native-share/commit/d88e542ddd0983d09a4aa1a82737bb05b5731801. React Native 0.61.2. Testing on device, Android 10.

FWIW, since my files are fairly small, I’ve resorted to accessing them as base64-encoded strings.

Expand to read a short rant. ❤️ to the maintainers regardless.

This does my head in though: I need one package to access the data and bridge it into JavaScript, and then bridge it back into this package, which ends up writing it to disk (the Downloads directory). Sharing from there works because I imagine every App is allowed to read from that directory, at the cost of a permissions dialog before my App is allowed to write there. It’s not really a solution when the files are even slightly sensitive, however.