Use separate Uris for MTP to the media provider files table
Separating the Uris for local and MTP access to the database will
allow us to handle MTP originated queries differently in the provider.
Change-Id: I78d1c0a0e656eddee1e17212a79157f67ca46b38
Signed-off-by: Mike Lockwood <lockwood@android.com>
diff --git a/core/java/android/provider/MediaStore.java b/core/java/android/provider/MediaStore.java
index 2b8a8e6..d3718f8 100644
--- a/core/java/android/provider/MediaStore.java
+++ b/core/java/android/provider/MediaStore.java
@@ -273,7 +273,9 @@
}
/**
- * Media provider interface used by MTP implementation.
+ * Media provider table containing an index of all files in the storage.
+ * This can be used by applications to find all documents of a particular type
+ * and is also used internally by the device side MTP implementation.
* @hide
*/
public static final class Files {
@@ -289,11 +291,22 @@
+ "/file/" + fileId);
}
- // used for MTP GetObjectReferences and SetObjectReferences
- public static final Uri getReferencesUri(String volumeName,
+ public static Uri getMtpObjectsUri(String volumeName) {
+ return Uri.parse(CONTENT_AUTHORITY_SLASH + volumeName +
+ "/object");
+ }
+
+ public static final Uri getMtpObjectsUri(String volumeName,
long fileId) {
return Uri.parse(CONTENT_AUTHORITY_SLASH + volumeName
- + "/file/" + fileId + "/references");
+ + "/object/" + fileId);
+ }
+
+ // Used to implement the MTP GetObjectReferences and SetObjectReferences commands.
+ public static final Uri getMtpReferencesUri(String volumeName,
+ long fileId) {
+ return Uri.parse(CONTENT_AUTHORITY_SLASH + volumeName
+ + "/object/" + fileId + "/references");
}
/**
diff --git a/media/java/android/media/MtpDatabase.java b/media/java/android/media/MtpDatabase.java
index 536d49f..ad029a6 100644
--- a/media/java/android/media/MtpDatabase.java
+++ b/media/java/android/media/MtpDatabase.java
@@ -89,7 +89,7 @@
mContext = context;
mMediaProvider = context.getContentResolver().acquireProvider("media");
mVolumeName = volumeName;
- mObjectsUri = Files.getContentUri(volumeName);
+ mObjectsUri = Files.getMtpObjectsUri(volumeName);
mMediaScanner = new MediaScanner(context);
openDevicePropertiesDatabase(context);
}
@@ -481,7 +481,7 @@
private int deleteFile(int handle) {
Log.d(TAG, "deleteFile: " + handle);
mDatabaseModified = true;
- Uri uri = Files.getContentUri(mVolumeName, handle);
+ Uri uri = Files.getMtpObjectsUri(mVolumeName, handle);
try {
if (mMediaProvider.delete(uri, null, null) == 1) {
return MtpConstants.RESPONSE_OK;
@@ -496,7 +496,7 @@
private int[] getObjectReferences(int handle) {
Log.d(TAG, "getObjectReferences for: " + handle);
- Uri uri = Files.getReferencesUri(mVolumeName, handle);
+ Uri uri = Files.getMtpReferencesUri(mVolumeName, handle);
Cursor c = null;
try {
c = mMediaProvider.query(uri, ID_PROJECTION, null, null, null);
@@ -524,7 +524,7 @@
private int setObjectReferences(int handle, int[] references) {
mDatabaseModified = true;
- Uri uri = Files.getReferencesUri(mVolumeName, handle);
+ Uri uri = Files.getMtpReferencesUri(mVolumeName, handle);
int count = references.length;
ContentValues[] valuesList = new ContentValues[count];
for (int i = 0; i < count; i++) {