Add storageId to moveObjects

When moving between different storages, the storageId
must be changed as well.

Bug: 67028892
Test: Move between storages with virtual sdcard.
Change-Id: Ie82aa8d53686bfffb7c26b46a49524a00f2f0214
This commit is contained in:
Jerry Zhang
2017-10-17 13:47:51 -07:00
parent 16fbd3a1d8
commit def7b19300
3 changed files with 23 additions and 13 deletions

View File

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