Modify Media provider such that app-shared picker-URIs can be accessed by the receiving app.
Test: pending
Bug: 262503735
Change-Id: I44a6f7e45345f6af0ee58bf0c738e350961f05f1
diff --git a/src/com/android/providers/media/MediaProvider.java b/src/com/android/providers/media/MediaProvider.java
index 35e65e0..8843dd0 100644
--- a/src/com/android/providers/media/MediaProvider.java
+++ b/src/com/android/providers/media/MediaProvider.java
@@ -3317,11 +3317,18 @@
}
if (isPickerUri(uri)) {
- // Do not allow implicit access (by the virtue of ownership/permission) to picker uris.
- // Picker uris should have explicit permission grants.
- // If the calling app A has an explicit grant on picker uri, UriGrantsManagerService
- // will check the grant status and allow app A to grant the uri to app B (without
- // calling into MediaProvider)
+ // If the Uri for which the permission needs to be checked is a picker Uri then query
+ // PickerUriResolver and verify if the data represented by the Uri still exists and is
+ // accessible then grant the permission, else deny it.
+ // TODO(b/276948648): Remove flag once changes are tested and verified.
+ if (mConfigStore.isGetContentTakeOverEnabled()) {
+ try (Cursor c = mPickerUriResolver.query(uri, new String[]{BaseColumns._ID},
+ mCallingIdentity.get().pid, uid, mCallingIdentity.get().getPackageName())) {
+ if (c != null && c.getCount() == 1) {
+ return PackageManager.PERMISSION_GRANTED;
+ }
+ }
+ }
return PackageManager.PERMISSION_DENIED;
}