summaryrefslogtreecommitdiffstats
path: root/media/mtp
diff options
context:
space:
mode:
authorMike Lockwood <lockwood@android.com>2010-07-09 10:45:22 -0400
committerMike Lockwood <lockwood@android.com>2010-07-09 11:07:55 -0400
commit7f53a190463274096155704276f3002c1620a364 (patch)
tree074ae70636a0169c5b07e15d1c8d64b99e564eba /media/mtp
parent723a540125f48aaf8a00b0cc5ed98fbbc01e5f14 (diff)
downloadframeworks_av-7f53a190463274096155704276f3002c1620a364.zip
frameworks_av-7f53a190463274096155704276f3002c1620a364.tar.gz
frameworks_av-7f53a190463274096155704276f3002c1620a364.tar.bz2
Remove some scafolding and test code that is no longer worth maintaining.
Change-Id: I9ee62d2463d8df1246a84774e8ac7e674778279a Signed-off-by: Mike Lockwood <lockwood@android.com>
Diffstat (limited to 'media/mtp')
-rw-r--r--media/mtp/Android.mk43
-rw-r--r--media/mtp/MtpDatabase.h5
-rw-r--r--media/mtp/MtpMediaScanner.cpp233
-rw-r--r--media/mtp/MtpMediaScanner.h52
-rw-r--r--media/mtp/MtpServer.cpp9
-rw-r--r--media/mtp/MtpServer.h1
-rw-r--r--media/mtp/MtpSqliteDatabase.cpp453
-rw-r--r--media/mtp/MtpSqliteDatabase.h80
-rw-r--r--media/mtp/MtpStorage.cpp6
-rw-r--r--media/mtp/MtpStorage.h3
-rw-r--r--media/mtp/MtpTypes.h5
-rw-r--r--media/mtp/SqliteDatabase.cpp88
-rw-r--r--media/mtp/SqliteDatabase.h50
-rw-r--r--media/mtp/SqliteStatement.cpp83
-rw-r--r--media/mtp/SqliteStatement.h56
-rw-r--r--media/mtp/mtptest.cpp91
-rw-r--r--media/mtp/scantest.cpp38
17 files changed, 1 insertions, 1295 deletions
diff --git a/media/mtp/Android.mk b/media/mtp/Android.mk
index e523815..174ea36 100644
--- a/media/mtp/Android.mk
+++ b/media/mtp/Android.mk
@@ -24,62 +24,19 @@ LOCAL_SRC_FILES:= \
MtpDebug.cpp \
MtpDevice.cpp \
MtpDeviceInfo.cpp \
- MtpMediaScanner.cpp \
MtpObjectInfo.cpp \
MtpPacket.cpp \
MtpProperty.cpp \
MtpRequestPacket.cpp \
MtpResponsePacket.cpp \
MtpServer.cpp \
- MtpSqliteDatabase.cpp \
MtpStorageInfo.cpp \
MtpStringBuffer.cpp \
MtpStorage.cpp \
MtpUtils.cpp \
- SqliteDatabase.cpp \
- SqliteStatement.cpp \
LOCAL_MODULE:= libmtp
-LOCAL_C_INCLUDES := external/sqlite/dist
-
LOCAL_CFLAGS := -DMTP_DEVICE -DMTP_HOST
include $(BUILD_STATIC_LIBRARY)
-
-ifneq ($(TARGET_SIMULATOR),true)
-
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES:= \
- mtptest.cpp \
-
-LOCAL_MODULE:= mtptest
-
-LOCAL_CFLAGS := -DMTP_DEVICE
-
-LOCAL_SHARED_LIBRARIES := libutils libsqlite libcutils \
- libmedia
-
-LOCAL_STATIC_LIBRARIES := libmtp
-
-include $(BUILD_EXECUTABLE)
-
-include $(CLEAR_VARS)
-
-LOCAL_MODULE := scantest
-LOCAL_SRC_FILES:= \
- scantest.cpp \
-
-
-LOCAL_STATIC_LIBRARIES := libmtp
-
-LOCAL_C_INCLUDES := external/sqlite/dist
-LOCAL_SHARED_LIBRARIES := libutils libsqlite libmedia
-
-LOCAL_CFLAGS := -g
-LOCAL_LDFLAGS := -g
-
-include $(BUILD_EXECUTABLE)
-
-endif
diff --git a/media/mtp/MtpDatabase.h b/media/mtp/MtpDatabase.h
index a6aaf0f..1566a11 100644
--- a/media/mtp/MtpDatabase.h
+++ b/media/mtp/MtpDatabase.h
@@ -18,7 +18,6 @@
#define _MTP_DATABASE_H
#include "MtpTypes.h"
-#include "SqliteDatabase.h"
namespace android {
@@ -28,7 +27,6 @@ class MtpDatabase {
public:
virtual ~MtpDatabase() {}
- virtual MtpObjectHandle getObjectHandle(const char* path) = 0;
virtual MtpObjectHandle addFile(const char* path,
MtpObjectFormat format,
MtpObjectHandle parent,
@@ -52,9 +50,6 @@ public:
int64_t& fileLength) = 0;
virtual bool deleteFile(MtpObjectHandle handle) = 0;
- // helper for media scanner
- virtual MtpObjectHandle* getFileList(int& outCount) = 0;
-
virtual void beginTransaction() = 0;
virtual void commitTransaction() = 0;
virtual void rollbackTransaction() = 0;
diff --git a/media/mtp/MtpMediaScanner.cpp b/media/mtp/MtpMediaScanner.cpp
deleted file mode 100644
index a9adf01..0000000
--- a/media/mtp/MtpMediaScanner.cpp
+++ /dev/null
@@ -1,233 +0,0 @@
-/*
- * Copyright (C) 2010 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#define LOG_TAG "MtpMediaScanner"
-
-#include "MtpDebug.h"
-#include "MtpDatabase.h"
-#include "MtpMediaScanner.h"
-#include "mtp.h"
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/statfs.h>
-#include <unistd.h>
-#include <dirent.h>
-#include <errno.h>
-#include <string.h>
-#include <stdio.h>
-#include <limits.h>
-
-namespace android {
-
-MtpMediaScanner::MtpMediaScanner(MtpStorageID id, const char* filePath, MtpDatabase* db)
- : mStorageID(id),
- mFilePath(filePath),
- mDatabase(db),
- mFileList(NULL),
- mFileCount(0)
-{
-}
-
-MtpMediaScanner::~MtpMediaScanner() {
-}
-
-bool MtpMediaScanner::scanFiles() {
- mDatabase->beginTransaction();
- mFileCount = 0;
- mFileList = mDatabase->getFileList(mFileCount);
-
- int ret = scanDirectory(mFilePath, MTP_PARENT_ROOT);
-
- for (int i = 0; i < mFileCount; i++) {
- MtpObjectHandle test = mFileList[i];
- if (! (test & kObjectHandleMarkBit)) {
- LOGV("delete missing file %08X", test);
- mDatabase->deleteFile(test);
- }
- }
-
- delete[] mFileList;
- mFileCount = 0;
- mDatabase->commitTransaction();
- return (ret == 0);
-}
-
-
-static const struct MediaFileTypeEntry
-{
- const char* extension;
- MtpObjectFormat format;
-} sFileTypes[] =
-{
- { "MP3", MTP_FORMAT_MP3, },
- { "M4A", MTP_FORMAT_UNDEFINED_AUDIO, },
- { "WAV", MTP_FORMAT_WAV, },
- { "AMR", MTP_FORMAT_UNDEFINED_AUDIO, },
- { "AWB", MTP_FORMAT_UNDEFINED_AUDIO, },
- { "WMA", MTP_FORMAT_WMA, },
- { "OGG", MTP_FORMAT_OGG, },
- { "OGA", MTP_FORMAT_UNDEFINED_AUDIO, },
- { "AAC", MTP_FORMAT_AAC, },
- { "MID", MTP_FORMAT_UNDEFINED_AUDIO, },
- { "MIDI", MTP_FORMAT_UNDEFINED_AUDIO, },
- { "XMF", MTP_FORMAT_UNDEFINED_AUDIO, },
- { "RTTTL", MTP_FORMAT_UNDEFINED_AUDIO, },
- { "SMF", MTP_FORMAT_UNDEFINED_AUDIO, },
- { "IMY", MTP_FORMAT_UNDEFINED_AUDIO, },
- { "RTX", MTP_FORMAT_UNDEFINED_AUDIO, },
- { "OTA", MTP_FORMAT_UNDEFINED_AUDIO, },
- { "MPEG", MTP_FORMAT_UNDEFINED_VIDEO, },
- { "MP4", MTP_FORMAT_UNDEFINED_VIDEO, },
- { "M4V", MTP_FORMAT_UNDEFINED_VIDEO, },
- { "3GP", MTP_FORMAT_UNDEFINED_VIDEO, },
- { "3GPP", MTP_FORMAT_UNDEFINED_VIDEO, },
- { "3G2", MTP_FORMAT_UNDEFINED_VIDEO, },
- { "3GPP2", MTP_FORMAT_UNDEFINED_VIDEO, },
- { "WMV", MTP_FORMAT_UNDEFINED_VIDEO, },
- { "ASF", MTP_FORMAT_UNDEFINED_VIDEO, },
- { "JPG", MTP_FORMAT_EXIF_JPEG, },
- { "JPEG", MTP_FORMAT_EXIF_JPEG, },
- { "GIF", MTP_FORMAT_GIF, },
- { "PNG", MTP_FORMAT_PNG, },
- { "BMP", MTP_FORMAT_BMP, },
- { "WBMP", MTP_FORMAT_BMP, },
- { "M3U", MTP_FORMAT_M3U_PLAYLIST, },
- { "PLS", MTP_FORMAT_PLS_PLAYLIST, },
- { "WPL", MTP_FORMAT_WPL_PLAYLIST, },
-};
-
-MtpObjectFormat MtpMediaScanner::getFileFormat(const char* path)
-{
- const char* extension = strrchr(path, '.');
- if (!extension)
- return MTP_FORMAT_UNDEFINED;
- extension++; // skip the dot
-
- for (unsigned i = 0; i < sizeof(sFileTypes) / sizeof(sFileTypes[0]); i++) {
- if (!strcasecmp(extension, sFileTypes[i].extension)) {
- return sFileTypes[i].format;
- }
- }
- return MTP_FORMAT_UNDEFINED;
-}
-
-int MtpMediaScanner::scanDirectory(const char* path, MtpObjectHandle parent)
-{
- char buffer[PATH_MAX];
- struct dirent* entry;
-
- unsigned length = strlen(path);
- if (length > sizeof(buffer) + 2) {
- LOGE("path too long: %s", path);
- }
-
- DIR* dir = opendir(path);
- if (!dir) {
- LOGE("opendir %s failed, errno: %d", path, errno);
- return -1;
- }
-
- strncpy(buffer, path, sizeof(buffer));
- char* fileStart = buffer + length;
- // make sure we have a trailing slash
- if (fileStart[-1] != '/') {
- *(fileStart++) = '/';
- }
- int fileNameLength = sizeof(buffer) + fileStart - buffer;
-
- while ((entry = readdir(dir))) {
- const char* name = entry->d_name;
-
- // ignore "." and "..", as well as any files or directories staring with dot
- if (name[0] == '.') {
- continue;
- }
- if (strlen(name) + 1 > fileNameLength) {
- LOGE("path too long for %s", name);
- continue;
- }
- strcpy(fileStart, name);
-
- struct stat statbuf;
- memset(&statbuf, 0, sizeof(statbuf));
- stat(buffer, &statbuf);
-
- if (S_ISDIR(statbuf.st_mode)) {
- MtpObjectHandle handle = mDatabase->getObjectHandle(buffer);
- if (handle) {
- markFile(handle);
- } else {
- handle = mDatabase->addFile(buffer, MTP_FORMAT_ASSOCIATION,
- parent, mStorageID, 0, statbuf.st_mtime);
- }
- scanDirectory(buffer, handle);
- } else if (S_ISREG(statbuf.st_mode)) {
- scanFile(buffer, parent, statbuf);
- }
- }
-
- closedir(dir);
- return 0;
-}
-
-void MtpMediaScanner::scanFile(const char* path, MtpObjectHandle parent, struct stat& statbuf) {
- MtpObjectFormat format = getFileFormat(path);
- // don't scan unknown file types
- if (format == MTP_FORMAT_UNDEFINED)
- return;
- MtpObjectHandle handle = mDatabase->getObjectHandle(path);
- // fixme - rescan if mod date changed
- if (handle) {
- markFile(handle);
- } else {
- mDatabase->beginTransaction();
- handle = mDatabase->addFile(path, format, parent, mStorageID,
- statbuf.st_size, statbuf.st_mtime);
- if (handle <= 0) {
- LOGE("addFile failed in MtpMediaScanner::scanFile()");
- mDatabase->rollbackTransaction();
- return;
- }
- mDatabase->commitTransaction();
- }
-}
-
-void MtpMediaScanner::markFile(MtpObjectHandle handle) {
- if (mFileList) {
- handle &= kObjectHandleIndexMask;
- // binary search for the file in mFileList
- int low = 0;
- int high = mFileCount;
- int index;
-
- while (low < high) {
- index = (low + high) >> 1;
- MtpObjectHandle test = (mFileList[index] & kObjectHandleIndexMask);
- if (handle < test)
- high = index; // item is less than index
- else if (handle > test)
- low = index + 1; // item is greater than index
- else {
- mFileList[index] |= kObjectHandleMarkBit;
- return;
- }
- }
- LOGE("file %d not found in mFileList", handle);
- }
-}
-
-} // namespace android
diff --git a/media/mtp/MtpMediaScanner.h b/media/mtp/MtpMediaScanner.h
deleted file mode 100644
index 9cf10c5..0000000
--- a/media/mtp/MtpMediaScanner.h
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright (C) 2010 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _MTP_MEDIA_SCANNER_H
-#define _MTP_MEDIA_SCANNER_H
-
-struct stat;
-
-namespace android {
-
-class MtpDatabase;
-class SqliteStatement;
-
-class MtpMediaScanner {
-private:
- MtpStorageID mStorageID;
- const char* mFilePath;
- MtpDatabase* mDatabase;
-
- // for garbage collecting missing files
- MtpObjectHandle* mFileList;
- int mFileCount;
-
-public:
- MtpMediaScanner(MtpStorageID id, const char* filePath, MtpDatabase* db);
- virtual ~MtpMediaScanner();
-
- bool scanFiles();
-
-private:
- MtpObjectFormat getFileFormat(const char* path);
- int scanDirectory(const char* path, MtpObjectHandle parent);
- void scanFile(const char* path, MtpObjectHandle parent, struct stat& statbuf);
- void markFile(MtpObjectHandle handle);
-};
-
-}; // namespace android
-
-#endif // _MTP_MEDIA_SCANNER_H
diff --git a/media/mtp/MtpServer.cpp b/media/mtp/MtpServer.cpp
index 967ebc9..5a16a03 100644
--- a/media/mtp/MtpServer.cpp
+++ b/media/mtp/MtpServer.cpp
@@ -25,9 +25,9 @@
#include <cutils/properties.h>
#include "MtpDebug.h"
+#include "MtpDatabase.h"
#include "MtpProperty.h"
#include "MtpServer.h"
-#include "MtpSqliteDatabase.h"
#include "MtpStorage.h"
#include "MtpStringBuffer.h"
@@ -147,13 +147,6 @@ MtpStorage* MtpServer::getStorage(MtpStorageID id) {
return NULL;
}
-void MtpServer::scanStorage() {
- for (int i = 0; i < mStorages.size(); i++) {
- MtpStorage* storage = mStorages[i];
- storage->scanFiles();
- }
-}
-
void MtpServer::run() {
int fd = mFD;
diff --git a/media/mtp/MtpServer.h b/media/mtp/MtpServer.h
index 09556b3..afba846 100644
--- a/media/mtp/MtpServer.h
+++ b/media/mtp/MtpServer.h
@@ -71,7 +71,6 @@ public:
void addStorage(const char* filePath);
inline void addStorage(MtpStorage* storage) { mStorages.push(storage); }
MtpStorage* getStorage(MtpStorageID id);
- void scanStorage();
void run();
MtpProperty* getObjectProperty(MtpPropertyCode propCode);
diff --git a/media/mtp/MtpSqliteDatabase.cpp b/media/mtp/MtpSqliteDatabase.cpp
deleted file mode 100644
index eae9cb8..0000000
--- a/media/mtp/MtpSqliteDatabase.cpp
+++ /dev/null
@@ -1,453 +0,0 @@
-/*
- * Copyright (C) 2010 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#define LOG_TAG "MtpSqliteDatabase"
-
-#include "MtpDebug.h"
-#include "MtpSqliteDatabase.h"
-#include "MtpDataPacket.h"
-#include "MtpUtils.h"
-#include "SqliteDatabase.h"
-#include "SqliteStatement.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <sqlite3.h>
-
-namespace android {
-
-#define FILE_ID_COLUMN 1
-#define FILE_PATH_COLUMN 2
-#define FILE_FORMAT_COLUMN 3
-#define FILE_PARENT_COLUMN 4
-#define FILE_STORAGE_COLUMN 5
-#define FILE_SIZE_COLUMN 6
-#define FILE_MODIFIED_COLUMN 7
-
-#define FILE_TABLE_CREATE "CREATE TABLE IF NOT EXISTS files (" \
- "_id INTEGER PRIMARY KEY," \
- "path TEXT," \
- "format INTEGER," \
- "parent INTEGER," \
- "storage INTEGER," \
- "size INTEGER," \
- "date_modified INTEGER" \
- ");"
-
-#define PATH_INDEX_CREATE "CREATE INDEX IF NOT EXISTS path_index on files(path);"
-
-#define FILE_ID_QUERY "SELECT _id,format FROM files WHERE path = ?;"
-#define FILE_PATH_QUERY "SELECT path,size FROM files WHERE _id = ?"
-
-#define GET_OBJECT_INFO_QUERY "SELECT storage,format,parent,path,size,date_modified FROM files WHERE _id = ?;"
-#define FILE_INSERT "INSERT INTO files VALUES(?,?,?,?,?,?,?);"
-#define FILE_DELETE "DELETE FROM files WHERE _id = ?;"
-
-struct PropertyTableEntry {
- MtpObjectProperty property;
- int type;
- const char* columnName;
-};
-
-static const PropertyTableEntry kPropertyTable[] = {
- { MTP_PROPERTY_PARENT_OBJECT, MTP_TYPE_UINT32, "parent" },
- { MTP_PROPERTY_STORAGE_ID, MTP_TYPE_UINT32, "storage" },
- { MTP_PROPERTY_OBJECT_FORMAT, MTP_TYPE_UINT32, "format" },
- { MTP_PROPERTY_OBJECT_FILE_NAME, MTP_TYPE_STR, "path" },
- { MTP_PROPERTY_OBJECT_SIZE, MTP_TYPE_UINT64, "size" },
- { MTP_PROPERTY_DATE_MODIFIED, MTP_TYPE_STR, "date_modified" },
-};
-
-static bool getPropertyInfo(MtpObjectProperty property, int& type, const char*& columnName) {
- int count = sizeof(kPropertyTable) / sizeof(kPropertyTable[0]);
- const PropertyTableEntry* entry = kPropertyTable;
- for (int i = 0; i < count; i++, entry++) {
- if (entry->property == property) {
- type = entry->type;
- columnName = entry->columnName;
- return true;
- }
- }
- return false;
-}
-
-MtpSqliteDatabase::MtpSqliteDatabase()
- : mDatabase(NULL),
- mFileIdQuery(NULL),
- mFilePathQuery(NULL),
- mObjectInfoQuery(NULL),
- mFileInserter(NULL),
- mFileDeleter(NULL)
-{
-}
-
-MtpSqliteDatabase::~MtpSqliteDatabase() {
- delete mDatabase;
- delete mFileIdQuery;
- delete mFilePathQuery;
- delete mObjectInfoQuery;
- delete mFileInserter;
- delete mFileDeleter;
-}
-
-bool MtpSqliteDatabase::open(const char* path, bool create) {
- mDatabase = new SqliteDatabase;
-
- if (!mDatabase->open(path, create))
- goto fail;
-
- // create tables and indices if necessary
- if (!mDatabase->exec(FILE_TABLE_CREATE)) {
- LOGE("could not create file table");
- goto fail;
- }
- if (!mDatabase->exec(PATH_INDEX_CREATE)) {
- LOGE("could not path index on file table");
- goto fail;
- }
-
- if (!mFileIdQuery) {
- mFileIdQuery = new SqliteStatement(mDatabase);
- if (!mFileIdQuery->prepare(FILE_ID_QUERY)) {
- LOGE("could not compile FILE_ID_QUERY");
- goto fail;
- }
- }
- if (!mFilePathQuery) {
- mFilePathQuery = new SqliteStatement(mDatabase);
- if (!mFilePathQuery->prepare(FILE_PATH_QUERY)) {
- LOGE("could not compile FILE_PATH_QUERY");
- goto fail;
- }
- }
- if (!mObjectInfoQuery) {
- mObjectInfoQuery = new SqliteStatement(mDatabase);
- if (!mObjectInfoQuery->prepare(GET_OBJECT_INFO_QUERY)) {
- LOGE("could not compile GET_OBJECT_INFO_QUERY");
- goto fail;
- }
- }
- if (!mFileInserter) {
- mFileInserter = new SqliteStatement(mDatabase);
- if (!mFileInserter->prepare(FILE_INSERT)) {
- LOGE("could not compile FILE_INSERT\n");
- goto fail;
- }
- }
- if (!mFileDeleter) {
- mFileDeleter = new SqliteStatement(mDatabase);
- if (!mFileDeleter->prepare(FILE_DELETE)) {
- LOGE("could not compile FILE_DELETE\n");
- goto fail;
- }
- }
-
- return true;
-
-fail:
- delete mDatabase;
- delete mFileIdQuery;
- delete mFilePathQuery;
- delete mObjectInfoQuery;
- delete mFileInserter;
- delete mFileDeleter;
- mDatabase = NULL;
- mFileIdQuery = NULL;
- mFilePathQuery = NULL;
- mObjectInfoQuery = NULL;
- mFileInserter = NULL;
- mFileDeleter = NULL;
- return false;
-}
-
-void MtpSqliteDatabase::close() {
- if (mDatabase) {
- mDatabase->close();
- mDatabase = NULL;
- }
-}
-
-MtpObjectHandle MtpSqliteDatabase::getObjectHandle(const char* path) {
- mFileIdQuery->reset();
- mFileIdQuery->bind(1, path);
- if (mFileIdQuery->step()) {
- int row = mFileIdQuery->getColumnInt(0);
- if (row > 0) {
- MtpObjectFormat format = mFileIdQuery->getColumnInt(1);
- return row;
- }
- }
-
- return 0;
-}
-
-MtpObjectHandle MtpSqliteDatabase::addFile(const char* path,
- MtpObjectFormat format,
- MtpObjectHandle parent,
- MtpStorageID storage,
- uint64_t size,
- time_t modified) {
- mFileInserter->bind(FILE_PATH_COLUMN, path);
- mFileInserter->bind(FILE_FORMAT_COLUMN, format);
- mFileInserter->bind(FILE_PARENT_COLUMN, parent);
- mFileInserter->bind(FILE_STORAGE_COLUMN, storage);
- mFileInserter->bind(FILE_SIZE_COLUMN, size);
- mFileInserter->bind(FILE_MODIFIED_COLUMN, modified);
- mFileInserter->step();
- mFileInserter->reset();
- int result = mDatabase->lastInsertedRow();
- return (result <= 0 ? kInvalidObjectHandle : result);
-}
-
-MtpObjectHandleList* MtpSqliteDatabase::getObjectList(MtpStorageID storageID,
- MtpObjectFormat format,
- MtpObjectHandle parent) {
- bool whereStorage = (storageID != 0xFFFFFFFF);
- bool whereFormat = (format != 0);
- bool whereParent = (parent != 0);
- char intBuffer[20];
-
- MtpString query("SELECT _id,format FROM files");
- if (whereStorage || whereFormat || whereParent)
- query += " WHERE";
- if (whereStorage) {
- snprintf(intBuffer, sizeof(intBuffer), "%d", storageID);
- query += " storage = ";
- query += intBuffer;
- }
- if (whereFormat) {
- snprintf(intBuffer, sizeof(intBuffer), "%d", format);
- if (whereStorage)
- query += " AND";
- query += " format = ";
- query += intBuffer;
- }
- if (whereParent) {
- if (parent != MTP_PARENT_ROOT)
- parent &= kObjectHandleIndexMask;
- snprintf(intBuffer, sizeof(intBuffer), "%d", parent);
- if (whereStorage || whereFormat)
- query += " AND";
- query += " parent = ";
- query += intBuffer;
- }
- query += ";";
-
- SqliteStatement stmt(mDatabase);
- LOGV("%s", (const char *)query);
- stmt.prepare(query);
-
- MtpObjectHandleList* list = new MtpObjectHandleList();
- while (!stmt.isDone()) {
- if (stmt.step()) {
- int index = stmt.getColumnInt(0);
- LOGV("stmt.getColumnInt returned %d", index);
- if (index > 0) {
- MtpObjectFormat format = stmt.getColumnInt(1);
- list->push(index);
- }
- }
- }
- LOGV("list size: %d", list->size());
- return list;
-}
-
-
-MtpResponseCode MtpSqliteDatabase::getObjectProperty(MtpObjectHandle handle,
- MtpObjectProperty property,
- MtpDataPacket& packet) {
- int type;
- const char* columnName;
- char intBuffer[20];
-
- if (handle != MTP_PARENT_ROOT)
- handle &= kObjectHandleIndexMask;
-
- if (!getPropertyInfo(property, type, columnName))
- return MTP_RESPONSE_INVALID_OBJECT_PROP_CODE;
- snprintf(intBuffer, sizeof(intBuffer), "%d", handle);
-
- MtpString query("SELECT ");
- query += columnName;
- query += " FROM files WHERE _id = ";
- query += intBuffer;
- query += ";";
-
- SqliteStatement stmt(mDatabase);
- LOGV("%s", (const char *)query);
- stmt.prepare(query);
-
- if (!stmt.step())
- return MTP_RESPONSE_INVALID_OBJECT_HANDLE;
-
- switch (type) {
- case MTP_TYPE_INT8:
- packet.putInt8(stmt.getColumnInt(0));
- break;
- case MTP_TYPE_UINT8:
- packet.putUInt8(stmt.getColumnInt(0));
- break;
- case MTP_TYPE_INT16:
- packet.putInt16(stmt.getColumnInt(0));
- break;
- case MTP_TYPE_UINT16:
- packet.putUInt16(stmt.getColumnInt(0));
- break;
- case MTP_TYPE_INT32:
- packet.putInt32(stmt.getColumnInt(0));
- break;
- case MTP_TYPE_UINT32:
- packet.putUInt32(stmt.getColumnInt(0));
- break;
- case MTP_TYPE_INT64:
- packet.putInt64(stmt.getColumnInt64(0));
- break;
- case MTP_TYPE_UINT64:
- packet.putUInt64(stmt.getColumnInt64(0));
- break;
- case MTP_TYPE_STR:
- packet.putString(stmt.getColumnString(0));
- break;
- default:
- LOGE("unsupported object type\n");
- return MTP_RESPONSE_INVALID_OBJECT_HANDLE;
- }
- return MTP_RESPONSE_OK;
-}
-
-MtpResponseCode MtpSqliteDatabase::getObjectInfo(MtpObjectHandle handle,
- MtpDataPacket& packet) {
- char date[20];
-
- if (handle != MTP_PARENT_ROOT)
- handle &= kObjectHandleIndexMask;
-
- mObjectInfoQuery->reset();
- mObjectInfoQuery->bind(1, handle);
- if (!mObjectInfoQuery->step())
- return MTP_RESPONSE_INVALID_OBJECT_HANDLE;
-
- MtpStorageID storageID = mObjectInfoQuery->getColumnInt(0);
- MtpObjectFormat format = mObjectInfoQuery->getColumnInt(1);
- MtpObjectHandle parent = mObjectInfoQuery->getColumnInt(2);
- // extract name from path. do we want a separate database entry for this?
- const char* name = mObjectInfoQuery->getColumnString(3);
- const char* lastSlash = strrchr(name, '/');
- if (lastSlash)
- name = lastSlash + 1;
- int64_t size = mObjectInfoQuery->getColumnInt64(4);
- time_t modified = mObjectInfoQuery->getColumnInt(5);
- int associationType = (format == MTP_FORMAT_ASSOCIATION ?
- MTP_ASSOCIATION_TYPE_GENERIC_FOLDER :
- MTP_ASSOCIATION_TYPE_UNDEFINED);
-
- LOGV("storageID: %d, format: %d, parent: %d", storageID, format, parent);
-
- packet.putUInt32(storageID);
- packet.putUInt16(format);
- packet.putUInt16(0); // protection status
- packet.putUInt32((size > 0xFFFFFFFFLL ? 0xFFFFFFFF : size));
- packet.putUInt16(0); // thumb format
- packet.putUInt32(0); // thumb compressed size
- packet.putUInt32(0); // thumb pix width
- packet.putUInt32(0); // thumb pix height
- packet.putUInt32(0); // image pix width
- packet.putUInt32(0); // image pix height
- packet.putUInt32(0); // image bit depth
- packet.putUInt32(parent);
- packet.putUInt16(associationType);
- packet.putUInt32(0); // association desc
- packet.putUInt32(0); // sequence number
- packet.putString(name); // file name
- packet.putEmptyString();
- formatDateTime(modified, date, sizeof(date));
- packet.putString(date); // date modified
- packet.putEmptyString(); // keywords
-
- return MTP_RESPONSE_OK;
-}
-
-bool MtpSqliteDatabase::getObjectFilePath(MtpObjectHandle handle,
- MtpString& filePath,
- int64_t& fileLength) {
- if (handle != MTP_PARENT_ROOT)
- handle &= kObjectHandleIndexMask;
- mFilePathQuery->reset();
- mFilePathQuery->bind(1, handle);
- if (!mFilePathQuery->step())
- return false;
-
- const char* path = mFilePathQuery->getColumnString(0);
- if (!path)
- return false;
- filePath = path;
- fileLength = mFilePathQuery->getColumnInt64(1);
- return true;
-}
-
-bool MtpSqliteDatabase::deleteFile(MtpObjectHandle handle) {
- uint32_t table = handle & kObjectHandleTableMask;
- handle &= kObjectHandleIndexMask;
- mFileDeleter->bind(1, handle);
- mFileDeleter->step();
- mFileDeleter->reset();
-
- return true;
-}
-
-MtpObjectHandle* MtpSqliteDatabase::getFileList(int& outCount) {
- MtpObjectHandle* result = NULL;
- int count = 0;
- SqliteStatement stmt(mDatabase);
- stmt.prepare("SELECT count(*) FROM files;");
-
- if (stmt.step())
- count = stmt.getColumnInt(0);
-
- if (count > 0) {
- result = new MtpObjectHandle[count];
- memset(result, 0, count * sizeof(*result));
- SqliteStatement stmt2(mDatabase);
- stmt2.prepare("SELECT _id,format FROM files;");
-
- for (int i = 0; i < count; i++) {
- if (!stmt2.step()) {
- LOGW("getFileList ended early");
- count = i;
- break;
- }
- MtpObjectHandle handle = stmt2.getColumnInt(0);
- MtpObjectFormat format = stmt2.getColumnInt(1);
- result[i] = handle;
- }
- }
- outCount = count;
- return result;
-}
-
-void MtpSqliteDatabase::beginTransaction() {
- mDatabase->beginTransaction();
-}
-
-void MtpSqliteDatabase::commitTransaction() {
- mDatabase->commitTransaction();
-}
-
-void MtpSqliteDatabase::rollbackTransaction() {
- mDatabase->rollbackTransaction();
-}
-
-} // namespace android
diff --git a/media/mtp/MtpSqliteDatabase.h b/media/mtp/MtpSqliteDatabase.h
deleted file mode 100644
index 14ed281..0000000
--- a/media/mtp/MtpSqliteDatabase.h
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * Copyright (C) 2010 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _MTP_SQLITE_DATABASE_H
-#define _MTP_SQLITE_DATABASE_H
-
-#include "MtpTypes.h"
-#include "MtpDatabase.h"
-
-class SqliteDatabase;
-
-namespace android {
-
-class MtpDataPacket;
-class SqliteStatement;
-
-class MtpSqliteDatabase : public MtpDatabase {
-private:
- SqliteDatabase* mDatabase;
- SqliteStatement* mFileIdQuery;
- SqliteStatement* mFilePathQuery;
- SqliteStatement* mObjectInfoQuery;
- SqliteStatement* mFileInserter;
- SqliteStatement* mFileDeleter;
-
-public:
- MtpSqliteDatabase();
- virtual ~MtpSqliteDatabase();
-
- bool open(const char* path, bool create);
- void close();
-
- virtual MtpObjectHandle getObjectHandle(const char* path);
- virtual MtpObjectHandle addFile(const char* path,
- MtpObjectFormat format,
- MtpObjectHandle parent,
- MtpStorageID storage,
- uint64_t size,
- time_t modified);
-
- virtual MtpObjectHandleList* getObjectList(MtpStorageID storageID,
- MtpObjectFormat format,
- MtpObjectHandle parent);
-
- virtual MtpResponseCode getObjectProperty(MtpObjectHandle handle,
- MtpObjectProperty property,
- MtpDataPacket& packet);
-
- virtual MtpResponseCode getObjectInfo(MtpObjectHandle handle,
- MtpDataPacket& packet);
-
- virtual bool getObjectFilePath(MtpObjectHandle handle,
- MtpString& filePath,
- int64_t& fileLength);
- virtual bool deleteFile(MtpObjectHandle handle);
-
- // helper for media scanner
- virtual MtpObjectHandle* getFileList(int& outCount);
-
- virtual void beginTransaction();
- virtual void commitTransaction();
- virtual void rollbackTransaction();
-};
-
-}; // namespace android
-
-#endif // _MTP_SQLITE_DATABASE_H
diff --git a/media/mtp/MtpStorage.cpp b/media/mtp/MtpStorage.cpp
index 7e89a90..eccf186 100644
--- a/media/mtp/MtpStorage.cpp
+++ b/media/mtp/MtpStorage.cpp
@@ -19,7 +19,6 @@
#include "MtpDebug.h"
#include "MtpDatabase.h"
#include "MtpStorage.h"
-#include "MtpMediaScanner.h"
#include <sys/types.h>
#include <sys/stat.h>
@@ -78,9 +77,4 @@ const char* MtpStorage::getDescription() const {
return "Device Storage";
}
-bool MtpStorage::scanFiles() {
- MtpMediaScanner scanner(mStorageID, mFilePath, mDatabase);
- return scanner.scanFiles();
-}
-
} // namespace android
diff --git a/media/mtp/MtpStorage.h b/media/mtp/MtpStorage.h
index 6097272..b13b926 100644
--- a/media/mtp/MtpStorage.h
+++ b/media/mtp/MtpStorage.h
@@ -22,7 +22,6 @@
namespace android {
class MtpDatabase;
-class SqliteStatement;
class MtpStorage {
@@ -44,8 +43,6 @@ public:
uint64_t getFreeSpace();
const char* getDescription() const;
inline const char* getPath() const { return mFilePath; }
-
- bool scanFiles();
};
}; // namespace android
diff --git a/media/mtp/MtpTypes.h b/media/mtp/MtpTypes.h
index 33cd369..ec0f867 100644
--- a/media/mtp/MtpTypes.h
+++ b/media/mtp/MtpTypes.h
@@ -60,11 +60,6 @@ union MtpPropertyValue {
#define MTP_PARENT_ROOT 0xFFFFFFFF // parent is root of the storage
#define kInvalidObjectHandle 0xFFFFFFFF
-// MtpObjectHandle bits and masks
-#define kObjectHandleMarkBit 0x80000000 // used for mark & sweep by MtpMediaScanner
-#define kObjectHandleTableMask 0x70000000 // mask for object table
-#define kObjectHandleIndexMask 0x0FFFFFFF // mask for object index in file table
-
class MtpStorage;
class MtpDevice;
class MtpProperty;
diff --git a/media/mtp/SqliteDatabase.cpp b/media/mtp/SqliteDatabase.cpp
deleted file mode 100644
index 1de3a41..0000000
--- a/media/mtp/SqliteDatabase.cpp
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * Copyright (C) 2010 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#define LOG_TAG "SqliteDatabase"
-
-#include "MtpDebug.h"
-#include "SqliteDatabase.h"
-#include "SqliteStatement.h"
-
-#include <stdio.h>
-#include <sqlite3.h>
-
-namespace android {
-
-SqliteDatabase::SqliteDatabase()
- : mDatabaseHandle(NULL)
-{
-}
-
-SqliteDatabase::~SqliteDatabase() {
- close();
-}
-
-bool SqliteDatabase::open(const char* path, bool create) {
- int flags = SQLITE_OPEN_READWRITE;
- if (create) flags |= SQLITE_OPEN_CREATE;
- // SQLITE_OPEN_NOMUTEX?
- int ret = sqlite3_open_v2(path, &mDatabaseHandle, flags, NULL);
- if (ret) {
- LOGE("could not open database\n");
- return false;
- }
- return true;
-}
-
-void SqliteDatabase::close() {
- if (mDatabaseHandle) {
- sqlite3_close(mDatabaseHandle);
- mDatabaseHandle = NULL;
- }
-}
-
-bool SqliteDatabase::exec(const char* sql) {
- return (sqlite3_exec(mDatabaseHandle, sql, NULL, NULL, NULL) == 0);
-}
-
-int SqliteDatabase::lastInsertedRow() {
- return sqlite3_last_insert_rowid(mDatabaseHandle);
-}
-
-void SqliteDatabase::beginTransaction() {
- exec("BEGIN TRANSACTION");
-}
-
-void SqliteDatabase::commitTransaction() {
- exec("COMMIT TRANSACTION");
-}
-
-void SqliteDatabase::rollbackTransaction() {
- exec("ROLLBACK TRANSACTION");
-}
-
-int SqliteDatabase::getVersion() {
- SqliteStatement stmt(this);
- stmt.prepare("PRAGMA user_version;");
- stmt.step();
- return stmt.getColumnInt(0);
-}
-void SqliteDatabase::setVersion(int version) {
- char buffer[40];
- snprintf(buffer, sizeof(buffer), "PRAGMA user_version = %d", version);
- exec(buffer);
-}
-
-} // namespace android
diff --git a/media/mtp/SqliteDatabase.h b/media/mtp/SqliteDatabase.h
deleted file mode 100644
index 7d008f9..0000000
--- a/media/mtp/SqliteDatabase.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright (C) 2010 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _SQLITE_DATABASE_H
-#define _SQLITE_DATABASE_H
-
-typedef struct sqlite3 sqlite3;
-
-namespace android {
-
-class SqliteDatabase {
-private:
- sqlite3* mDatabaseHandle;
-
-public:
- SqliteDatabase();
- virtual ~SqliteDatabase();
-
- bool open(const char* path, bool create);
- void close();
-
- bool exec(const char* sql);
- int lastInsertedRow();
-
- void beginTransaction();
- void commitTransaction();
- void rollbackTransaction();
-
- int getVersion();
- void setVersion(int version);
-
- inline sqlite3* getDatabaseHandle() const { return mDatabaseHandle; }
-};
-
-}; // namespace android
-
-#endif // _SQLITE_DATABASE_H
diff --git a/media/mtp/SqliteStatement.cpp b/media/mtp/SqliteStatement.cpp
deleted file mode 100644
index adef7ae..0000000
--- a/media/mtp/SqliteStatement.cpp
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * Copyright (C) 2010 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#define LOG_TAG "SqliteStatement"
-
-#include "SqliteStatement.h"
-#include "SqliteDatabase.h"
-
-#include <stdio.h>
-#include <sqlite3.h>
-
-namespace android {
-
-SqliteStatement::SqliteStatement(SqliteDatabase* db)
- : mDatabaseHandle(db->getDatabaseHandle()),
- mStatement(NULL),
- mDone(false)
-{
-}
-
-SqliteStatement::~SqliteStatement() {
- finalize();
-}
-
-bool SqliteStatement::prepare(const char* sql) {
- return (sqlite3_prepare_v2(mDatabaseHandle, sql, -1, &mStatement, NULL) == 0);
-}
-
-bool SqliteStatement::step() {
- int ret = sqlite3_step(mStatement);
- if (ret == SQLITE_DONE) {
- mDone = true;
- return true;
- }
- return (ret == SQLITE_OK || ret == SQLITE_ROW);
-}
-
-void SqliteStatement::reset() {
- sqlite3_reset(mStatement);
- mDone = false;
-}
-
-void SqliteStatement::finalize() {
- if (mStatement) {
- sqlite3_finalize(mStatement);
- mStatement = NULL;
- }
-}
-
-void SqliteStatement::bind(int column, int value) {
- sqlite3_bind_int(mStatement, column, value);
-}
-
-void SqliteStatement::bind(int column, const char* value) {
- sqlite3_bind_text(mStatement, column, value, -1, SQLITE_TRANSIENT);
-}
-
-int SqliteStatement::getColumnInt(int column) {
- return sqlite3_column_int(mStatement, column);
-}
-
-int64_t SqliteStatement::getColumnInt64(int column) {
- return sqlite3_column_int64(mStatement, column);
-}
-
-const char* SqliteStatement::getColumnString(int column) {
- return (const char *)sqlite3_column_text(mStatement, column);
-}
-
-} // namespace android
diff --git a/media/mtp/SqliteStatement.h b/media/mtp/SqliteStatement.h
deleted file mode 100644
index c0ebfff..0000000
--- a/media/mtp/SqliteStatement.h
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright (C) 2010 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _SQLITE_STATEMENT_H
-#define _SQLITE_STATEMENT_H
-
-#include <stdint.h>
-
-typedef struct sqlite3 sqlite3;
-typedef struct sqlite3_stmt sqlite3_stmt;
-
-namespace android {
-
-class SqliteDatabase;
-
-class SqliteStatement {
-private:
- sqlite3* mDatabaseHandle;
- sqlite3_stmt* mStatement;
- bool mDone;
-
-public:
- SqliteStatement(SqliteDatabase* db);
- virtual ~SqliteStatement();
-
- bool prepare(const char* sql);
- bool step();
- void reset();
- void finalize();
-
- void bind(int column, int value);
- void bind(int column, const char* value);
-
- int getColumnInt(int column);
- int64_t getColumnInt64(int column);
- const char* getColumnString(int column);
-
- inline bool isDone() const { return mDone; }
-};
-
-}; // namespace android
-
-#endif // _SQLITE_STATEMENT_H
diff --git a/media/mtp/mtptest.cpp b/media/mtp/mtptest.cpp
deleted file mode 100644
index a2cb826..0000000
--- a/media/mtp/mtptest.cpp
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * Copyright (C) 2010 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#define LOG_TAG "mtp_usb"
-
-#include "MtpDebug.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <fcntl.h>
-#include <sys/ioctl.h>
-
-#include "MtpServer.h"
-#include "MtpSqliteDatabase.h"
-#include "MtpStorage.h"
-#include "f_mtp.h"
-#include "private/android_filesystem_config.h"
-
-using namespace android;
-
-static bool enable_usb_function(const char* name, bool enable) {
- char path[PATH_MAX];
-
- snprintf(path, sizeof(path), "/sys/class/usb_composite/%s/enable", name);
- int fd = open(path, O_RDWR);
- if (fd < 0) {
- fprintf(stderr, "could not open %s in enable_usb_function\n", path);
- return false;
- }
- write(fd, enable ? "1" : "0", 2);
- close(fd);
- return true;
-}
-
-int main(int argc, char* argv[]) {
- bool usePTP = false;
- const char* storagePath = "/sdcard";
-
- for (int i = 1; i < argc; i++) {
- const char* arg = argv[i];
- if (!strcmp(arg, "-p"))
- usePTP = true;
- else if (arg[0] == '/')
- storagePath = arg;
- }
-
- int fd = open("/dev/mtp_usb", O_RDWR);
- printf("open returned %d\n", fd);
- if (fd < 0) {
- fprintf(stderr, "could not open MTP driver\n");
- return -1;
- }
-
- if (usePTP) {
- // set driver mode to PTP
- int ret = ioctl(fd, MTP_SET_INTERFACE_MODE, MTP_INTERFACE_MODE_PTP);
- if (ret) {
- fprintf(stderr, "MTP_SET_INTERFACE_MODE failed\n");
- return -1;
- }
- }
-
- // disable UMS and enable MTP USB functions
- enable_usb_function("usb_mass_storage", false);
- enable_usb_function("mtp", true);
-
- 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();
-
- close(fd);
- return 0;
-}
-
diff --git a/media/mtp/scantest.cpp b/media/mtp/scantest.cpp
deleted file mode 100644
index 3702a5d..0000000
--- a/media/mtp/scantest.cpp
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright (C) 2010 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stdio.h>
-
-#include "MtpSqliteDatabase.h"
-#include "MtpMediaScanner.h"
-
-using namespace android;
-
-int main(int argc, char* argv[]) {
- if (argc != 2) {
- fprintf(stderr, "usage: %s <storage path>\n", argv[0]);
- return -1;
- }
-
- MtpSqliteDatabase* database = new MtpSqliteDatabase();
- database->open("scantest.db", true);
-
- MtpMediaScanner scanner(1, argv[1], database);
- scanner.scanFiles();
- database->close();
-
- return 0;
-}