summaryrefslogtreecommitdiff
path: root/packages/ExternalStorageProvider
diff options
context:
space:
mode:
authorJeff Sharkey <jsharkey@android.com>2018-10-22 18:01:27 -0600
committerJeff Sharkey <jsharkey@android.com>2018-10-24 19:34:09 -0600
commit643e99ef060063c2cee2758ce6398d1f7a72b5e0 (patch)
treec8c331b1a972b4a81cb7dff6078df2fd7da0f602 /packages/ExternalStorageProvider
parentc72a391e6369ec983f31909f76a2bb3598c0bb3c (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')
-rw-r--r--packages/ExternalStorageProvider/AndroidManifest.xml4
-rw-r--r--packages/ExternalStorageProvider/src/com/android/externalstorage/ExternalStorageProvider.java29
2 files changed, 29 insertions, 4 deletions
diff --git a/packages/ExternalStorageProvider/AndroidManifest.xml b/packages/ExternalStorageProvider/AndroidManifest.xml
index 1072f95371a0..484dbccca9a8 100644
--- a/packages/ExternalStorageProvider/AndroidManifest.xml
+++ b/packages/ExternalStorageProvider/AndroidManifest.xml
@@ -17,6 +17,10 @@
<intent-filter>
<action android:name="android.content.action.DOCUMENTS_PROVIDER" />
</intent-filter>
+ <!-- Stub that allows MediaProvider to make incoming calls -->
+ <path-permission
+ android:path="/media_internal"
+ android:permission="android.permission.WRITE_MEDIA_STORAGE" />
</provider>
<receiver android:name=".MountReceiver">
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);