diff options
author | Jerry Zhang <zhangjerry@google.com> | 2017-10-03 00:04:03 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2017-10-03 00:04:03 +0000 |
commit | 0f09ac317de0c32c57bbc9e096fd761cba752af3 (patch) | |
tree | 7705071bb03ab674eb70aa41b95ca7719c6314c0 /media/java/android/mtp/MtpDatabase.java | |
parent | 72ad4a04eed579eda28a7335c941662f97635d77 (diff) | |
parent | 33a200e5724791de2e55462cb8620404503fdc9f (diff) |
Merge "Add moveObject method to change object's path and parent."
am: 33a200e572
Change-Id: Iabb8c9989ad35140ab1c752fb70741f52e56c04d
Diffstat (limited to 'media/java/android/mtp/MtpDatabase.java')
-rwxr-xr-x | media/java/android/mtp/MtpDatabase.java | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/media/java/android/mtp/MtpDatabase.java b/media/java/android/mtp/MtpDatabase.java index 698c9c96fe01..9f00828a48f3 100755 --- a/media/java/android/mtp/MtpDatabase.java +++ b/media/java/android/mtp/MtpDatabase.java @@ -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) { |