summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--media/java/android/media/MtpDatabase.java45
-rw-r--r--media/jni/android_media_MtpDatabase.cpp70
-rw-r--r--media/mtp/MtpDatabase.h12
-rw-r--r--media/mtp/MtpServer.cpp69
-rw-r--r--media/mtp/MtpServer.h1
5 files changed, 121 insertions, 76 deletions
diff --git a/media/java/android/media/MtpDatabase.java b/media/java/android/media/MtpDatabase.java
index 2b311f58de1d..1b82d3974109 100644
--- a/media/java/android/media/MtpDatabase.java
+++ b/media/java/android/media/MtpDatabase.java
@@ -164,6 +164,33 @@ public class MtpDatabase {
return null;
}
+ private int getNumObjects(int storageID, int format, int parent) {
+ // we can ignore storageID until we support multiple storages
+ Log.d(TAG, "getObjectList parent: " + parent);
+ Cursor c = null;
+ try {
+ if (format != 0) {
+ c = mMediaProvider.query(mObjectsUri, ID_PROJECTION,
+ PARENT_FORMAT_WHERE,
+ new String[] { Integer.toString(parent), Integer.toString(format) },
+ null);
+ } else {
+ c = mMediaProvider.query(mObjectsUri, ID_PROJECTION,
+ PARENT_WHERE, new String[] { Integer.toString(parent) }, null);
+ }
+ if (c != null) {
+ return c.getCount();
+ }
+ } catch (RemoteException e) {
+ Log.e(TAG, "RemoteException in getNumObjects", e);
+ } finally {
+ if (c != null) {
+ c.close();
+ }
+ }
+ return -1;
+ }
+
private int getObjectProperty(int handle, int property,
long[] outIntValue, char[] outStringValue) {
Log.d(TAG, "getObjectProperty: " + property);
@@ -271,7 +298,7 @@ public class MtpDatabase {
return false;
}
- private boolean getObjectFilePath(int handle, char[] outFilePath, long[] outFileLength) {
+ private int getObjectFilePath(int handle, char[] outFilePath, long[] outFileLength) {
Log.d(TAG, "getObjectFilePath: " + handle);
Cursor c = null;
try {
@@ -282,26 +309,32 @@ public class MtpDatabase {
path.getChars(0, path.length(), outFilePath, 0);
outFilePath[path.length()] = 0;
outFileLength[0] = c.getLong(2);
- return true;
+ return MTP_RESPONSE_OK;
+ } else {
+ return MTP_RESPONSE_INVALID_OBJECT_HANDLE;
}
} catch (RemoteException e) {
Log.e(TAG, "RemoteException in getObjectFilePath", e);
+ return MTP_RESPONSE_GENERAL_ERROR;
} finally {
if (c != null) {
c.close();
}
}
- return false;
}
- private boolean deleteFile(int handle) {
+ private int deleteFile(int handle) {
Log.d(TAG, "deleteFile: " + handle);
Uri uri = MtpObjects.getContentUri(mVolumeName, handle);
try {
- return (mMediaProvider.delete(uri, null, null) == 1);
+ if (mMediaProvider.delete(uri, null, null) == 1) {
+ return MTP_RESPONSE_OK;
+ } else {
+ return MTP_RESPONSE_INVALID_OBJECT_HANDLE;
+ }
} catch (RemoteException e) {
Log.e(TAG, "RemoteException in deleteFile", e);
- return false;
+ return MTP_RESPONSE_GENERAL_ERROR;
}
}
diff --git a/media/jni/android_media_MtpDatabase.cpp b/media/jni/android_media_MtpDatabase.cpp
index be5936294ffa..5ab0a55a2945 100644
--- a/media/jni/android_media_MtpDatabase.cpp
+++ b/media/jni/android_media_MtpDatabase.cpp
@@ -39,6 +39,7 @@ using namespace android;
static jmethodID method_beginSendObject;
static jmethodID method_endSendObject;
static jmethodID method_getObjectList;
+static jmethodID method_getNumObjects;
static jmethodID method_getObjectProperty;
static jmethodID method_getObjectInfo;
static jmethodID method_getObjectFilePath;
@@ -80,6 +81,10 @@ public:
MtpObjectFormat format,
MtpObjectHandle parent);
+ virtual int getNumObjects(MtpStorageID storageID,
+ MtpObjectFormat format,
+ MtpObjectHandle parent);
+
virtual MtpResponseCode getObjectProperty(MtpObjectHandle handle,
MtpObjectProperty property,
MtpDataPacket& packet);
@@ -87,17 +92,10 @@ public:
virtual MtpResponseCode getObjectInfo(MtpObjectHandle handle,
MtpDataPacket& packet);
- virtual bool getObjectFilePath(MtpObjectHandle handle,
+ virtual MtpResponseCode 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();
+ virtual MtpResponseCode deleteFile(MtpObjectHandle handle);
bool getPropertyInfo(MtpObjectProperty property, int& type);
};
@@ -171,15 +169,20 @@ MtpObjectHandleList* MyMtpDatabase::getObjectList(MtpStorageID storageID,
MtpObjectHandleList* list = new MtpObjectHandleList();
jint* handles = env->GetIntArrayElements(array, 0);
jsize length = env->GetArrayLength(array);
-LOGD("getObjectList length: %d", length);
- for (int i = 0; i < length; i++) {
-LOGD("push: %d", handles[i]);
+ for (int i = 0; i < length; i++)
list->push(handles[i]);
- }
env->ReleaseIntArrayElements(array, handles, 0);
return list;
}
+int MyMtpDatabase::getNumObjects(MtpStorageID storageID,
+ MtpObjectFormat format,
+ MtpObjectHandle parent) {
+ JNIEnv* env = AndroidRuntime::getJNIEnv();
+ return env->CallIntMethod(mDatabase, method_getNumObjects,
+ (jint)storageID, (jint)format, (jint)parent);
+}
+
MtpResponseCode MyMtpDatabase::getObjectProperty(MtpObjectHandle handle,
MtpObjectProperty property,
MtpDataPacket& packet) {
@@ -290,14 +293,14 @@ MtpResponseCode MyMtpDatabase::getObjectInfo(MtpObjectHandle handle,
return MTP_RESPONSE_OK;
}
-bool MyMtpDatabase::getObjectFilePath(MtpObjectHandle handle,
+MtpResponseCode MyMtpDatabase::getObjectFilePath(MtpObjectHandle handle,
MtpString& filePath,
int64_t& fileLength) {
JNIEnv* env = AndroidRuntime::getJNIEnv();
- jboolean result = env->CallBooleanMethod(mDatabase, method_getObjectFilePath,
+ jint result = env->CallIntMethod(mDatabase, method_getObjectFilePath,
(jint)handle, mStringBuffer, mLongBuffer);
- if (!result)
- return false;
+ if (result != MTP_RESPONSE_OK)
+ return result;
jchar* str = env->GetCharArrayElements(mStringBuffer, 0);
filePath.setTo(str, strlen16(str));
@@ -307,30 +310,12 @@ bool MyMtpDatabase::getObjectFilePath(MtpObjectHandle handle,
fileLength = longValues[0];
env->ReleaseLongArrayElements(mLongBuffer, longValues, 0);
- return true;
+ return result;
}
-bool MyMtpDatabase::deleteFile(MtpObjectHandle handle) {
+MtpResponseCode MyMtpDatabase::deleteFile(MtpObjectHandle handle) {
JNIEnv* env = AndroidRuntime::getJNIEnv();
- return env->CallBooleanMethod(mDatabase, method_deleteFile, (jint)handle);
-}
-
- // helper for media scanner
-MtpObjectHandle* MyMtpDatabase::getFileList(int& outCount) {
- // REMOVE ME
- return NULL;
-}
-
-void MyMtpDatabase::beginTransaction() {
- // REMOVE ME
-}
-
-void MyMtpDatabase::commitTransaction() {
- // REMOVE ME
-}
-
-void MyMtpDatabase::rollbackTransaction() {
- // REMOVE ME
+ return env->CallIntMethod(mDatabase, method_deleteFile, (jint)handle);
}
struct PropertyTableEntry {
@@ -432,6 +417,11 @@ int register_android_media_MtpDatabase(JNIEnv *env)
LOGE("Can't find getObjectList");
return -1;
}
+ method_getNumObjects = env->GetMethodID(clazz, "getNumObjects", "(III)I");
+ if (method_getNumObjects == NULL) {
+ LOGE("Can't find getNumObjects");
+ return -1;
+ }
method_getObjectProperty = env->GetMethodID(clazz, "getObjectProperty", "(II[J[C)I");
if (method_getObjectProperty == NULL) {
LOGE("Can't find getObjectProperty");
@@ -442,12 +432,12 @@ int register_android_media_MtpDatabase(JNIEnv *env)
LOGE("Can't find getObjectInfo");
return -1;
}
- method_getObjectFilePath = env->GetMethodID(clazz, "getObjectFilePath", "(I[C[J)Z");
+ method_getObjectFilePath = env->GetMethodID(clazz, "getObjectFilePath", "(I[C[J)I");
if (method_getObjectFilePath == NULL) {
LOGE("Can't find getObjectFilePath");
return -1;
}
- method_deleteFile = env->GetMethodID(clazz, "deleteFile", "(I)Z");
+ method_deleteFile = env->GetMethodID(clazz, "deleteFile", "(I)I");
if (method_deleteFile == NULL) {
LOGE("Can't find deleteFile");
return -1;
diff --git a/media/mtp/MtpDatabase.h b/media/mtp/MtpDatabase.h
index 7feb3dc245fd..bbbbc38b5ca8 100644
--- a/media/mtp/MtpDatabase.h
+++ b/media/mtp/MtpDatabase.h
@@ -47,6 +47,10 @@ public:
MtpObjectFormat format,
MtpObjectHandle parent) = 0;
+ virtual int getNumObjects(MtpStorageID storageID,
+ MtpObjectFormat format,
+ MtpObjectHandle parent) = 0;
+
virtual MtpResponseCode getObjectProperty(MtpObjectHandle handle,
MtpObjectProperty property,
MtpDataPacket& packet) = 0;
@@ -54,14 +58,10 @@ public:
virtual MtpResponseCode getObjectInfo(MtpObjectHandle handle,
MtpDataPacket& packet) = 0;
- virtual bool getObjectFilePath(MtpObjectHandle handle,
+ virtual MtpResponseCode getObjectFilePath(MtpObjectHandle handle,
MtpString& filePath,
int64_t& fileLength) = 0;
- virtual bool deleteFile(MtpObjectHandle handle) = 0;
-
- virtual void beginTransaction() = 0;
- virtual void commitTransaction() = 0;
- virtual void rollbackTransaction() = 0;
+ virtual MtpResponseCode deleteFile(MtpObjectHandle handle) = 0;
};
}; // namespace android
diff --git a/media/mtp/MtpServer.cpp b/media/mtp/MtpServer.cpp
index adfe3a904b41..50a839ea17e8 100644
--- a/media/mtp/MtpServer.cpp
+++ b/media/mtp/MtpServer.cpp
@@ -55,10 +55,10 @@ static const MtpOperationCode kSupportedOperationCodes[] = {
// MTP_OPERATION_SELF_TEST,
// MTP_OPERATION_SET_OBJECT_PROTECTION,
// MTP_OPERATION_POWER_DOWN,
- MTP_OPERATION_GET_DEVICE_PROP_DESC,
- MTP_OPERATION_GET_DEVICE_PROP_VALUE,
- MTP_OPERATION_SET_DEVICE_PROP_VALUE,
- MTP_OPERATION_RESET_DEVICE_PROP_VALUE,
+// MTP_OPERATION_GET_DEVICE_PROP_DESC,
+// MTP_OPERATION_GET_DEVICE_PROP_VALUE,
+// MTP_OPERATION_SET_DEVICE_PROP_VALUE,
+// MTP_OPERATION_RESET_DEVICE_PROP_VALUE,
// MTP_OPERATION_TERMINATE_OPEN_CAPTURE,
// MTP_OPERATION_MOVE_OBJECT,
// MTP_OPERATION_COPY_OBJECT,
@@ -67,7 +67,7 @@ static const MtpOperationCode kSupportedOperationCodes[] = {
MTP_OPERATION_GET_OBJECT_PROPS_SUPPORTED,
// MTP_OPERATION_GET_OBJECT_PROP_DESC,
MTP_OPERATION_GET_OBJECT_PROP_VALUE,
- MTP_OPERATION_SET_OBJECT_PROP_VALUE,
+// MTP_OPERATION_SET_OBJECT_PROP_VALUE,
// MTP_OPERATION_GET_OBJECT_REFERENCES,
// MTP_OPERATION_SET_OBJECT_REFERENCES,
// MTP_OPERATION_SKIP,
@@ -308,6 +308,9 @@ bool MtpServer::handleRequest() {
case MTP_OPERATION_GET_OBJECT_HANDLES:
response = doGetObjectHandles();
break;
+ case MTP_OPERATION_GET_NUM_OBJECTS:
+ response = doGetNumObjects();
+ break;
case MTP_OPERATION_GET_OBJECT_PROP_VALUE:
response = doGetObjectPropValue();
break;
@@ -454,6 +457,26 @@ MtpResponseCode MtpServer::doGetObjectHandles() {
return MTP_RESPONSE_OK;
}
+MtpResponseCode MtpServer::doGetNumObjects() {
+ if (!mSessionOpen)
+ return MTP_RESPONSE_SESSION_NOT_OPEN;
+ 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?
+ if (parent == 0xFFFFFFFF)
+ parent = 0;
+
+ int count = mDatabase->getNumObjects(storageID, format, parent);
+ if (count >= 0) {
+ mResponse.setParameter(1, count);
+ return MTP_RESPONSE_OK;
+ } else {
+ mResponse.setParameter(1, 0);
+ return MTP_RESPONSE_INVALID_OBJECT_HANDLE;
+ }
+}
+
MtpResponseCode MtpServer::doGetObjectPropValue() {
MtpObjectHandle handle = mRequest.getParameter(1);
MtpObjectProperty property = mRequest.getParameter(2);
@@ -470,10 +493,11 @@ MtpResponseCode MtpServer::doGetObject() {
MtpObjectHandle handle = mRequest.getParameter(1);
MtpString pathBuf;
int64_t fileLength;
- if (!mDatabase->getObjectFilePath(handle, pathBuf, fileLength))
- return MTP_RESPONSE_INVALID_OBJECT_HANDLE;
- const char* filePath = (const char *)pathBuf;
+ int result = mDatabase->getObjectFilePath(handle, pathBuf, fileLength);
+ if (result != MTP_RESPONSE_OK)
+ return result;
+ const char* filePath = (const char *)pathBuf;
mtp_file_range mfr;
mfr.fd = open(filePath, O_RDONLY);
if (mfr.fd < 0) {
@@ -513,8 +537,9 @@ MtpResponseCode MtpServer::doSendObjectInfo() {
parent = 0;
} else {
int64_t dummy;
- if (!mDatabase->getObjectFilePath(parent, path, dummy))
- return MTP_RESPONSE_INVALID_OBJECT_HANDLE;
+ int result = mDatabase->getObjectFilePath(parent, path, dummy);
+ if (result != MTP_RESPONSE_OK)
+ return result;
}
// read only the fields we need
@@ -547,14 +572,11 @@ MtpResponseCode MtpServer::doSendObjectInfo() {
path += "/";
path += (const char *)name;
- mDatabase->beginTransaction();
MtpObjectHandle handle = mDatabase->beginSendObject((const char*)path,
format, parent, storageID, mSendObjectFileSize, modifiedTime);
if (handle == kInvalidObjectHandle) {
- mDatabase->rollbackTransaction();
return MTP_RESPONSE_GENERAL_ERROR;
}
- mDatabase->commitTransaction();
if (format == MTP_FORMAT_ASSOCIATION) {
mode_t mask = umask(0);
@@ -641,17 +663,16 @@ MtpResponseCode MtpServer::doDeleteObject() {
MtpString filePath;
int64_t fileLength;
- if (!mDatabase->getObjectFilePath(handle, filePath, fileLength))
- return MTP_RESPONSE_INVALID_OBJECT_HANDLE;
-
- LOGV("deleting %s", (const char *)filePath);
- // one of these should work
- rmdir((const char *)filePath);
- unlink((const char *)filePath);
-
- mDatabase->deleteFile(handle);
-
- return MTP_RESPONSE_OK;
+ int result = mDatabase->getObjectFilePath(handle, filePath, fileLength);
+ if (result == MTP_RESPONSE_OK) {
+ LOGV("deleting %s", (const char *)filePath);
+ // one of these should work
+ rmdir((const char *)filePath);
+ unlink((const char *)filePath);
+ return mDatabase->deleteFile(handle);
+ } else {
+ return result;
+ }
}
MtpResponseCode MtpServer::doGetObjectPropDesc() {
diff --git a/media/mtp/MtpServer.h b/media/mtp/MtpServer.h
index aff973a4afd0..9ed1c8448684 100644
--- a/media/mtp/MtpServer.h
+++ b/media/mtp/MtpServer.h
@@ -94,6 +94,7 @@ private:
MtpResponseCode doGetStorageInfo();
MtpResponseCode doGetObjectPropsSupported();
MtpResponseCode doGetObjectHandles();
+ MtpResponseCode doGetNumObjects();
MtpResponseCode doGetObjectPropValue();
MtpResponseCode doGetObjectInfo();
MtpResponseCode doGetObject();