Yalantis/uCrop

[BUG] SecurityException: No persistable permission grants found for UID

Drjacky opened this issue · 1 comments

What is the current behavior?
If you use both crop library and this code snippet:

contentResolver.takePersistableUriPermission(
                            galleryUri, takeFlags
                        )

you get the error: SecurityException: No persistable permission grants found for UID

What is the expected behavior?
If developer use or not use .crop, don't crash due to using takePersistableUriPermission.

2022-10-30 12:42:43.628 9648-9648/sample E/AndroidRuntime: FATAL EXCEPTION: main
    Process: sample, PID: 9648
    java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=639535455, result=-1, data=Intent { dat=file:///... (has extras) }} to activity {sample.MainActivity}: java.lang.SecurityException: No persistable permission grants found for UID 10177 and Uri file:///...
        at android.app.ActivityThread.deliverResults(ActivityThread.java:5347)
        at android.app.ActivityThread.handleSendResult(ActivityThread.java:5386)
        at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:67)
        at android.app.servertransaction.ActivityTransactionItem.execute(ActivityTransactionItem.java:45)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2308)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loopOnce(Looper.java:201)
        at android.os.Looper.loop(Looper.java:288)
        at android.app.ActivityThread.main(ActivityThread.java:7898)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
     Caused by: java.lang.SecurityException: No persistable permission grants found for UID 10177 and Uri file:///...
        at android.os.Parcel.createExceptionOrNull(Parcel.java:3011)
        at android.os.Parcel.createException(Parcel.java:2995)
        at android.os.Parcel.readException(Parcel.java:2978)
        at android.os.Parcel.readException(Parcel.java:2920)
        at android.app.IUriGrantsManager$Stub$Proxy.takePersistableUriPermission(IUriGrantsManager.java:249)
        at android.content.ContentResolver.takePersistableUriPermission(ContentResolver.java:2936)
        at sample.MainActivity.galleryLauncher$lambda-2(MainActivity.kt:55)
        at sample.MainActivity.$r8$lambda$ZkWtFZTk4SDiS3o04k4U88QfYrk(Unknown Source:0)
        at sample.MainActivity$$ExternalSyntheticLambda1.onActivityResult(Unknown Source:4)
        at androidx.activity.result.ActivityResultRegistry.doDispatch(ActivityResultRegistry.java:392)
        at androidx.activity.result.ActivityResultRegistry.dispatchResult(ActivityResultRegistry.java:351)
        at androidx.activity.ComponentActivity.onActivityResult(ComponentActivity.java:647)
        at androidx.fragment.app.FragmentActivity.onActivityResult(FragmentActivity.java:140)
        at android.app.Activity.dispatchActivityResult(Activity.java:8613)
        at android.app.ActivityThread.deliverResults(ActivityThread.java:5340)
        at android.app.ActivityThread.handleSendResult(ActivityThread.java:5386) 
        at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:67) 
        at android.app.servertransaction.ActivityTransactionItem.execute(ActivityTransactionItem.java:45) 
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2308) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loopOnce(Looper.java:201) 
        at android.os.Looper.loop(Looper.java:288) 
        at android.app.ActivityThread.main(ActivityThread.java:7898) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936Caused by: android.os.RemoteException: Remote stack trace:
        at com.android.server.uri.UriGrantsManagerService.takePersistableUriPermission(UriGrantsManagerService.java:376)
        at android.app.IUriGrantsManager$Stub.onTransact(IUriGrantsManager.java:139)
        at android.os.Binder.execTransactInternal(Binder.java:1280)
        at android.os.Binder.execTransact(Binder.java:1244)

Which versions of uCrop, and which Android API versions are affected by this issue? Did this work in previous versions of uCrop? 2.2.8

how can it be bypassed