Merge "Add storageId to moveObjects"

This commit is contained in:
Jerry Zhang
2017-10-19 17:55:34 +00:00
committed by Gerrit Code Review
3 changed files with 23 additions and 13 deletions

View File

@@ -466,10 +466,14 @@ public class MtpDatabase implements AutoCloseable {
if (parent == 0xFFFFFFFF) { if (parent == 0xFFFFFFFF) {
// all objects in root of store // all objects in root of store
parent = 0; parent = 0;
}
where = STORAGE_PARENT_WHERE; where = STORAGE_PARENT_WHERE;
whereArgs = new String[]{Integer.toString(storageID), whereArgs = new String[]{Integer.toString(storageID),
Integer.toString(parent)}; Integer.toString(parent)};
} else {
// If a parent is specified, the storage is redundant
where = PARENT_WHERE;
whereArgs = new String[]{Integer.toString(parent)};
}
} }
} else { } else {
// query specific format // query specific format
@@ -482,11 +486,16 @@ public class MtpDatabase implements AutoCloseable {
if (parent == 0xFFFFFFFF) { if (parent == 0xFFFFFFFF) {
// all objects in root of store // all objects in root of store
parent = 0; parent = 0;
}
where = STORAGE_FORMAT_PARENT_WHERE; where = STORAGE_FORMAT_PARENT_WHERE;
whereArgs = new String[]{Integer.toString(storageID), whereArgs = new String[]{Integer.toString(storageID),
Integer.toString(format), Integer.toString(format),
Integer.toString(parent)}; Integer.toString(parent)};
} else {
// If a parent is specified, the storage is redundant
where = FORMAT_PARENT_WHERE;
whereArgs = new String[]{Integer.toString(format),
Integer.toString(parent)};
}
} }
} }
} }
@@ -838,7 +847,7 @@ public class MtpDatabase implements AutoCloseable {
return MtpConstants.RESPONSE_OK; return MtpConstants.RESPONSE_OK;
} }
private int moveObject(int handle, int newParent, String newPath) { private int moveObject(int handle, int newParent, int newStorage, String newPath) {
String[] whereArgs = new String[] { Integer.toString(handle) }; String[] whereArgs = new String[] { Integer.toString(handle) };
// do not allow renaming any of the special subdirectories // do not allow renaming any of the special subdirectories
@@ -850,6 +859,7 @@ public class MtpDatabase implements AutoCloseable {
ContentValues values = new ContentValues(); ContentValues values = new ContentValues();
values.put(Files.FileColumns.DATA, newPath); values.put(Files.FileColumns.DATA, newPath);
values.put(Files.FileColumns.PARENT, newParent); values.put(Files.FileColumns.PARENT, newParent);
values.put(Files.FileColumns.STORAGE_ID, newStorage);
int updated = 0; int updated = 0;
try { try {
// note - we are relying on a special case in MediaProvider.update() to update // note - we are relying on a special case in MediaProvider.update() to update

View File

@@ -180,7 +180,7 @@ public:
virtual MtpProperty* getDevicePropertyDesc(MtpDeviceProperty property); virtual MtpProperty* getDevicePropertyDesc(MtpDeviceProperty property);
virtual MtpResponseCode moveObject(MtpObjectHandle handle, MtpObjectHandle newParent, virtual MtpResponseCode moveObject(MtpObjectHandle handle, MtpObjectHandle newParent,
MtpString& newPath); MtpStorageID newStorage, MtpString& newPath);
virtual void sessionStarted(); virtual void sessionStarted();
@@ -998,11 +998,11 @@ MtpResponseCode MyMtpDatabase::deleteFile(MtpObjectHandle handle) {
} }
MtpResponseCode MyMtpDatabase::moveObject(MtpObjectHandle handle, MtpObjectHandle newParent, MtpResponseCode MyMtpDatabase::moveObject(MtpObjectHandle handle, MtpObjectHandle newParent,
MtpString &newPath) { MtpStorageID newStorage, MtpString &newPath) {
JNIEnv* env = AndroidRuntime::getJNIEnv(); JNIEnv* env = AndroidRuntime::getJNIEnv();
jstring stringValue = env->NewStringUTF((const char *) newPath); jstring stringValue = env->NewStringUTF((const char *) newPath);
MtpResponseCode result = env->CallIntMethod(mDatabase, method_moveObject, MtpResponseCode result = env->CallIntMethod(mDatabase, method_moveObject,
(jint)handle, (jint)newParent, stringValue); (jint)handle, (jint)newParent, (jint) newStorage, stringValue);
checkAndClearExceptionFromCallback(env, __FUNCTION__); checkAndClearExceptionFromCallback(env, __FUNCTION__);
env->DeleteLocalRef(stringValue); env->DeleteLocalRef(stringValue);
@@ -1374,7 +1374,7 @@ int register_android_mtp_MtpDatabase(JNIEnv *env)
ALOGE("Can't find deleteFile"); ALOGE("Can't find deleteFile");
return -1; return -1;
} }
method_moveObject = env->GetMethodID(clazz, "moveObject", "(IILjava/lang/String;)I"); method_moveObject = env->GetMethodID(clazz, "moveObject", "(IIILjava/lang/String;)I");
if (method_moveObject == NULL) { if (method_moveObject == NULL) {
ALOGE("Can't find moveObject"); ALOGE("Can't find moveObject");
return -1; return -1;

View File

@@ -72,7 +72,7 @@ android_mtp_MtpServer_setup(JNIEnv *env, jobject thiz, jobject javaDatabase, jbo
const char *deviceInfoDeviceVersionStr = env->GetStringUTFChars(deviceInfoDeviceVersion, NULL); const char *deviceInfoDeviceVersionStr = env->GetStringUTFChars(deviceInfoDeviceVersion, NULL);
const char *deviceInfoSerialNumberStr = env->GetStringUTFChars(deviceInfoSerialNumber, NULL); const char *deviceInfoSerialNumberStr = env->GetStringUTFChars(deviceInfoSerialNumber, NULL);
MtpServer* server = new MtpServer(getMtpDatabase(env, javaDatabase), MtpServer* server = new MtpServer(getMtpDatabase(env, javaDatabase),
usePtp, AID_MEDIA_RW, 0664, 0775, usePtp,
MtpString((deviceInfoManufacturerStr != NULL) ? deviceInfoManufacturerStr : ""), MtpString((deviceInfoManufacturerStr != NULL) ? deviceInfoManufacturerStr : ""),
MtpString((deviceInfoModelStr != NULL) ? deviceInfoModelStr : ""), MtpString((deviceInfoModelStr != NULL) ? deviceInfoModelStr : ""),
MtpString((deviceInfoDeviceVersionStr != NULL) ? deviceInfoDeviceVersionStr : ""), MtpString((deviceInfoDeviceVersionStr != NULL) ? deviceInfoDeviceVersionStr : ""),