summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
authorMike Lockwood <lockwood@android.com>2010-07-03 00:44:05 -0400
committerMike Lockwood <lockwood@android.com>2010-07-08 16:21:09 -0400
commit1865a5ddcfe7b0e8dc211419aea1094b1491a5fd (patch)
tree7d5cf198bb5802a4e6faf0f58bccf1ddecd62ce7 /media
parentdda7e2b7378755637f188cca7c5ae854427a28f7 (diff)
downloadframeworks_av-1865a5ddcfe7b0e8dc211419aea1094b1491a5fd.zip
frameworks_av-1865a5ddcfe7b0e8dc211419aea1094b1491a5fd.tar.gz
frameworks_av-1865a5ddcfe7b0e8dc211419aea1094b1491a5fd.tar.bz2
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>
Diffstat (limited to 'media')
-rw-r--r--media/mtp/MtpDataPacket.cpp19
-rw-r--r--media/mtp/MtpDataPacket.h1
-rw-r--r--media/mtp/MtpServer.cpp17
-rw-r--r--media/mtp/MtpServer.h11
-rw-r--r--media/mtp/MtpSqliteDatabase.cpp1
-rw-r--r--media/mtp/mtptest.cpp5
6 files changed, 32 insertions, 22 deletions
diff --git a/media/mtp/MtpDataPacket.cpp b/media/mtp/MtpDataPacket.cpp
index a7e975c..6f9ea24 100644
--- a/media/mtp/MtpDataPacket.cpp
+++ b/media/mtp/MtpDataPacket.cpp
@@ -299,17 +299,28 @@ void MtpDataPacket::putAUInt64(const uint64_t* values, int count) {
putUInt64(*values++);
}
-void MtpDataPacket::putString(const MtpStringBuffer& string)
-{
+void MtpDataPacket::putString(const MtpStringBuffer& string) {
string.writeToPacket(this);
}
-void MtpDataPacket::putString(const char* s)
-{
+void MtpDataPacket::putString(const char* s) {
MtpStringBuffer string(s);
string.writeToPacket(this);
}
+void MtpDataPacket::putString(const uint16_t* string) {
+ int count = 0;
+ for (int i = 0; i < 256; i++) {
+ if (string[i])
+ count++;
+ else
+ break;
+ }
+ putUInt8(count);
+ for (int i = 0; i < count; i++)
+ putUInt16(string[i]);
+}
+
#ifdef MTP_DEVICE
int MtpDataPacket::read(int fd) {
// first read the header
diff --git a/media/mtp/MtpDataPacket.h b/media/mtp/MtpDataPacket.h
index 146ef64..759c0f9 100644
--- a/media/mtp/MtpDataPacket.h
+++ b/media/mtp/MtpDataPacket.h
@@ -79,6 +79,7 @@ public:
void putAUInt64(const uint64_t* values, int count);
void putString(const MtpStringBuffer& string);
void putString(const char* string);
+ void putString(const uint16_t* string);
inline void putEmptyString() { putUInt16(0); }
inline void putEmptyArray() { putUInt32(0); }
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 @@ static const MtpObjectFormat kSupportedPlaybackFormats[] = {
// 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 @@ MtpServer::MtpServer(int fd, const char* databasePath,
mSendObjectHandle(kInvalidObjectHandle),
mSendObjectFileSize(0)
{
- mDatabase = new MtpSqliteDatabase();
- mDatabase->open(databasePath, true);
-
initObjectProperties();
}
@@ -427,6 +423,8 @@ MtpResponseCode MtpServer::doGetObjectHandles() {
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 @@ MtpResponseCode MtpServer::doSendObjectInfo() {
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 @@ MtpResponseCode MtpServer::doSendObjectInfo() {
}
mResponse.setParameter(1, storageID);
- mResponse.setParameter(2, parent);
+ mResponse.setParameter(2, (parent == 0 ? 0xFFFFFFFF: parent));
mResponse.setParameter(3, handle);
return MTP_RESPONSE_OK;
diff --git a/media/mtp/MtpServer.h b/media/mtp/MtpServer.h
index 25635af..09556b3 100644
--- a/media/mtp/MtpServer.h
+++ b/media/mtp/MtpServer.h
@@ -26,9 +26,9 @@
namespace android {
-class MtpStorage;
-class MtpSqliteDatabase;
+class MtpDatabase;
class MtpProperty;
+class MtpStorage;
class MtpServer {
@@ -36,10 +36,7 @@ private:
// file descriptor for MTP kernel driver
int mFD;
- // path to our sqlite3 database
- const char* mDatabasePath;
-
- MtpSqliteDatabase* mDatabase;
+ MtpDatabase* mDatabase;
// group to own new files and folders
int mFileGroup;
@@ -67,7 +64,7 @@ private:
size_t mSendObjectFileSize;
public:
- MtpServer(int fd, const char* databasePath,
+ MtpServer(int fd, MtpDatabase* database,
int fileGroup, int filePerm, int directoryPerm);
virtual ~MtpServer();
diff --git a/media/mtp/MtpSqliteDatabase.cpp b/media/mtp/MtpSqliteDatabase.cpp
index c11ba50..eae9cb8 100644
--- a/media/mtp/MtpSqliteDatabase.cpp
+++ b/media/mtp/MtpSqliteDatabase.cpp
@@ -414,7 +414,6 @@ MtpObjectHandle* MtpSqliteDatabase::getFileList(int& outCount) {
SqliteStatement stmt(mDatabase);
stmt.prepare("SELECT count(*) FROM files;");
- MtpObjectHandleList* list = new MtpObjectHandleList();
if (stmt.step())
count = stmt.getColumnInt(0);
diff --git a/media/mtp/mtptest.cpp b/media/mtp/mtptest.cpp
index af0f77f..a2cb826 100644
--- a/media/mtp/mtptest.cpp
+++ b/media/mtp/mtptest.cpp
@@ -25,6 +25,7 @@
#include <sys/ioctl.h>
#include "MtpServer.h"
+#include "MtpSqliteDatabase.h"
#include "MtpStorage.h"
#include "f_mtp.h"
#include "private/android_filesystem_config.h"
@@ -77,7 +78,9 @@ int main(int argc, char* argv[]) {
enable_usb_function("usb_mass_storage", false);
enable_usb_function("mtp", true);
- MtpServer server(fd, "/data/data/mtp/mtp.db", AID_SDCARD_RW, 0664, 0775);
+ MtpSqliteDatabase* database = new MtpSqliteDatabase();
+ database->open("/data/data/mtp/mtp.db", true);
+ MtpServer server(fd, database, AID_SDCARD_RW, 0664, 0775);
server.addStorage(storagePath);
server.scanStorage();
server.run();