Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 51a14c09 authored by Jeff Sharkey's avatar Jeff Sharkey
Browse files

Fix logic inversion bug for "basicGrant".

Basic grants are defined to be one that only involve read/write
permissions, which we attempted to validate by checking for any other
flags, but there are many other (completely valid) flags that are
unrelated to Uri permissions.

Thus we invert the logic to look explicitly for the two specific
modes that cause a grant to be non-basic: persistable and prefix.

Update tests to verify the fix.

Bug: 155717493
Test: atest FrameworksServicesTests:com.android.server.uri
Change-Id: Ic8d7980d99bba59fb389d34f3bd054a9907df55c
parent 971448af
Loading
Loading
Loading
Loading
+3 −4
Original line number Diff line number Diff line
@@ -21,9 +21,8 @@ import static android.Manifest.permission.FORCE_PERSISTABLE_URI_PERMISSIONS;
import static android.Manifest.permission.GET_APP_GRANTED_URI_PERMISSIONS;
import static android.Manifest.permission.INTERACT_ACROSS_USERS;
import static android.app.ActivityManagerInternal.ALLOW_FULL_ONLY;
import static android.content.Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION;
import static android.content.Intent.FLAG_GRANT_PREFIX_URI_PERMISSION;
import static android.content.Intent.FLAG_GRANT_READ_URI_PERMISSION;
import static android.content.Intent.FLAG_GRANT_WRITE_URI_PERMISSION;
import static android.content.pm.PackageManager.MATCH_ANY_USER;
import static android.content.pm.PackageManager.MATCH_DEBUG_TRIAGED_MISSING;
import static android.content.pm.PackageManager.MATCH_DIRECT_BOOT_AWARE;
@@ -1138,8 +1137,8 @@ public class UriGrantsManagerService extends IUriGrantsManager.Stub {
            targetHoldsPermission = false;
        }

        final boolean basicGrant = (modeFlags & ~(FLAG_GRANT_READ_URI_PERMISSION
                | FLAG_GRANT_WRITE_URI_PERMISSION)) == 0;
        final boolean basicGrant = (modeFlags
                & (FLAG_GRANT_PERSISTABLE_URI_PERMISSION | FLAG_GRANT_PREFIX_URI_PERMISSION)) == 0;
        if (basicGrant && targetHoldsPermission) {
            // When caller holds permission, and this is a simple permission
            // grant, we can skip generating any bookkeeping; when any advanced
+1 −1
Original line number Diff line number Diff line
@@ -171,7 +171,7 @@ public class UriGrantsManagerServiceTest {
        final Uri uri = Uri.parse("content://" + PKG_COMPLEX + "/");
        {
            final Intent intent = new Intent(Intent.ACTION_VIEW, uri)
                    .addFlags(FLAG_READ);
                    .addFlags(FLAG_READ | Intent.FLAG_ACTIVITY_CLEAR_TASK);
            assertNull(mService.checkGrantUriPermissionFromIntent(UID_PRIMARY_COMPLEX, PKG_SOCIAL,
                    intent, intent.getFlags(), null, USER_PRIMARY));
        }