Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android max number of persistable uri permission granted to an app is limited to 128?

My application calls the Android image gallery through an intent and then the user can select multiple images. It turns out that the code listed below (already reported in other posts), works fine for me.

if(Utils.isKitkat())
{
    final int takeFlags = data.getFlags() & (Intent.FLAG_GRANT_READ_URI_PERMISSION);
    ContentResolver resolver = getActivity().getContentResolver();
    for (Uri uri : images)
    {
        resolver.takePersistableUriPermission(uri, takeFlags);
    }
}

Anyway I noticed that the max number of persistable uri granted to my app is limited to 128. If I select more than 128 uri, I get the error:

java.lang.SecurityException: Permission Denial: opening provider........

when I try to process an image for which I wasn't able to persist the permission. Is anyone aware of the limitation? Can you figure out any solution?

like image 961
David Avatar asked Nov 10 '22 11:11

David


1 Answers

I know this is an old post, but I'm running into the same issue in my app and so started looking through the Android source, and found: com.android.server.uri.UriGrantsManagerService, see this link.

It defines a private static final int MAX_PERSISTED_URI_GRANTS = 128;

I didn't trace through exactly how this is used, other than to notice the constant is used in a private method in that class, which gets called within the takePersistableUriPermission() method. So seems like the logical "culprit".

Given that this is a private static constant, I think until they decide to change it there is no "work-around".

I entered an enhancement request to track this here.

like image 150
tfrysinger Avatar answered Nov 15 '22 13:11

tfrysinger