diff options
author | Daichi Hirono <hirono@google.com> | 2016-01-12 15:46:41 +0900 |
---|---|---|
committer | Daichi Hirono <hirono@google.com> | 2016-01-14 09:42:59 +0900 |
commit | 2dd48256e9657b013dd6fa0ca86d1d7c7c730428 (patch) | |
tree | 2c71d5ff602cbe8c1cc5769f87dfd86a6842b4a3 /media/jni/android_mtp_MtpDevice.cpp | |
parent | d7c46bdec12b364f79ab44c089928a6d2734694c (diff) |
Change offset and size arguments of MtpDevice#getPartialObject to Java
long.
To represents full range of 32-bit unsigned integer, we should use
jlong instead of jint.
BUG=26284424
Change-Id: Id3fa9e3daa778c204ab8e38f821d454c709c317a
Diffstat (limited to 'media/jni/android_mtp_MtpDevice.cpp')
-rw-r--r-- | media/jni/android_mtp_MtpDevice.cpp | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/media/jni/android_mtp_MtpDevice.cpp b/media/jni/android_mtp_MtpDevice.cpp index 130dfe554f89..b1b3b621ee0b 100644 --- a/media/jni/android_mtp_MtpDevice.cpp +++ b/media/jni/android_mtp_MtpDevice.cpp @@ -372,12 +372,12 @@ android_mtp_MtpDevice_get_object(JNIEnv *env, jobject thiz, jint objectID, jint return nullptr; } -static jint +static jlong android_mtp_MtpDevice_get_partial_object(JNIEnv *env, jobject thiz, jint objectID, - jint offset, - jint size, + jlong offset, + jlong size, jbyteArray array) { if (!array) { @@ -385,6 +385,22 @@ android_mtp_MtpDevice_get_partial_object(JNIEnv *env, return -1; } + if (offset < 0 || 0xffffffffL < offset) { + jniThrowException( + env, + "java/lang/IllegalArgumentException", + "Offset argument must be a 32-bit unsigned integer."); + 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."); @@ -393,16 +409,13 @@ android_mtp_MtpDevice_get_partial_object(JNIEnv *env, JavaArrayWriter writer(env, array); uint32_t written_size; - bool success = device->readPartialObject( + const bool success = device->readPartialObject( objectID, offset, size, &written_size, JavaArrayWriter::writeTo, &writer); if (!success) { jniThrowException(env, "java/io/IOException", "Failed to read data."); return -1; } - // Note: assumption here is that a negative value will be treated as unsigned on the Java - // level. - // TODO: Make sure that actually holds. - return static_cast<jint>(written_size); + return static_cast<jlong>(written_size); } static jbyteArray @@ -615,7 +628,7 @@ static const JNINativeMethod gMethods[] = { {"native_get_object_info", "(I)Landroid/mtp/MtpObjectInfo;", (void *)android_mtp_MtpDevice_get_object_info}, {"native_get_object", "(II)[B",(void *)android_mtp_MtpDevice_get_object}, - {"native_get_partial_object", "(III[B)I", (void *)android_mtp_MtpDevice_get_partial_object}, + {"native_get_partial_object", "(IJJ[B)J", (void *)android_mtp_MtpDevice_get_partial_object}, {"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}, |