summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Daichi Hirono <hirono@google.com> 2016-01-28 04:46:16 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2016-01-28 04:46:16 +0000
commit376c5a8d34493a847a513e64cf3a654556f98017 (patch)
tree647ebfe089bf3ea7c5c05df93fc6a84831de071e
parent4f93c58b393bad5d0bcc4237fa66f14fb9c9ee28 (diff)
parent038832b9001f66bd2cbebaf1312a7ada2e512114 (diff)
Merge "Implement MtpDevice#getPartialObject64 in Java API."
-rw-r--r--api/current.txt2
-rw-r--r--api/system-current.txt2
-rw-r--r--api/test-current.txt2
-rw-r--r--media/java/android/mtp/MtpConstants.java2
-rw-r--r--media/java/android/mtp/MtpDevice.java23
-rw-r--r--media/jni/android_mtp_MtpDevice.cpp56
6 files changed, 87 insertions, 0 deletions
diff --git a/api/current.txt b/api/current.txt
index f0a528f355e9..f5291e7f967d 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -23126,6 +23126,7 @@ package android.mtp {
field public static final int OPERATION_GET_OBJECT_PROP_VALUE = 38915; // 0x9803
field public static final int OPERATION_GET_OBJECT_REFERENCES = 38928; // 0x9810
field public static final int OPERATION_GET_PARTIAL_OBJECT = 4123; // 0x101b
+ field public static final int OPERATION_GET_PARTIAL_OBJECT_64 = 38337; // 0x95c1
field public static final int OPERATION_GET_STORAGE_INFO = 4101; // 0x1005
field public static final int OPERATION_GET_STORAGE_I_DS = 4100; // 0x1004
field public static final int OPERATION_GET_THUMB = 4106; // 0x100a
@@ -23163,6 +23164,7 @@ package android.mtp {
method public android.mtp.MtpObjectInfo getObjectInfo(int);
method public long getParent(int);
method public long getPartialObject(int, long, long, byte[]) throws java.io.IOException;
+ method public long getPartialObject64(int, long, long, byte[]) throws java.io.IOException;
method public long getStorageId(int);
method public int[] getStorageIds();
method public android.mtp.MtpStorageInfo getStorageInfo(int);
diff --git a/api/system-current.txt b/api/system-current.txt
index 904f0336b879..fd12b9a8e3b1 100644
--- a/api/system-current.txt
+++ b/api/system-current.txt
@@ -24545,6 +24545,7 @@ package android.mtp {
field public static final int OPERATION_GET_OBJECT_PROP_VALUE = 38915; // 0x9803
field public static final int OPERATION_GET_OBJECT_REFERENCES = 38928; // 0x9810
field public static final int OPERATION_GET_PARTIAL_OBJECT = 4123; // 0x101b
+ field public static final int OPERATION_GET_PARTIAL_OBJECT_64 = 38337; // 0x95c1
field public static final int OPERATION_GET_STORAGE_INFO = 4101; // 0x1005
field public static final int OPERATION_GET_STORAGE_I_DS = 4100; // 0x1004
field public static final int OPERATION_GET_THUMB = 4106; // 0x100a
@@ -24582,6 +24583,7 @@ package android.mtp {
method public android.mtp.MtpObjectInfo getObjectInfo(int);
method public long getParent(int);
method public long getPartialObject(int, long, long, byte[]) throws java.io.IOException;
+ method public long getPartialObject64(int, long, long, byte[]) throws java.io.IOException;
method public long getStorageId(int);
method public int[] getStorageIds();
method public android.mtp.MtpStorageInfo getStorageInfo(int);
diff --git a/api/test-current.txt b/api/test-current.txt
index 3a7210a3deb6..c3d5453083a3 100644
--- a/api/test-current.txt
+++ b/api/test-current.txt
@@ -23135,6 +23135,7 @@ package android.mtp {
field public static final int OPERATION_GET_OBJECT_PROP_VALUE = 38915; // 0x9803
field public static final int OPERATION_GET_OBJECT_REFERENCES = 38928; // 0x9810
field public static final int OPERATION_GET_PARTIAL_OBJECT = 4123; // 0x101b
+ field public static final int OPERATION_GET_PARTIAL_OBJECT_64 = 38337; // 0x95c1
field public static final int OPERATION_GET_STORAGE_INFO = 4101; // 0x1005
field public static final int OPERATION_GET_STORAGE_I_DS = 4100; // 0x1004
field public static final int OPERATION_GET_THUMB = 4106; // 0x100a
@@ -23172,6 +23173,7 @@ package android.mtp {
method public android.mtp.MtpObjectInfo getObjectInfo(int);
method public long getParent(int);
method public long getPartialObject(int, long, long, byte[]) throws java.io.IOException;
+ method public long getPartialObject64(int, long, long, byte[]) throws java.io.IOException;
method public long getStorageId(int);
method public int[] getStorageIds();
method public android.mtp.MtpStorageInfo getStorageInfo(int);
diff --git a/media/java/android/mtp/MtpConstants.java b/media/java/android/mtp/MtpConstants.java
index ef2cf2bc4cda..0dcc7180b156 100644
--- a/media/java/android/mtp/MtpConstants.java
+++ b/media/java/android/mtp/MtpConstants.java
@@ -690,4 +690,6 @@ public final class MtpConstants {
public static final int OPERATION_SET_OBJECT_REFERENCES = 0x9811;
/** Operation code for Skip */
public static final int OPERATION_SKIP = 0x9820;
+ /** Operation code for GetPartialObject64 */
+ public static final int OPERATION_GET_PARTIAL_OBJECT_64 = 0x95C1;
}
diff --git a/media/java/android/mtp/MtpDevice.java b/media/java/android/mtp/MtpDevice.java
index 6bf942fbfb77..0e7013c97252 100644
--- a/media/java/android/mtp/MtpDevice.java
+++ b/media/java/android/mtp/MtpDevice.java
@@ -180,6 +180,27 @@ public final class MtpDevice {
}
/**
+ * Obtains object bytes in the specified range and writes it to an array.
+ * This call may block for an arbitrary amount of time depending on the size
+ * of the data and speed of the devices.
+ *
+ * This is a vender-extended operation supported by Android that enables us to pass
+ * unsigned 64-bit offset. Check if the MTP device supports the operation by using
+ * {@link MtpDeviceInfo#getOperationsSupported()}.
+ *
+ * @param objectHandle handle of the object to read
+ * @param offset Start index of reading range. It must be a non-negative value.
+ * @param size Size of reading range. It must be a non-negative value at most 0xffffffff.
+ * @param buffer Array to write data.
+ * @return Size of bytes that are actually read.
+ * @see MtpConstants#OPERATION_GET_PARTIAL_OBJECT_64
+ */
+ public long getPartialObject64(int objectHandle, long offset, long size, byte[] buffer)
+ throws IOException {
+ return native_get_partial_object_64(objectHandle, offset, size, buffer);
+ }
+
+ /**
* Returns the thumbnail data for an object as a byte array.
* The size and format of the thumbnail data can be determined via
* {@link MtpObjectInfo#getThumbCompressedSize} and
@@ -347,6 +368,8 @@ public final class MtpDevice {
private native byte[] native_get_object(int objectHandle, long objectSize);
private native long native_get_partial_object(
int objectHandle, long offset, long objectSize, byte[] buffer) throws IOException;
+ private native int native_get_partial_object_64(
+ int objectHandle, long offset, long objectSize, byte[] buffer) throws IOException;
private native byte[] native_get_thumbnail(int objectHandle);
private native boolean native_delete_object(int objectHandle);
private native int native_get_parent(int objectHandle);
diff --git a/media/jni/android_mtp_MtpDevice.cpp b/media/jni/android_mtp_MtpDevice.cpp
index dc5784374b8d..0ecb75018c45 100644
--- a/media/jni/android_mtp_MtpDevice.cpp
+++ b/media/jni/android_mtp_MtpDevice.cpp
@@ -447,6 +447,60 @@ android_mtp_MtpDevice_get_partial_object(JNIEnv *env,
return static_cast<jlong>(written_size);
}
+static jint
+android_mtp_MtpDevice_get_partial_object_64(JNIEnv *env,
+ jobject thiz,
+ jint objectID,
+ jlong offset,
+ jlong size,
+ jbyteArray array) {
+ if (!array) {
+ jniThrowException(env, "java/lang/IllegalArgumentException", "Array must not be null.");
+ return -1;
+ }
+
+ if (offset < 0) {
+ jniThrowException(
+ env,
+ "java/lang/IllegalArgumentException",
+ "Offset argument must not be a negative value.");
+ return -1;
+ }
+
+ if (size < 0 || 0xffffffffL < size) {
+ jniThrowException(
+ env,
+ "java/lang/IllegalArgumentException",
+ "Size argument must be a 32-bit unsigned integer.");
+ return -1;
+ }
+
+ MtpDevice* const device = get_device_from_object(env, thiz);
+ if (!device) {
+ jniThrowException(env, "java/io/IOException", "Failed to obtain MtpDevice.");
+ return -1;
+ }
+
+ const uint32_t native_object_handle = static_cast<uint32_t>(objectID);
+ const uint64_t native_offset = static_cast<uint64_t>(offset);
+ const uint32_t native_size = static_cast<uint32_t>(size);
+
+ JavaArrayWriter writer(env, array);
+ uint32_t written_size;
+ const bool success = device->readPartialObject64(
+ native_object_handle,
+ native_offset,
+ native_size,
+ &written_size,
+ JavaArrayWriter::writeTo,
+ &writer);
+ if (!success) {
+ jniThrowException(env, "java/io/IOException", "Failed to read data.");
+ return -1;
+ }
+ return static_cast<jint>(written_size);
+}
+
static jbyteArray
android_mtp_MtpDevice_get_thumbnail(JNIEnv *env, jobject thiz, jint objectID)
{
@@ -663,6 +717,8 @@ static const JNINativeMethod gMethods[] = {
(void *)android_mtp_MtpDevice_get_object_info},
{"native_get_object", "(IJ)[B",(void *)android_mtp_MtpDevice_get_object},
{"native_get_partial_object", "(IJJ[B)J", (void *)android_mtp_MtpDevice_get_partial_object},
+ {"native_get_partial_object_64", "(IJJ[B)I",
+ (void *)android_mtp_MtpDevice_get_partial_object_64},
{"native_get_thumbnail", "(I)[B",(void *)android_mtp_MtpDevice_get_thumbnail},
{"native_delete_object", "(I)Z", (void *)android_mtp_MtpDevice_delete_object},
{"native_get_parent", "(I)I", (void *)android_mtp_MtpDevice_get_parent},