MTP: Use media provider database to implement MTP device support.
Uses a new "MTP objects" table in the media provider to support basic
enumeration of the external storage file system.
Support for accessing audio, video and image metadata in the existing
media provider tables will be added in a later commit.
The C++ MtpDatabase class is now abstract, to support a proxy subclass that
calls through JNI to the Java MtpDatabase class in the media provider.
Change-Id: I90f0db5f3acc5d35ae78c27a8507edff16d14305
Signed-off-by: Mike Lockwood <lockwood@android.com>
diff --git a/media/mtp/MtpServer.cpp b/media/mtp/MtpServer.cpp
index 3456815..967ebc9 100644
--- a/media/mtp/MtpServer.cpp
+++ b/media/mtp/MtpServer.cpp
@@ -113,11 +113,10 @@
// MTP_FORMAT_PLS_PLAYLIST,
};
-MtpServer::MtpServer(int fd, const char* databasePath,
+MtpServer::MtpServer(int fd, MtpDatabase* database,
int fileGroup, int filePerm, int directoryPerm)
: mFD(fd),
- mDatabasePath(databasePath),
- mDatabase(NULL),
+ mDatabase(database),
mFileGroup(fileGroup),
mFilePermission(filePerm),
mDirectoryPermission(directoryPerm),
@@ -126,9 +125,6 @@
mSendObjectHandle(kInvalidObjectHandle),
mSendObjectFileSize(0)
{
- mDatabase = new MtpSqliteDatabase();
- mDatabase->open(databasePath, true);
-
initObjectProperties();
}
@@ -427,6 +423,8 @@
MtpObjectFormat format = mRequest.getParameter(2); // 0 for all formats
MtpObjectHandle parent = mRequest.getParameter(3); // 0xFFFFFFFF for objects with no parent
// 0x00000000 for all objects?
+ if (parent == 0xFFFFFFFF)
+ parent = 0;
MtpObjectHandleList* handles = mDatabase->getObjectList(storageID, format, parent);
mData.putAUInt32(handles);
@@ -488,9 +486,10 @@
return MTP_RESPONSE_INVALID_STORAGE_ID;
// special case the root
- if (parent == MTP_PARENT_ROOT)
+ if (parent == MTP_PARENT_ROOT) {
path = storage->getPath();
- else {
+ parent = 0;
+ } else {
int64_t dummy;
if (!mDatabase->getObjectFilePath(parent, path, dummy))
return MTP_RESPONSE_INVALID_OBJECT_HANDLE;
@@ -549,7 +548,7 @@
}
mResponse.setParameter(1, storageID);
- mResponse.setParameter(2, parent);
+ mResponse.setParameter(2, (parent == 0 ? 0xFFFFFFFF: parent));
mResponse.setParameter(3, handle);
return MTP_RESPONSE_OK;