Merge "Add moveObject method to change object's path and parent." am: 33a200e572 am: 0f09ac317d

am: f9696617bd

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

View File

@@ -845,6 +845,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) {