summaryrefslogtreecommitdiff
path: root/media/java/android/mtp/MtpDevice.java
diff options
context:
space:
mode:
authorTomasz Mikolajewski <mtomasz@google.com>2015-08-06 19:13:09 +0900
committerTomasz Mikolajewski <mtomasz@google.com>2015-08-14 13:09:52 +0900
commitb04990599a1a05cc922b0fe9dd98128440efb56a (patch)
tree3fa2cac3ca093e3249a9b6b7cf629f4a05a16f48 /media/java/android/mtp/MtpDevice.java
parent0ca8da52f76c1996a9ea6df866324855fd4d145f (diff)
Add API for uploading files to MTP devices.
Bug: 22545670 Change-Id: I038c54db06b7cf780bd027d76693e98c685d57a7
Diffstat (limited to 'media/java/android/mtp/MtpDevice.java')
-rw-r--r--media/java/android/mtp/MtpDevice.java29
1 files changed, 29 insertions, 0 deletions
diff --git a/media/java/android/mtp/MtpDevice.java b/media/java/android/mtp/MtpDevice.java
index a9611c52f75e..fbe047dea1d7 100644
--- a/media/java/android/mtp/MtpDevice.java
+++ b/media/java/android/mtp/MtpDevice.java
@@ -250,6 +250,33 @@ public final class MtpDevice {
return native_import_file(objectHandle, descriptor.getFd());
}
+ /**
+ * Copies the data for an object from a file descriptor.
+ * This call may block for an arbitrary amount of time depending on the size
+ * of the data and speed of the devices. The file descriptor is not closed
+ * on completion, and must be done by the caller.
+ *
+ * @param objectHandle handle of the target file
+ * @param descriptor file descriptor to read the data from.
+ * @return true if the file transfer succeeds
+ */
+ public boolean sendObject(int objectHandle, ParcelFileDescriptor descriptor) {
+ return native_send_object(objectHandle, descriptor.getFd());
+ }
+
+ /**
+ * Uploads an object metadata for a new entry. The {@link MtpObjectInfo} can be
+ * created with the {@link MtpObjectInfo.Builder} class.
+ *
+ * The returned {@link MtpObjectInfo} has the new object handle field filled in.
+ *
+ * @param info metadata of the entry
+ * @return object info of the created entry
+ */
+ public MtpObjectInfo sendObjectInfo(MtpObjectInfo info) {
+ return native_send_object_info(info);
+ }
+
// used by the JNI code
private long mNativeContext;
@@ -267,4 +294,6 @@ public final class MtpDevice {
private native long native_get_storage_id(int objectHandle);
private native boolean native_import_file(int objectHandle, String destPath);
private native boolean native_import_file(int objectHandle, int fd);
+ private native boolean native_send_object(int objectHandle, int fd);
+ private native MtpObjectInfo native_send_object_info(MtpObjectInfo info);
}