summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Jeff Sharkey <jsharkey@android.com> 2020-05-06 14:15:44 -0600
committer Jeff Sharkey <jsharkey@android.com> 2020-05-06 14:15:46 -0600
commit51a14c09bcf981dbd1a04ca8eab69b1e8e0799d7 (patch)
tree51aa6569dcdee002cf72856fbfbad59dbe36e1e8
parent971448afb67e4f4b6db031fabc07a0802f45e480 (diff)
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
-rw-r--r--services/core/java/com/android/server/uri/UriGrantsManagerService.java7
-rw-r--r--services/tests/servicestests/src/com/android/server/uri/UriGrantsManagerServiceTest.java2
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 6734ce76675d..72cdf4afb007 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 0e48e7ed2682..e86399e1a631 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));
}