summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Daichi Hirono <hirono@google.com> 2016-01-15 14:42:53 +0900
committer Daichi Hirono <hirono@google.com> 2016-01-28 11:54:57 +0900
commite0e6654a31ad01fe4712dec0358ad95f8d3c8c8d (patch)
tree0f71c7089ff4644b2d645cff6e00358170d822bf
parent5012919bc3a75d1de972d29f70ae4a493f3493ed (diff)
Add varietions of MtpDevice's mehtods using long.
BUG=26525304 Change-Id: I0a0b187910cf498720d8e7b8fbe9b0590e67e65e
-rw-r--r--api/current.txt26
-rw-r--r--api/system-current.txt26
-rw-r--r--api/test-current.txt26
-rw-r--r--media/java/android/mtp/MtpDevice.java13
-rw-r--r--media/java/android/mtp/MtpObjectInfo.java134
-rw-r--r--media/jni/android_mtp_MtpDevice.cpp64
6 files changed, 214 insertions, 75 deletions
diff --git a/api/current.txt b/api/current.txt
index 737670baca94..5ec9d1404061 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -22774,7 +22774,7 @@ package android.mtp {
method public boolean importFile(int, android.os.ParcelFileDescriptor);
method public boolean open(android.hardware.usb.UsbDeviceConnection);
method public android.mtp.MtpEvent readEvent(android.os.CancellationSignal);
- method public boolean sendObject(int, int, android.os.ParcelFileDescriptor);
+ method public boolean sendObject(int, long, android.os.ParcelFileDescriptor);
method public android.mtp.MtpObjectInfo sendObjectInfo(android.mtp.MtpObjectInfo);
}
@@ -22805,23 +22805,31 @@ package android.mtp {
method public final int getAssociationDesc();
method public final int getAssociationType();
method public final int getCompressedSize();
+ method public final long getCompressedSizeLong();
method public final long getDateCreated();
method public final long getDateModified();
method public final int getFormat();
method public final int getImagePixDepth();
+ method public final long getImagePixDepthLong();
method public final int getImagePixHeight();
+ method public final long getImagePixHeightLong();
method public final int getImagePixWidth();
+ method public final long getImagePixWidthLong();
method public final java.lang.String getKeywords();
method public final java.lang.String getName();
method public final int getObjectHandle();
method public final int getParent();
method public final int getProtectionStatus();
method public final int getSequenceNumber();
+ method public final long getSequenceNumberLong();
method public final int getStorageId();
method public final int getThumbCompressedSize();
+ method public final long getThumbCompressedSizeLong();
method public final int getThumbFormat();
method public final int getThumbPixHeight();
+ method public final long getThumbPixHeightLong();
method public final int getThumbPixWidth();
+ method public final long getThumbPixWidthLong();
}
public static class MtpObjectInfo.Builder {
@@ -22830,24 +22838,24 @@ package android.mtp {
method public android.mtp.MtpObjectInfo build();
method public android.mtp.MtpObjectInfo.Builder setAssociationDesc(int);
method public android.mtp.MtpObjectInfo.Builder setAssociationType(int);
- method public android.mtp.MtpObjectInfo.Builder setCompressedSize(int);
+ method public android.mtp.MtpObjectInfo.Builder setCompressedSize(long);
method public android.mtp.MtpObjectInfo.Builder setDateCreated(long);
method public android.mtp.MtpObjectInfo.Builder setDateModified(long);
method public android.mtp.MtpObjectInfo.Builder setFormat(int);
- method public android.mtp.MtpObjectInfo.Builder setImagePixDepth(int);
- method public android.mtp.MtpObjectInfo.Builder setImagePixHeight(int);
- method public android.mtp.MtpObjectInfo.Builder setImagePixWidth(int);
+ method public android.mtp.MtpObjectInfo.Builder setImagePixDepth(long);
+ method public android.mtp.MtpObjectInfo.Builder setImagePixHeight(long);
+ method public android.mtp.MtpObjectInfo.Builder setImagePixWidth(long);
method public android.mtp.MtpObjectInfo.Builder setKeywords(java.lang.String);
method public android.mtp.MtpObjectInfo.Builder setName(java.lang.String);
method public android.mtp.MtpObjectInfo.Builder setObjectHandle(int);
method public android.mtp.MtpObjectInfo.Builder setParent(int);
method public android.mtp.MtpObjectInfo.Builder setProtectionStatus(int);
- method public android.mtp.MtpObjectInfo.Builder setSequenceNumber(int);
+ method public android.mtp.MtpObjectInfo.Builder setSequenceNumber(long);
method public android.mtp.MtpObjectInfo.Builder setStorageId(int);
- method public android.mtp.MtpObjectInfo.Builder setThumbCompressedSize(int);
+ method public android.mtp.MtpObjectInfo.Builder setThumbCompressedSize(long);
method public android.mtp.MtpObjectInfo.Builder setThumbFormat(int);
- method public android.mtp.MtpObjectInfo.Builder setThumbPixHeight(int);
- method public android.mtp.MtpObjectInfo.Builder setThumbPixWidth(int);
+ method public android.mtp.MtpObjectInfo.Builder setThumbPixHeight(long);
+ method public android.mtp.MtpObjectInfo.Builder setThumbPixWidth(long);
}
public final class MtpStorageInfo {
diff --git a/api/system-current.txt b/api/system-current.txt
index 3c39edb202b2..e76f4a044afe 100644
--- a/api/system-current.txt
+++ b/api/system-current.txt
@@ -24381,7 +24381,7 @@ package android.mtp {
method public boolean importFile(int, android.os.ParcelFileDescriptor);
method public boolean open(android.hardware.usb.UsbDeviceConnection);
method public android.mtp.MtpEvent readEvent(android.os.CancellationSignal);
- method public boolean sendObject(int, int, android.os.ParcelFileDescriptor);
+ method public boolean sendObject(int, long, android.os.ParcelFileDescriptor);
method public android.mtp.MtpObjectInfo sendObjectInfo(android.mtp.MtpObjectInfo);
}
@@ -24412,23 +24412,31 @@ package android.mtp {
method public final int getAssociationDesc();
method public final int getAssociationType();
method public final int getCompressedSize();
+ method public final long getCompressedSizeLong();
method public final long getDateCreated();
method public final long getDateModified();
method public final int getFormat();
method public final int getImagePixDepth();
+ method public final long getImagePixDepthLong();
method public final int getImagePixHeight();
+ method public final long getImagePixHeightLong();
method public final int getImagePixWidth();
+ method public final long getImagePixWidthLong();
method public final java.lang.String getKeywords();
method public final java.lang.String getName();
method public final int getObjectHandle();
method public final int getParent();
method public final int getProtectionStatus();
method public final int getSequenceNumber();
+ method public final long getSequenceNumberLong();
method public final int getStorageId();
method public final int getThumbCompressedSize();
+ method public final long getThumbCompressedSizeLong();
method public final int getThumbFormat();
method public final int getThumbPixHeight();
+ method public final long getThumbPixHeightLong();
method public final int getThumbPixWidth();
+ method public final long getThumbPixWidthLong();
}
public static class MtpObjectInfo.Builder {
@@ -24437,24 +24445,24 @@ package android.mtp {
method public android.mtp.MtpObjectInfo build();
method public android.mtp.MtpObjectInfo.Builder setAssociationDesc(int);
method public android.mtp.MtpObjectInfo.Builder setAssociationType(int);
- method public android.mtp.MtpObjectInfo.Builder setCompressedSize(int);
+ method public android.mtp.MtpObjectInfo.Builder setCompressedSize(long);
method public android.mtp.MtpObjectInfo.Builder setDateCreated(long);
method public android.mtp.MtpObjectInfo.Builder setDateModified(long);
method public android.mtp.MtpObjectInfo.Builder setFormat(int);
- method public android.mtp.MtpObjectInfo.Builder setImagePixDepth(int);
- method public android.mtp.MtpObjectInfo.Builder setImagePixHeight(int);
- method public android.mtp.MtpObjectInfo.Builder setImagePixWidth(int);
+ method public android.mtp.MtpObjectInfo.Builder setImagePixDepth(long);
+ method public android.mtp.MtpObjectInfo.Builder setImagePixHeight(long);
+ method public android.mtp.MtpObjectInfo.Builder setImagePixWidth(long);
method public android.mtp.MtpObjectInfo.Builder setKeywords(java.lang.String);
method public android.mtp.MtpObjectInfo.Builder setName(java.lang.String);
method public android.mtp.MtpObjectInfo.Builder setObjectHandle(int);
method public android.mtp.MtpObjectInfo.Builder setParent(int);
method public android.mtp.MtpObjectInfo.Builder setProtectionStatus(int);
- method public android.mtp.MtpObjectInfo.Builder setSequenceNumber(int);
+ method public android.mtp.MtpObjectInfo.Builder setSequenceNumber(long);
method public android.mtp.MtpObjectInfo.Builder setStorageId(int);
- method public android.mtp.MtpObjectInfo.Builder setThumbCompressedSize(int);
+ method public android.mtp.MtpObjectInfo.Builder setThumbCompressedSize(long);
method public android.mtp.MtpObjectInfo.Builder setThumbFormat(int);
- method public android.mtp.MtpObjectInfo.Builder setThumbPixHeight(int);
- method public android.mtp.MtpObjectInfo.Builder setThumbPixWidth(int);
+ method public android.mtp.MtpObjectInfo.Builder setThumbPixHeight(long);
+ method public android.mtp.MtpObjectInfo.Builder setThumbPixWidth(long);
}
public final class MtpStorageInfo {
diff --git a/api/test-current.txt b/api/test-current.txt
index 52c5b5a8f90c..9b000db7c07c 100644
--- a/api/test-current.txt
+++ b/api/test-current.txt
@@ -22782,7 +22782,7 @@ package android.mtp {
method public boolean importFile(int, android.os.ParcelFileDescriptor);
method public boolean open(android.hardware.usb.UsbDeviceConnection);
method public android.mtp.MtpEvent readEvent(android.os.CancellationSignal);
- method public boolean sendObject(int, int, android.os.ParcelFileDescriptor);
+ method public boolean sendObject(int, long, android.os.ParcelFileDescriptor);
method public android.mtp.MtpObjectInfo sendObjectInfo(android.mtp.MtpObjectInfo);
}
@@ -22813,23 +22813,31 @@ package android.mtp {
method public final int getAssociationDesc();
method public final int getAssociationType();
method public final int getCompressedSize();
+ method public final long getCompressedSizeLong();
method public final long getDateCreated();
method public final long getDateModified();
method public final int getFormat();
method public final int getImagePixDepth();
+ method public final long getImagePixDepthLong();
method public final int getImagePixHeight();
+ method public final long getImagePixHeightLong();
method public final int getImagePixWidth();
+ method public final long getImagePixWidthLong();
method public final java.lang.String getKeywords();
method public final java.lang.String getName();
method public final int getObjectHandle();
method public final int getParent();
method public final int getProtectionStatus();
method public final int getSequenceNumber();
+ method public final long getSequenceNumberLong();
method public final int getStorageId();
method public final int getThumbCompressedSize();
+ method public final long getThumbCompressedSizeLong();
method public final int getThumbFormat();
method public final int getThumbPixHeight();
+ method public final long getThumbPixHeightLong();
method public final int getThumbPixWidth();
+ method public final long getThumbPixWidthLong();
}
public static class MtpObjectInfo.Builder {
@@ -22838,24 +22846,24 @@ package android.mtp {
method public android.mtp.MtpObjectInfo build();
method public android.mtp.MtpObjectInfo.Builder setAssociationDesc(int);
method public android.mtp.MtpObjectInfo.Builder setAssociationType(int);
- method public android.mtp.MtpObjectInfo.Builder setCompressedSize(int);
+ method public android.mtp.MtpObjectInfo.Builder setCompressedSize(long);
method public android.mtp.MtpObjectInfo.Builder setDateCreated(long);
method public android.mtp.MtpObjectInfo.Builder setDateModified(long);
method public android.mtp.MtpObjectInfo.Builder setFormat(int);
- method public android.mtp.MtpObjectInfo.Builder setImagePixDepth(int);
- method public android.mtp.MtpObjectInfo.Builder setImagePixHeight(int);
- method public android.mtp.MtpObjectInfo.Builder setImagePixWidth(int);
+ method public android.mtp.MtpObjectInfo.Builder setImagePixDepth(long);
+ method public android.mtp.MtpObjectInfo.Builder setImagePixHeight(long);
+ method public android.mtp.MtpObjectInfo.Builder setImagePixWidth(long);
method public android.mtp.MtpObjectInfo.Builder setKeywords(java.lang.String);
method public android.mtp.MtpObjectInfo.Builder setName(java.lang.String);
method public android.mtp.MtpObjectInfo.Builder setObjectHandle(int);
method public android.mtp.MtpObjectInfo.Builder setParent(int);
method public android.mtp.MtpObjectInfo.Builder setProtectionStatus(int);
- method public android.mtp.MtpObjectInfo.Builder setSequenceNumber(int);
+ method public android.mtp.MtpObjectInfo.Builder setSequenceNumber(long);
method public android.mtp.MtpObjectInfo.Builder setStorageId(int);
- method public android.mtp.MtpObjectInfo.Builder setThumbCompressedSize(int);
+ method public android.mtp.MtpObjectInfo.Builder setThumbCompressedSize(long);
method public android.mtp.MtpObjectInfo.Builder setThumbFormat(int);
- method public android.mtp.MtpObjectInfo.Builder setThumbPixHeight(int);
- method public android.mtp.MtpObjectInfo.Builder setThumbPixWidth(int);
+ method public android.mtp.MtpObjectInfo.Builder setThumbPixHeight(long);
+ method public android.mtp.MtpObjectInfo.Builder setThumbPixWidth(long);
}
public final class MtpStorageInfo {
diff --git a/media/java/android/mtp/MtpDevice.java b/media/java/android/mtp/MtpDevice.java
index 4379a99cbb00..6bf942fbfb77 100644
--- a/media/java/android/mtp/MtpDevice.java
+++ b/media/java/android/mtp/MtpDevice.java
@@ -153,10 +153,11 @@ public final class MtpDevice {
*
* @param objectHandle handle of the object to read
* @param objectSize the size of the object (this should match
- * {@link MtpObjectInfo#getCompressedSize}
+ * {@link MtpObjectInfo#getCompressedSize})
* @return the object's data, or null if reading fails
*/
public byte[] getObject(int objectHandle, int objectSize) {
+ Preconditions.checkArgumentNonnegative(objectSize, "objectSize should not be negative");
return native_get_object(objectHandle, objectSize);
}
@@ -284,7 +285,7 @@ public final class MtpDevice {
* @param descriptor file descriptor to read the data from.
* @return true if the file transfer succeeds
*/
- public boolean sendObject(int objectHandle, int size, ParcelFileDescriptor descriptor) {
+ public boolean sendObject(int objectHandle, long size, ParcelFileDescriptor descriptor) {
return native_send_object(objectHandle, size, descriptor.getFd());
}
@@ -343,16 +344,16 @@ public final class MtpDevice {
private native MtpStorageInfo native_get_storage_info(int storageId);
private native int[] native_get_object_handles(int storageId, int format, int objectHandle);
private native MtpObjectInfo native_get_object_info(int objectHandle);
- private native byte[] native_get_object(int objectHandle, int objectSize);
+ 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 byte[] native_get_thumbnail(int objectHandle);
private native boolean native_delete_object(int objectHandle);
- private native long native_get_parent(int objectHandle);
- private native long native_get_storage_id(int objectHandle);
+ private native int native_get_parent(int objectHandle);
+ private native int 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 size, int fd);
+ private native boolean native_send_object(int objectHandle, long size, int fd);
private native MtpObjectInfo native_send_object_info(MtpObjectInfo info);
private native int native_submit_event_request();
private native MtpEvent native_reap_event_request(int handle);
diff --git a/media/java/android/mtp/MtpObjectInfo.java b/media/java/android/mtp/MtpObjectInfo.java
index 64aa99705b01..02092b177fe0 100644
--- a/media/java/android/mtp/MtpObjectInfo.java
+++ b/media/java/android/mtp/MtpObjectInfo.java
@@ -16,6 +16,8 @@
package android.mtp;
+import com.android.internal.util.Preconditions;
+
/**
* This class encapsulates information about an object on an MTP device.
* This corresponds to the ObjectInfo Dataset described in
@@ -96,10 +98,20 @@ public final class MtpObjectInfo {
* @return the object size
*/
public final int getCompressedSize() {
+ Preconditions.checkState(mCompressedSize >= 0);
return mCompressedSize;
}
/**
+ * Returns the size of the MTP object
+ *
+ * @return the object size
+ */
+ public final long getCompressedSizeLong() {
+ return uint32ToLong(mCompressedSize);
+ }
+
+ /**
* Returns the format code for the MTP object's thumbnail
* Will be zero for objects with no thumbnail
*
@@ -116,60 +128,126 @@ public final class MtpObjectInfo {
* @return the thumbnail size
*/
public final int getThumbCompressedSize() {
+ Preconditions.checkState(mThumbCompressedSize >= 0);
return mThumbCompressedSize;
}
/**
+ * Returns the size of the MTP object's thumbnail
+ * Will be zero for objects with no thumbnail
+ *
+ * @return the thumbnail size
+ */
+ public final long getThumbCompressedSizeLong() {
+ return uint32ToLong(mThumbCompressedSize);
+ }
+
+ /**
* Returns the width of the MTP object's thumbnail in pixels
* Will be zero for objects with no thumbnail
*
* @return the thumbnail width
*/
public final int getThumbPixWidth() {
+ Preconditions.checkState(mThumbPixWidth >= 0);
return mThumbPixWidth;
}
/**
+ * Returns the width of the MTP object's thumbnail in pixels
+ * Will be zero for objects with no thumbnail
+ *
+ * @return the thumbnail width
+ */
+ public final long getThumbPixWidthLong() {
+ return uint32ToLong(mThumbPixWidth);
+ }
+
+ /**
* Returns the height of the MTP object's thumbnail in pixels
* Will be zero for objects with no thumbnail
*
* @return the thumbnail height
*/
public final int getThumbPixHeight() {
+ Preconditions.checkState(mThumbPixHeight >= 0);
return mThumbPixHeight;
}
/**
+ * Returns the height of the MTP object's thumbnail in pixels
+ * Will be zero for objects with no thumbnail
+ *
+ * @return the thumbnail height
+ */
+ public final long getThumbPixHeightLong() {
+ return uint32ToLong(mThumbPixHeight);
+ }
+
+ /**
* Returns the width of the MTP object in pixels
* Will be zero for non-image objects
*
* @return the image width
*/
public final int getImagePixWidth() {
+ Preconditions.checkState(mImagePixWidth >= 0);
return mImagePixWidth;
}
/**
+ * Returns the width of the MTP object in pixels
+ * Will be zero for non-image objects
+ *
+ * @return the image width
+ */
+ public final long getImagePixWidthLong() {
+ return uint32ToLong(mImagePixWidth);
+ }
+
+ /**
* Returns the height of the MTP object in pixels
* Will be zero for non-image objects
*
* @return the image height
*/
public final int getImagePixHeight() {
+ Preconditions.checkState(mImagePixHeight >= 0);
return mImagePixHeight;
}
/**
+ * Returns the height of the MTP object in pixels
+ * Will be zero for non-image objects
+ *
+ * @return the image height
+ */
+ public final long getImagePixHeightLong() {
+ return uint32ToLong(mImagePixHeight);
+ }
+
+ /**
* Returns the depth of the MTP object in bits per pixel
* Will be zero for non-image objects
*
* @return the image depth
*/
public final int getImagePixDepth() {
+ Preconditions.checkState(mImagePixDepth >= 0);
return mImagePixDepth;
}
/**
+ * Returns the depth of the MTP object in bits per pixel
+ * Will be zero for non-image objects
+ *
+ * @return the image depth
+ */
+ public final long getImagePixDepthLong() {
+ return uint32ToLong(mImagePixDepth);
+ }
+
+ /**
* Returns the object handle for the object's parent
* Will be zero for the root directory of a storage unit
*
@@ -203,7 +281,7 @@ public final class MtpObjectInfo {
return mAssociationDesc;
}
- /**
+ /**
* Returns the sequence number for the MTP object
* This field is typically not used for MTP devices,
* but is sometimes used to define a sequence of photos
@@ -212,9 +290,22 @@ public final class MtpObjectInfo {
* @return the object's sequence number
*/
public final int getSequenceNumber() {
+ Preconditions.checkState(mSequenceNumber >= 0);
return mSequenceNumber;
}
+ /**
+ * Returns the sequence number for the MTP object
+ * This field is typically not used for MTP devices,
+ * but is sometimes used to define a sequence of photos
+ * on PTP cameras.
+ *
+ * @return the object's sequence number
+ */
+ public final long getSequenceNumberLong() {
+ return uint32ToLong(mSequenceNumber);
+ }
+
/**
* Returns the name of the MTP object
*
@@ -309,8 +400,8 @@ public final class MtpObjectInfo {
return this;
}
- public Builder setCompressedSize(int value) {
- mObjectInfo.mCompressedSize = value;
+ public Builder setCompressedSize(long value) {
+ mObjectInfo.mCompressedSize = longToUint32(value, "value");
return this;
}
@@ -329,18 +420,18 @@ public final class MtpObjectInfo {
return this;
}
- public Builder setImagePixDepth(int value) {
- mObjectInfo.mImagePixDepth = value;
+ public Builder setImagePixDepth(long value) {
+ mObjectInfo.mImagePixDepth = longToUint32(value, "value");
return this;
}
- public Builder setImagePixHeight(int value) {
- mObjectInfo.mImagePixHeight = value;
+ public Builder setImagePixHeight(long value) {
+ mObjectInfo.mImagePixHeight = longToUint32(value, "value");
return this;
}
- public Builder setImagePixWidth(int value) {
- mObjectInfo.mImagePixWidth = value;
+ public Builder setImagePixWidth(long value) {
+ mObjectInfo.mImagePixWidth = longToUint32(value, "value");
return this;
}
@@ -364,8 +455,8 @@ public final class MtpObjectInfo {
return this;
}
- public Builder setSequenceNumber(int value) {
- mObjectInfo.mSequenceNumber = value;
+ public Builder setSequenceNumber(long value) {
+ mObjectInfo.mSequenceNumber = longToUint32(value, "value");
return this;
}
@@ -374,8 +465,8 @@ public final class MtpObjectInfo {
return this;
}
- public Builder setThumbCompressedSize(int value) {
- mObjectInfo.mThumbCompressedSize = value;
+ public Builder setThumbCompressedSize(long value) {
+ mObjectInfo.mThumbCompressedSize = longToUint32(value, "value");
return this;
}
@@ -384,13 +475,13 @@ public final class MtpObjectInfo {
return this;
}
- public Builder setThumbPixHeight(int value) {
- mObjectInfo.mThumbPixHeight = value;
+ public Builder setThumbPixHeight(long value) {
+ mObjectInfo.mThumbPixHeight = longToUint32(value, "value");
return this;
}
- public Builder setThumbPixWidth(int value) {
- mObjectInfo.mThumbPixWidth = value;
+ public Builder setThumbPixWidth(long value) {
+ mObjectInfo.mThumbPixWidth = longToUint32(value, "value");
return this;
}
@@ -407,4 +498,13 @@ public final class MtpObjectInfo {
return result;
}
}
+
+ private static long uint32ToLong(int value) {
+ return value < 0 ? 0x100000000L + value : value;
+ }
+
+ private static int longToUint32(long value, String valueName) {
+ Preconditions.checkArgumentInRange(value, 0, 0xffffffffL, valueName);
+ return (int) value;
+ }
}
diff --git a/media/jni/android_mtp_MtpDevice.cpp b/media/jni/android_mtp_MtpDevice.cpp
index 8b7a9264a30a..dc5784374b8d 100644
--- a/media/jni/android_mtp_MtpDevice.cpp
+++ b/media/jni/android_mtp_MtpDevice.cpp
@@ -26,6 +26,7 @@
#include <fcntl.h>
#include <memory>
+#include <string>
#include "jni.h"
#include "JNIHelp.h"
@@ -370,9 +371,26 @@ android_mtp_MtpDevice_get_object_info(JNIEnv *env, jobject thiz, jint objectID)
return info;
}
+bool check_uint32_arg(JNIEnv *env, const char* name, jlong value, uint32_t* out) {
+ if (value < 0 || 0xffffffff < value) {
+ jniThrowException(
+ env,
+ "java/lang/IllegalArgumentException",
+ (std::string("argument must be a 32-bit unsigned integer: ") + name).c_str());
+ return false;
+ }
+ *out = static_cast<uint32_t>(value);
+ return true;
+}
+
static jbyteArray
-android_mtp_MtpDevice_get_object(JNIEnv *env, jobject thiz, jint objectID, jint objectSize)
+android_mtp_MtpDevice_get_object(JNIEnv *env, jobject thiz, jint objectID, jlong objectSizeLong)
{
+ uint32_t objectSize;
+ if (!check_uint32_arg(env, "objectSize", objectSizeLong, &objectSize)) {
+ return nullptr;
+ }
+
MtpDevice* device = get_device_from_object(env, thiz);
if (!device) {
return nullptr;
@@ -396,8 +414,8 @@ static jlong
android_mtp_MtpDevice_get_partial_object(JNIEnv *env,
jobject thiz,
jint objectID,
- jlong offset,
- jlong size,
+ jlong offsetLong,
+ jlong sizeLong,
jbyteArray array)
{
if (!array) {
@@ -405,19 +423,10 @@ 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.");
+ uint32_t offset;
+ uint32_t size;
+ if (!check_uint32_arg(env, "offset", offsetLong, &offset) ||
+ !check_uint32_arg(env, "size", sizeLong, &size)) {
return -1;
}
@@ -467,22 +476,22 @@ android_mtp_MtpDevice_delete_object(JNIEnv *env, jobject thiz, jint object_id)
}
}
-static jlong
+static jint
android_mtp_MtpDevice_get_parent(JNIEnv *env, jobject thiz, jint object_id)
{
MtpDevice* device = get_device_from_object(env, thiz);
if (device)
- return (jlong)device->getParent(object_id);
+ return static_cast<jint>(device->getParent(object_id));
else
return -1;
}
-static jlong
+static jint
android_mtp_MtpDevice_get_storage_id(JNIEnv *env, jobject thiz, jint object_id)
{
MtpDevice* device = get_device_from_object(env, thiz);
if (device)
- return (jlong)device->getStorageID(object_id);
+ return static_cast<jint>(device->getStorageID(object_id));
else
return -1;
}
@@ -516,8 +525,13 @@ android_mtp_MtpDevice_import_file_to_fd(JNIEnv *env, jobject thiz, jint object_i
}
static jboolean
-android_mtp_MtpDevice_send_object(JNIEnv *env, jobject thiz, jint object_id, jint size, jint fd)
+android_mtp_MtpDevice_send_object(
+ JNIEnv *env, jobject thiz, jint object_id, jlong sizeLong, jint fd)
{
+ uint32_t size;
+ if (!check_uint32_arg(env, "size", sizeLong, &size))
+ return JNI_FALSE;
+
MtpDevice* device = get_device_from_object(env, thiz);
if (!device)
return JNI_FALSE;
@@ -647,16 +661,16 @@ static const JNINativeMethod gMethods[] = {
(void *)android_mtp_MtpDevice_get_object_handles},
{"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_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_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},
- {"native_get_storage_id", "(I)J", (void *)android_mtp_MtpDevice_get_storage_id},
+ {"native_get_parent", "(I)I", (void *)android_mtp_MtpDevice_get_parent},
+ {"native_get_storage_id", "(I)I", (void *)android_mtp_MtpDevice_get_storage_id},
{"native_import_file", "(ILjava/lang/String;)Z",
(void *)android_mtp_MtpDevice_import_file},
{"native_import_file", "(II)Z",(void *)android_mtp_MtpDevice_import_file_to_fd},
- {"native_send_object", "(III)Z",(void *)android_mtp_MtpDevice_send_object},
+ {"native_send_object", "(IJI)Z",(void *)android_mtp_MtpDevice_send_object},
{"native_send_object_info", "(Landroid/mtp/MtpObjectInfo;)Landroid/mtp/MtpObjectInfo;",
(void *)android_mtp_MtpDevice_send_object_info},
{"native_submit_event_request", "()I", (void *)android_mtp_MtpDevice_submit_event_request},