Merge "Add moveObject method to change object's path and parent."

am: 33a200e572

Change-Id: Iabb8c9989ad35140ab1c752fb70741f52e56c04d
This commit is contained in:
Jerry Zhang
2017-10-03 00:04:03 +00:00
committed by android-build-merger
2 changed files with 48 additions and 0 deletions

View File

@@ -841,6 +841,33 @@ public class MtpDatabase implements AutoCloseable {
return MtpConstants.RESPONSE_OK;
}
private int moveObject(int handle, int newParent, String newPath) {
String[] whereArgs = new String[] { Integer.toString(handle) };
// do not allow renaming any of the special subdirectories
if (isStorageSubDirectory(newPath)) {
return MtpConstants.RESPONSE_OBJECT_WRITE_PROTECTED;
}
// update database
ContentValues values = new ContentValues();
values.put(Files.FileColumns.DATA, newPath);
values.put(Files.FileColumns.PARENT, newParent);
int updated = 0;
try {
// note - we are relying on a special case in MediaProvider.update() to update
// the paths for all children in the case where this is a directory.
updated = mMediaProvider.update(mObjectsUri, values, ID_WHERE, whereArgs);
} catch (RemoteException e) {
Log.e(TAG, "RemoteException in mMediaProvider.update", e);
}
if (updated == 0) {
Log.e(TAG, "Unable to update path for " + handle + " to " + newPath);
return MtpConstants.RESPONSE_GENERAL_ERROR;
}
return MtpConstants.RESPONSE_OK;
}
private int setObjectProperty(int handle, int property,
long intValue, String stringValue) {
switch (property) {