From 51a14c09bcf981dbd1a04ca8eab69b1e8e0799d7 Mon Sep 17 00:00:00 2001 From: Jeff Sharkey Date: Wed, 6 May 2020 14:15:44 -0600 Subject: [PATCH] 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 --- .../com/android/server/uri/UriGrantsManagerService.java | 7 +++---- .../android/server/uri/UriGrantsManagerServiceTest.java | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/services/core/java/com/android/server/uri/UriGrantsManagerService.java b/services/core/java/com/android/server/uri/UriGrantsManagerService.java index 6734ce76675d0..72cdf4afb0078 100644 --- a/services/core/java/com/android/server/uri/UriGrantsManagerService.java +++ b/services/core/java/com/android/server/uri/UriGrantsManagerService.java @@ -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 diff --git a/services/tests/servicestests/src/com/android/server/uri/UriGrantsManagerServiceTest.java b/services/tests/servicestests/src/com/android/server/uri/UriGrantsManagerServiceTest.java index 0e48e7ed2682e..e86399e1a6312 100644 --- a/services/tests/servicestests/src/com/android/server/uri/UriGrantsManagerServiceTest.java +++ b/services/tests/servicestests/src/com/android/server/uri/UriGrantsManagerServiceTest.java @@ -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)); }