diff options
author | 2016-01-22 19:34:25 +0900 | |
---|---|---|
committer | 2016-01-28 11:19:55 +0900 | |
commit | 038832b9001f66bd2cbebaf1312a7ada2e512114 (patch) | |
tree | 20ff3174957a2f30b24619208db6e66591ef1d18 | |
parent | 5012919bc3a75d1de972d29f70ae4a493f3493ed (diff) |
Implement MtpDevice#getPartialObject64 in Java API.
BUG=26703522
Change-Id: I08510e3a179b7dc8bf247a9e997dc8a160138fc2
-rw-r--r-- | api/current.txt | 2 | ||||
-rw-r--r-- | api/system-current.txt | 2 | ||||
-rw-r--r-- | api/test-current.txt | 2 | ||||
-rw-r--r-- | media/java/android/mtp/MtpConstants.java | 2 | ||||
-rw-r--r-- | media/java/android/mtp/MtpDevice.java | 23 | ||||
-rw-r--r-- | media/jni/android_mtp_MtpDevice.cpp | 56 |
6 files changed, 87 insertions, 0 deletions
diff --git a/api/current.txt b/api/current.txt index 737670baca94..e62732a28eb4 100644 --- a/api/current.txt +++ b/api/current.txt @@ -22729,6 +22729,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 @@ -22766,6 +22767,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 3c39edb202b2..6c61340e2f90 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -24336,6 +24336,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 @@ -24373,6 +24374,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 52c5b5a8f90c..b118a3950193 100644 --- a/api/test-current.txt +++ b/api/test-current.txt @@ -22737,6 +22737,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 @@ -22774,6 +22775,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 bdd86439bae0..b396821aabd0 100644 --- a/media/java/android/mtp/MtpConstants.java +++ b/media/java/android/mtp/MtpConstants.java @@ -683,4 +683,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 4379a99cbb00..1aac27f0eff2 100644 --- a/media/java/android/mtp/MtpDevice.java +++ b/media/java/android/mtp/MtpDevice.java @@ -179,6 +179,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 @@ -346,6 +367,8 @@ public final class MtpDevice { private native byte[] native_get_object(int objectHandle, int 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 long native_get_parent(int objectHandle); diff --git a/media/jni/android_mtp_MtpDevice.cpp b/media/jni/android_mtp_MtpDevice.cpp index 8b7a9264a30a..129ce1ca2829 100644 --- a/media/jni/android_mtp_MtpDevice.cpp +++ b/media/jni/android_mtp_MtpDevice.cpp @@ -438,6 +438,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) { @@ -649,6 +703,8 @@ static const JNINativeMethod gMethods[] = { (void *)android_mtp_MtpDevice_get_object_info}, {"native_get_object", "(II)[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)J", (void *)android_mtp_MtpDevice_get_parent}, |