Skip to content

Permission Denial: opening provider ... from ProcessRecord{...} requires that you obtain access using ACTION_OPEN_DOCUMENT or related APIs #118

Closed
@afilp

Description

@afilp
    env: Android
    "react-native": "0.66.2",
    "react-native-blob-util": "^0.14.0",

I get the following error when trying to copy a video in order to upload it, using the new `copyToInternal" function:

          await ReactNativeBlobUtil.MediaCollection.copyToInternal(
            el.uri, // content uri of the entry in the media storage
            destpath, // path to destination the entry should be copied to
          )

The error is this:

Fatal Exception: java.lang.SecurityException: Permission Denial: opening provider com.android.providers.media.MediaDocumentsProvider from ProcessRecord{b94f6fd 12170:com.myapp.viewer/u0a658} (pid=12170, uid=10658) requires that you obtain access using ACTION_OPEN_DOCUMENT or related APIs
       at android.os.Parcel.createExceptionOrNull(Parcel.java:2376)
       at android.os.Parcel.createException(Parcel.java:2360)
       at android.os.Parcel.readException(Parcel.java:2343)
       at android.os.Parcel.readException(Parcel.java:2285)
       at android.app.IActivityManager$Stub$Proxy.getContentProvider(IActivityManager.java:5933)
       at android.app.ActivityThread.acquireProvider(ActivityThread.java:7185)
       at android.app.ContextImpl$ApplicationContentResolver.acquireUnstableProvider(ContextImpl.java:2954)
       at android.content.ContentResolver.acquireUnstableProvider(ContentResolver.java:2509)
       at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1994)
       at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:1825)
       at android.content.ContentResolver.openInputStream(ContentResolver.java:1502)
       at com.ReactNativeBlobUtil.ReactNativeBlobUtilMediaCollection.copyToInternal(ReactNativeBlobUtilMediaCollection.java:84)
       at com.ReactNativeBlobUtil.ReactNativeBlobUtil.copyToInternal(ReactNativeBlobUtil.java:4)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:148)
       at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:147)
       at com.facebook.react.bridge.queue.NativeRunnable.run(NativeRunnable.java)
       at android.os.Handler.handleCallback(Handler.java:938)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java)
       at android.os.Looper.loop(Looper.java:236)
       at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:37)
       at java.lang.Thread.run(Thread.java:923)
Caused by android.os.RemoteException: Remote stack trace:
	at com.android.server.am.ActivityManagerService.getContentProviderImpl(ActivityManagerService.java:7505)
	at com.android.server.am.ActivityManagerService.getContentProvider(ActivityManagerService.java:7969)
	at android.app.IActivityManager$Stub.onTransact(IActivityManager.java:2486)
	at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2981)
	at android.os.Binder.execTransactInternal(Binder.java:1162)

How?

I select a video with "react-native-image-picker".

I store its reference in AsyncStorage, for future uploading (the user may select photos/videos but close the app and re-open it later in order to upload the files):

    /*
    * Example of picked asset (video) in Android, saved in AsyncStorage to be retrieved later:
    *
      {
        "height": 320,
        "width": 568,
        "type": "video/mp4",
        "duration": 9,
        "fileName": "video:45544",
        "bitrate": 465939,
        "fileSize": 566583,
        "uri": "content://com.android.providers.media.documents/document/video%3A45544"
      }
    *
    * */

I re-open the app later, I do see the video's thumbnail in the UI (retrieved from AsyncStorage):
image

I start uploading.

When it goes to upload the video (photos work OK), the app crashes with above error.

This has to do something with the new "uri": "content:// logic.

  1. Is there something I can do to prevent this error?
  2. Is there a method (like "exists") to be used also with content:// uris? I suspect that maybe the actual file is not in the cache anymore (don't know why).

Thanks a lot!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions