AbedElazizShe / LightCompressor

A powerful and easy-to-use video compression library for android uses MediaCodec API.
Apache License 2.0
533 stars 116 forks source link

Crash with a PhotoPicker #189

Open akrulec opened 9 months ago

akrulec commented 9 months ago

We ask for reading permissions from media store before they can pick the image:

    fun canReadMediaStore(context: Context) =
        checkSelfPermission(context, READ_MEDIA_IMAGES) == PackageManager.PERMISSION_GRANTED &&
                checkSelfPermission(context, READ_MEDIA_VIDEO) == PackageManager.PERMISSION_GRANTED

But when we send that address to the video compressor library this still happens and the app crashes (eg. exception is NOT caught):

Fatal Exception: java.lang.SecurityException: Calling uid ( 10391 ) does not have permission to access picker uri: content://media/picker/0/com.android.providers.media.photopicker/media/1000006551
       at android.os.Parcel.createExceptionOrNull(Parcel.java:3057)
       at android.os.Parcel.createException(Parcel.java:3041)
       at android.os.Parcel.readException(Parcel.java:3024)
       at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:190)
       at android.database.DatabaseUtils.readExceptionWithFileNotFoundExceptionFromParcel(DatabaseUtils.java:153)
       at android.content.ContentProviderProxy.openTypedAssetFile(ContentProviderNative.java:814)
       at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:2043)
       at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:1858)
       at android.content.ContentResolver.openInputStream(ContentResolver.java:1528)
       at com.abedelazizshe.lightcompressorlibrary.VideoCompressor.getMediaPath(VideoCompressor.kt:369)
       at com.abedelazizshe.lightcompressorlibrary.VideoCompressor.access$getMediaPath(VideoCompressor.kt)
       at com.abedelazizshe.lightcompressorlibrary.VideoCompressor$doVideoCompression$1$job$1.invokeSuspend(VideoCompressor.kt:113)
       at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
       at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
       at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.kt:115)
       at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:100)
       at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt)
       at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:793)
       at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:697)
       at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt)