diff options
author | Jeff Sharkey <jsharkey@android.com> | 2018-10-22 18:01:27 -0600 |
---|---|---|
committer | Jeff Sharkey <jsharkey@android.com> | 2018-10-24 19:34:09 -0600 |
commit | 643e99ef060063c2cee2758ce6398d1f7a72b5e0 (patch) | |
tree | c8c331b1a972b4a81cb7dff6078df2fd7da0f602 /packages/ExternalStorageProvider/src | |
parent | c72a391e6369ec983f31909f76a2bb3598c0bb3c (diff) |
Reroute Uri conversions though MediaProvider.
Upcoming changes will prevent apps from reading "_data" columns
directly, which is required to convert between DocumentsProvider and
MediaProvider Uris. To solve this, delegate the call() through
MediaProvider, where it can perform the "_data" lookup on behalf
of the caller.
Also add new getMediaUri() call to offer symmetry.
Bug: 111960973, 117627072, 110961701
Test: atest android.provider.cts.MediaStoreUiTest
Change-Id: I53c640704d86047d7a4bf1702aca027873395abf
Diffstat (limited to 'packages/ExternalStorageProvider/src')
-rw-r--r-- | packages/ExternalStorageProvider/src/com/android/externalstorage/ExternalStorageProvider.java | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/packages/ExternalStorageProvider/src/com/android/externalstorage/ExternalStorageProvider.java b/packages/ExternalStorageProvider/src/com/android/externalstorage/ExternalStorageProvider.java index 62207c5517ec..4e52ff6d016c 100644 --- a/packages/ExternalStorageProvider/src/com/android/externalstorage/ExternalStorageProvider.java +++ b/packages/ExternalStorageProvider/src/com/android/externalstorage/ExternalStorageProvider.java @@ -37,6 +37,7 @@ import android.provider.DocumentsContract; import android.provider.DocumentsContract.Document; import android.provider.DocumentsContract.Path; import android.provider.DocumentsContract.Root; +import android.provider.MediaStore; import android.provider.Settings; import android.system.ErrnoException; import android.system.Os; @@ -606,11 +607,16 @@ public class ExternalStorageProvider extends FileSystemProvider { } break; } - case "getDocumentId": { - final String path = arg; - final List<UriPermission> accessUriPermissions = - extras.getParcelableArrayList(AUTHORITY + ".extra.uriPermissions"); + case MediaStore.GET_DOCUMENT_URI_CALL: { + // All callers must go through MediaProvider + getContext().enforceCallingPermission( + android.Manifest.permission.WRITE_MEDIA_STORAGE, TAG); + + final Uri fileUri = extras.getParcelable(DocumentsContract.EXTRA_URI); + final List<UriPermission> accessUriPermissions = extras + .getParcelableArrayList(DocumentsContract.EXTRA_URI_PERMISSIONS); + final String path = fileUri.getPath(); try { final Bundle out = new Bundle(); final Uri uri = getDocumentUri(path, accessUriPermissions); @@ -619,7 +625,22 @@ public class ExternalStorageProvider extends FileSystemProvider { } catch (FileNotFoundException e) { throw new IllegalStateException("File in " + path + " is not found.", e); } + } + case MediaStore.GET_MEDIA_URI_CALL: { + // All callers must go through MediaProvider + getContext().enforceCallingPermission( + android.Manifest.permission.WRITE_MEDIA_STORAGE, TAG); + final Uri documentUri = extras.getParcelable(DocumentsContract.EXTRA_URI); + final String docId = DocumentsContract.getDocumentId(documentUri); + try { + final Bundle out = new Bundle(); + final Uri uri = Uri.fromFile(getFileForDocId(docId)); + out.putParcelable(DocumentsContract.EXTRA_URI, uri); + return out; + } catch (FileNotFoundException e) { + throw new IllegalStateException(e); + } } default: Log.w(TAG, "unknown method passed to call(): " + method); |