diff options
-rw-r--r-- | media/java/android/mtp/MtpDatabase.java | 90 | ||||
-rw-r--r-- | media/mtp/MtpServer.cpp | 8 |
2 files changed, 70 insertions, 28 deletions
diff --git a/media/java/android/mtp/MtpDatabase.java b/media/java/android/mtp/MtpDatabase.java index c9e0f6f..4e271c7 100644 --- a/media/java/android/mtp/MtpDatabase.java +++ b/media/java/android/mtp/MtpDatabase.java @@ -92,13 +92,18 @@ public class MtpDatabase { }; private static final String ID_WHERE = Files.FileColumns._ID + "=?"; private static final String PATH_WHERE = Files.FileColumns.DATA + "=?"; - private static final String PARENT_WHERE = Files.FileColumns.PARENT + "=?"; - private static final String PARENT_FORMAT_WHERE = PARENT_WHERE + " AND " - + Files.FileColumns.FORMAT + "=?"; - private static final String PARENT_STORAGE_WHERE = PARENT_WHERE + " AND " - + Files.FileColumns.STORAGE_ID + "=?"; - private static final String PARENT_STORAGE_FORMAT_WHERE = PARENT_STORAGE_WHERE + " AND " + + private static final String STORAGE_WHERE = Files.FileColumns.STORAGE_ID + "=?"; + private static final String FORMAT_WHERE = Files.FileColumns.PARENT + "=?"; + private static final String PARENT_WHERE = Files.FileColumns.FORMAT + "=?"; + private static final String STORAGE_FORMAT_WHERE = STORAGE_WHERE + " AND " + Files.FileColumns.FORMAT + "=?"; + private static final String STORAGE_PARENT_WHERE = STORAGE_WHERE + " AND " + + Files.FileColumns.PARENT + "=?"; + private static final String FORMAT_PARENT_WHERE = FORMAT_WHERE + " AND " + + Files.FileColumns.PARENT + "=?"; + private static final String STORAGE_FORMAT_PARENT_WHERE = STORAGE_FORMAT_WHERE + " AND " + + Files.FileColumns.PARENT + "=?"; private final MediaScanner mMediaScanner; @@ -249,26 +254,67 @@ public class MtpDatabase { } private Cursor createObjectQuery(int storageID, int format, int parent) throws RemoteException { - if (storageID != 0) { - if (format != 0) { - return mMediaProvider.query(mObjectsUri, ID_PROJECTION, - PARENT_STORAGE_FORMAT_WHERE, - new String[] { Integer.toString(parent), Integer.toString(storageID), - Integer.toString(format) }, null); + if (storageID == 0xFFFFFFFF) { + // query all stores + if (format == 0) { + // query all formats + if (parent == 0) { + // query all objects + return mMediaProvider.query(mObjectsUri, ID_PROJECTION, null, null, null); + } + if (parent == 0xFFFFFFFF) { + // all objects in root of store + parent = 0; + } + return mMediaProvider.query(mObjectsUri, ID_PROJECTION, PARENT_WHERE, + new String[] { Integer.toString(parent) }, null); } else { - return mMediaProvider.query(mObjectsUri, ID_PROJECTION, - PARENT_STORAGE_WHERE, new String[] - { Integer.toString(parent), Integer.toString(storageID) }, null); + // query specific format + if (parent == 0) { + // query all objects + return mMediaProvider.query(mObjectsUri, ID_PROJECTION, FORMAT_WHERE, + new String[] { Integer.toString(format) }, null); + } + if (parent == 0xFFFFFFFF) { + // all objects in root of store + parent = 0; + } + return mMediaProvider.query(mObjectsUri, ID_PROJECTION, FORMAT_PARENT_WHERE, + new String[] { Integer.toString(format), Integer.toString(parent) }, null); } } else { - if (format != 0) { - return mMediaProvider.query(mObjectsUri, ID_PROJECTION, - PARENT_FORMAT_WHERE, - new String[] { Integer.toString(parent), Integer.toString(format) }, - null); + // query specific store + if (format == 0) { + // query all formats + if (parent == 0) { + // query all objects + return mMediaProvider.query(mObjectsUri, ID_PROJECTION, STORAGE_WHERE, + new String[] { Integer.toString(storageID) }, null); + } + if (parent == 0xFFFFFFFF) { + // all objects in root of store + parent = 0; + } + return mMediaProvider.query(mObjectsUri, ID_PROJECTION, STORAGE_PARENT_WHERE, + new String[] { Integer.toString(storageID), Integer.toString(parent) }, + null); } else { - return mMediaProvider.query(mObjectsUri, ID_PROJECTION, - PARENT_WHERE, new String[] { Integer.toString(parent) }, null); + // query specific format + if (parent == 0) { + // query all objects + return mMediaProvider.query(mObjectsUri, ID_PROJECTION, STORAGE_FORMAT_WHERE, + new String[] { Integer.toString(storageID), Integer.toString(format) }, + null); + } + if (parent == 0xFFFFFFFF) { + // all objects in root of store + parent = 0; + } + return mMediaProvider.query(mObjectsUri, ID_PROJECTION, STORAGE_FORMAT_PARENT_WHERE, + new String[] { Integer.toString(storageID), + Integer.toString(format), + Integer.toString(parent) }, + null); } } } diff --git a/media/mtp/MtpServer.cpp b/media/mtp/MtpServer.cpp index 4a8fd3e..9ec73c4 100644 --- a/media/mtp/MtpServer.cpp +++ b/media/mtp/MtpServer.cpp @@ -533,12 +533,10 @@ MtpResponseCode MtpServer::doGetObjectHandles() { MtpStorageID storageID = mRequest.getParameter(1); // 0xFFFFFFFF for all storage MtpObjectFormat format = mRequest.getParameter(2); // 0 for all formats MtpObjectHandle parent = mRequest.getParameter(3); // 0xFFFFFFFF for objects with no parent - // 0x00000000 for all objects? + // 0x00000000 for all objects if (!hasStorage(storageID)) return MTP_RESPONSE_INVALID_STORAGE_ID; - if (parent == 0xFFFFFFFF) - parent = 0; MtpObjectHandleList* handles = mDatabase->getObjectList(storageID, format, parent); mData.putAUInt32(handles); @@ -552,11 +550,9 @@ MtpResponseCode MtpServer::doGetNumObjects() { MtpStorageID storageID = mRequest.getParameter(1); // 0xFFFFFFFF for all storage MtpObjectFormat format = mRequest.getParameter(2); // 0 for all formats MtpObjectHandle parent = mRequest.getParameter(3); // 0xFFFFFFFF for objects with no parent - // 0x00000000 for all objects? + // 0x00000000 for all objects if (!hasStorage(storageID)) return MTP_RESPONSE_INVALID_STORAGE_ID; - if (parent == 0xFFFFFFFF) - parent = 0; int count = mDatabase->getNumObjects(storageID, format, parent); if (count >= 0) { |