diff options
author | Mike Lockwood <lockwood@android.com> | 2010-09-21 10:39:27 -0400 |
---|---|---|
committer | Mike Lockwood <lockwood@android.com> | 2010-09-21 10:41:33 -0400 |
commit | f1f5361e328c13be80e3760d8cc2170d70c9d0ba (patch) | |
tree | ec9d04509319c10492f7c8907be3ed1483239998 | |
parent | 141e00c212ab1cd9d6def55edadc3e709d88f9d5 (diff) | |
download | frameworks_base-f1f5361e328c13be80e3760d8cc2170d70c9d0ba.zip frameworks_base-f1f5361e328c13be80e3760d8cc2170d70c9d0ba.tar.gz frameworks_base-f1f5361e328c13be80e3760d8cc2170d70c9d0ba.tar.bz2 |
MTP host: Use Java longs for storage and object IDs
This avoids problems with unsigned 32 bit numbers with cameras that use
storage and object IDs > 0x7FFFFFFF
Change-Id: I615f2d468851e9d6ff8882d22966d3687697d8eb
Signed-off-by: Mike Lockwood <lockwood@android.com>
9 files changed, 41 insertions, 39 deletions
diff --git a/core/java/android/provider/Mtp.java b/core/java/android/provider/Mtp.java index bba54e1..de161e7 100644 --- a/core/java/android/provider/Mtp.java +++ b/core/java/android/provider/Mtp.java @@ -75,7 +75,7 @@ public final class Mtp return Uri.parse(CONTENT_AUTHORITY_DEVICE_SLASH + deviceID + "/storage"); } - public static Uri getContentUri(int deviceID, int storageID) { + public static Uri getContentUri(int deviceID, long storageID) { return Uri.parse(CONTENT_AUTHORITY_DEVICE_SLASH + deviceID + "/storage/" + storageID); } @@ -97,17 +97,17 @@ public final class Mtp */ public static final class Object implements BaseColumns { - public static Uri getContentUri(int deviceID, int objectID) { + public static Uri getContentUri(int deviceID, long objectID) { return Uri.parse(CONTENT_AUTHORITY_DEVICE_SLASH + deviceID + "/object/" + objectID); } - public static Uri getContentUriForObjectChildren(int deviceID, int objectID) { + public static Uri getContentUriForObjectChildren(int deviceID, long objectID) { return Uri.parse(CONTENT_AUTHORITY_DEVICE_SLASH + deviceID + "/object/" + objectID + "/child"); } - public static Uri getContentUriForStorageChildren(int deviceID, int storageID) { + public static Uri getContentUriForStorageChildren(int deviceID, long storageID) { return Uri.parse(CONTENT_AUTHORITY_DEVICE_SLASH + deviceID + "/storage/" + storageID + "/child"); } diff --git a/media/java/android/media/MtpClient.java b/media/java/android/media/MtpClient.java index f7c0ce2..98da1f6 100644 --- a/media/java/android/media/MtpClient.java +++ b/media/java/android/media/MtpClient.java @@ -57,20 +57,20 @@ public class MtpClient { native_stop(); } - public boolean deleteObject(int deviceID, int objectID) { + public boolean deleteObject(int deviceID, long objectID) { return native_delete_object(deviceID, objectID); } - public int getParent(int deviceID, int objectID) { + public long getParent(int deviceID, long objectID) { return native_get_parent(deviceID, objectID); } - public int getStorageID(int deviceID, int objectID) { + public long getStorageID(int deviceID, long objectID) { return native_get_storage_id(deviceID, objectID); } // create a file descriptor for reading the contents of an object over MTP - public ParcelFileDescriptor openFile(int deviceID, int objectID) { + public ParcelFileDescriptor openFile(int deviceID, long objectID) { return native_open_file(deviceID, objectID); } @@ -101,8 +101,8 @@ public class MtpClient { private native final void native_finalize(); private native boolean native_start(); private native void native_stop(); - private native boolean native_delete_object(int deviceID, int objectID); - private native int native_get_parent(int deviceID, int objectID); - private native int native_get_storage_id(int deviceID, int objectID); - private native ParcelFileDescriptor native_open_file(int deviceID, int objectID); + private native boolean native_delete_object(int deviceID, long objectID); + private native long native_get_parent(int deviceID, long objectID); + private native long native_get_storage_id(int deviceID, long objectID); + private native ParcelFileDescriptor native_open_file(int deviceID, long objectID); } diff --git a/media/java/android/media/MtpCursor.java b/media/java/android/media/MtpCursor.java index d4142d8..b9dd03e 100644 --- a/media/java/android/media/MtpCursor.java +++ b/media/java/android/media/MtpCursor.java @@ -43,8 +43,8 @@ public final class MtpCursor extends AbstractWindowedCursor { private int mQueryType; private int mDeviceID; - private int mStorageID; - private int mQbjectID; + private long mStorageID; + private long mQbjectID; /** The names of the columns in the projection */ private String[] mColumns; @@ -54,7 +54,7 @@ public final class MtpCursor extends AbstractWindowedCursor { private final MtpClient mClient; - public MtpCursor(MtpClient client, int queryType, int deviceID, int storageID, int objectID, + public MtpCursor(MtpClient client, int queryType, int deviceID, long storageID, long objectID, String[] projection) { mClient = client; @@ -220,7 +220,7 @@ public final class MtpCursor extends AbstractWindowedCursor { private int mNativeContext; private native final void native_setup(MtpClient client, int queryType, - int deviceID, int storageID, int objectID, int[] columns); + int deviceID, long storageID, long objectID, int[] columns); private native final void native_finalize(); private native void native_wait_for_event(); private native int native_fill_window(CursorWindow window, int startPos); diff --git a/media/jni/android_media_MtpClient.cpp b/media/jni/android_media_MtpClient.cpp index 67740bc..d23185b 100644 --- a/media/jni/android_media_MtpClient.cpp +++ b/media/jni/android_media_MtpClient.cpp @@ -161,7 +161,7 @@ android_media_MtpClient_stop(JNIEnv *env, jobject thiz) static jboolean android_media_MtpClient_delete_object(JNIEnv *env, jobject thiz, - jint device_id, jint object_id) + jint device_id, jlong object_id) { #ifdef HAVE_ANDROID_OS MyClient *client = (MyClient *)env->GetIntField(thiz, field_context); @@ -173,9 +173,9 @@ android_media_MtpClient_delete_object(JNIEnv *env, jobject thiz, return NULL; } -static jint +static jlong android_media_MtpClient_get_parent(JNIEnv *env, jobject thiz, - jint device_id, jint object_id) + jint device_id, jlong object_id) { #ifdef HAVE_ANDROID_OS MyClient *client = (MyClient *)env->GetIntField(thiz, field_context); @@ -187,9 +187,9 @@ android_media_MtpClient_get_parent(JNIEnv *env, jobject thiz, return -1; } -static jint +static jlong android_media_MtpClient_get_storage_id(JNIEnv *env, jobject thiz, - jint device_id, jint object_id) + jint device_id, jlong object_id) { #ifdef HAVE_ANDROID_OS MyClient *client = (MyClient *)env->GetIntField(thiz, field_context); @@ -203,7 +203,7 @@ android_media_MtpClient_get_storage_id(JNIEnv *env, jobject thiz, static jobject android_media_MtpClient_open_file(JNIEnv *env, jobject thiz, - jint device_id, jint object_id) + jint device_id, jlong object_id) { #ifdef HAVE_ANDROID_OS MyClient *client = (MyClient *)env->GetIntField(thiz, field_context); @@ -240,10 +240,10 @@ static JNINativeMethod gMethods[] = { {"native_finalize", "()V", (void *)android_media_MtpClient_finalize}, {"native_start", "()Z", (void *)android_media_MtpClient_start}, {"native_stop", "()V", (void *)android_media_MtpClient_stop}, - {"native_delete_object", "(II)Z", (void *)android_media_MtpClient_delete_object}, - {"native_get_parent", "(II)I", (void *)android_media_MtpClient_get_parent}, - {"native_get_storage_id", "(II)I", (void *)android_media_MtpClient_get_storage_id}, - {"native_open_file", "(II)Landroid/os/ParcelFileDescriptor;", + {"native_delete_object", "(IJ)Z", (void *)android_media_MtpClient_delete_object}, + {"native_get_parent", "(IJ)J", (void *)android_media_MtpClient_get_parent}, + {"native_get_storage_id", "(IJ)J", (void *)android_media_MtpClient_get_storage_id}, + {"native_open_file", "(IJ)Landroid/os/ParcelFileDescriptor;", (void *)android_media_MtpClient_open_file}, }; diff --git a/media/jni/android_media_MtpCursor.cpp b/media/jni/android_media_MtpCursor.cpp index 6228b5d..6a65ffd 100644 --- a/media/jni/android_media_MtpCursor.cpp +++ b/media/jni/android_media_MtpCursor.cpp @@ -49,7 +49,7 @@ static bool ExceptionCheck(void* env) static void android_media_MtpCursor_setup(JNIEnv *env, jobject thiz, jobject javaClient, - jint queryType, jint deviceID, jint storageID, jint objectID, jintArray javaColumns) + jint queryType, jint deviceID, jlong storageID, jlong objectID, jintArray javaColumns) { #ifdef HAVE_ANDROID_OS LOGD("android_media_MtpCursor_setup queryType: %d deviceID: %d storageID: %d objectID: %d\n", @@ -104,7 +104,7 @@ android_media_MtpCursor_fill_window(JNIEnv *env, jobject thiz, jobject javaWindo // ---------------------------------------------------------------------------- static JNINativeMethod gMethods[] = { - {"native_setup", "(Landroid/media/MtpClient;IIII[I)V", + {"native_setup", "(Landroid/media/MtpClient;IIJJ[I)V", (void *)android_media_MtpCursor_setup}, {"native_finalize", "()V", (void *)android_media_MtpCursor_finalize}, {"native_fill_window", "(Landroid/database/CursorWindow;I)I", diff --git a/media/tests/CameraBrowser/Android.mk b/media/tests/CameraBrowser/Android.mk index 33d2976..1d81129 100644 --- a/media/tests/CameraBrowser/Android.mk +++ b/media/tests/CameraBrowser/Android.mk @@ -1,6 +1,8 @@ LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS) +LOCAL_MODULE_TAGS := tests + LOCAL_SRC_FILES := $(call all-subdir-java-files) LOCAL_PACKAGE_NAME := CameraBrowser diff --git a/media/tests/CameraBrowser/src/com/android/camerabrowser/ObjectBrowser.java b/media/tests/CameraBrowser/src/com/android/camerabrowser/ObjectBrowser.java index 329aa40..6d34fd4 100644 --- a/media/tests/CameraBrowser/src/com/android/camerabrowser/ObjectBrowser.java +++ b/media/tests/CameraBrowser/src/com/android/camerabrowser/ObjectBrowser.java @@ -44,8 +44,8 @@ public class ObjectBrowser extends ListActivity { private Cursor mCursor; private ObjectCursorAdapter mAdapter; private int mDeviceID; - private int mStorageID; - private int mObjectID; + private long mStorageID; + private long mObjectID; private static final String[] OBJECT_COLUMNS = new String[] { Mtp.Object._ID, Mtp.Object.NAME, Mtp.Object.FORMAT, Mtp.Object.THUMB }; @@ -65,8 +65,8 @@ public class ObjectBrowser extends ListActivity { super.onResume(); mDeviceID = getIntent().getIntExtra("device", 0); - mStorageID = getIntent().getIntExtra("storage", 0); - mObjectID = getIntent().getIntExtra("object", 0); + mStorageID = getIntent().getLongExtra("storage", 0); + mObjectID = getIntent().getLongExtra("object", 0); if (mDeviceID != 0 && mStorageID != 0) { Cursor c; Uri uri; @@ -88,7 +88,7 @@ public class ObjectBrowser extends ListActivity { @Override protected void onListItemClick(ListView l, View v, int position, long id) { - int rowID = (int)mAdapter.getItemId(position); + long rowID = mAdapter.getItemId(position); Cursor c = getContentResolver().query( Mtp.Object.getContentUri(mDeviceID, rowID), OBJECT_COLUMNS, null, null, null); @@ -111,7 +111,7 @@ public class ObjectBrowser extends ListActivity { Intent intent = new Intent(this, ObjectViewer.class); intent.putExtra("device", mDeviceID); intent.putExtra("storage", mStorageID); - intent.putExtra("object",rowID); + intent.putExtra("object", rowID); startActivity(intent); } } diff --git a/media/tests/CameraBrowser/src/com/android/camerabrowser/ObjectViewer.java b/media/tests/CameraBrowser/src/com/android/camerabrowser/ObjectViewer.java index 408f15e..5899bc1 100644 --- a/media/tests/CameraBrowser/src/com/android/camerabrowser/ObjectViewer.java +++ b/media/tests/CameraBrowser/src/com/android/camerabrowser/ObjectViewer.java @@ -51,8 +51,8 @@ public class ObjectViewer extends Activity { private static final String TAG = "ObjectViewer"; private int mDeviceID; - private int mStorageID; - private int mObjectID; + private long mStorageID; + private long mObjectID; private static final String[] OBJECT_COLUMNS = new String[] { Mtp.Object._ID, @@ -84,8 +84,8 @@ public class ObjectViewer extends Activity { super.onResume(); mDeviceID = getIntent().getIntExtra("device", 0); - mStorageID = getIntent().getIntExtra("storage", 0); - mObjectID = getIntent().getIntExtra("object", 0); + mStorageID = getIntent().getLongExtra("storage", 0); + mObjectID = getIntent().getLongExtra("object", 0); if (mDeviceID != 0 && mObjectID != 0) { Cursor c = getContentResolver().query( diff --git a/media/tests/CameraBrowser/src/com/android/camerabrowser/StorageBrowser.java b/media/tests/CameraBrowser/src/com/android/camerabrowser/StorageBrowser.java index 6ddf4e7..63e036e 100644 --- a/media/tests/CameraBrowser/src/com/android/camerabrowser/StorageBrowser.java +++ b/media/tests/CameraBrowser/src/com/android/camerabrowser/StorageBrowser.java @@ -70,7 +70,7 @@ public class StorageBrowser extends ListActivity { protected void onListItemClick(ListView l, View v, int position, long id) { Intent intent = new Intent(this, ObjectBrowser.class); intent.putExtra("device", mDeviceID); - intent.putExtra("storage", (int)mAdapter.getItemId(position)); + intent.putExtra("storage", mAdapter.getItemId(position)); startActivity(intent); } } |