AArch64: Use long for pointers in MTP classes

For storing pointers, long is used in MTP classes,
as native pointers can be 64-bit.

In addition, some minor changes have been done
to conform with standard JNI practice (e.g. use
of jint instead of int in JNI function prototypes)

Change-Id: I67805547251722e7b77611d47d0bb632a64d3e6d
Signed-off-by: Ashok Bhat <ashok.bhat@arm.com>
Signed-off-by: Marcus Oakland <marcus.oakland@arm.com>
Signed-off-by: Kévin PETIT <kevin.petit@arm.com>
diff --git a/media/java/android/mtp/MtpDatabase.java b/media/java/android/mtp/MtpDatabase.java
index cf1238a..9ceefc3 100755
--- a/media/java/android/mtp/MtpDatabase.java
+++ b/media/java/android/mtp/MtpDatabase.java
@@ -1036,7 +1036,7 @@
     }
 
     // used by the JNI code
-    private int mNativeContext;
+    private long mNativeContext;
 
     private native final void native_setup();
     private native final void native_finalize();
diff --git a/media/java/android/mtp/MtpDevice.java b/media/java/android/mtp/MtpDevice.java
index 3272fed..8310579 100644
--- a/media/java/android/mtp/MtpDevice.java
+++ b/media/java/android/mtp/MtpDevice.java
@@ -237,7 +237,7 @@
     }
 
     // used by the JNI code
-    private int mNativeContext;
+    private long mNativeContext;
 
     private native boolean native_open(String deviceName, int fd);
     private native void native_close();
diff --git a/media/java/android/mtp/MtpServer.java b/media/java/android/mtp/MtpServer.java
index f561cc0..266f78e 100644
--- a/media/java/android/mtp/MtpServer.java
+++ b/media/java/android/mtp/MtpServer.java
@@ -22,7 +22,7 @@
  */
 public class MtpServer implements Runnable {
 
-    private int mNativeContext; // accessed by native methods
+    private long mNativeContext; // accessed by native methods
 
     static {
         System.loadLibrary("media_jni");
diff --git a/media/jni/android_mtp_MtpDatabase.cpp b/media/jni/android_mtp_MtpDatabase.cpp
index 77c7966..72ce3cc 100644
--- a/media/jni/android_mtp_MtpDatabase.cpp
+++ b/media/jni/android_mtp_MtpDatabase.cpp
@@ -77,7 +77,7 @@
 
 
 MtpDatabase* getMtpDatabase(JNIEnv *env, jobject database) {
-    return (MtpDatabase *)env->GetIntField(database, field_context);
+    return (MtpDatabase *)env->GetLongField(database, field_context);
 }
 
 // ----------------------------------------------------------------------------
@@ -1075,17 +1075,17 @@
 android_mtp_MtpDatabase_setup(JNIEnv *env, jobject thiz)
 {
     MyMtpDatabase* database = new MyMtpDatabase(env, thiz);
-    env->SetIntField(thiz, field_context, (int)database);
+    env->SetLongField(thiz, field_context, (jlong)database);
     checkAndClearExceptionFromCallback(env, __FUNCTION__);
 }
 
 static void
 android_mtp_MtpDatabase_finalize(JNIEnv *env, jobject thiz)
 {
-    MyMtpDatabase* database = (MyMtpDatabase *)env->GetIntField(thiz, field_context);
+    MyMtpDatabase* database = (MyMtpDatabase *)env->GetLongField(thiz, field_context);
     database->cleanup(env);
     delete database;
-    env->SetIntField(thiz, field_context, 0);
+    env->SetLongField(thiz, field_context, 0);
     checkAndClearExceptionFromCallback(env, __FUNCTION__);
 }
 
@@ -1217,7 +1217,7 @@
         return -1;
     }
 
-    field_context = env->GetFieldID(clazz, "mNativeContext", "I");
+    field_context = env->GetFieldID(clazz, "mNativeContext", "J");
     if (field_context == NULL) {
         ALOGE("Can't find MtpDatabase.mNativeContext");
         return -1;
diff --git a/media/jni/android_mtp_MtpDevice.cpp b/media/jni/android_mtp_MtpDevice.cpp
index b61b66c..8e013a0 100644
--- a/media/jni/android_mtp_MtpDevice.cpp
+++ b/media/jni/android_mtp_MtpDevice.cpp
@@ -88,7 +88,7 @@
 
 MtpDevice* get_device_from_object(JNIEnv* env, jobject javaDevice)
 {
-    return (MtpDevice*)env->GetIntField(javaDevice, field_context);
+    return (MtpDevice*)env->GetLongField(javaDevice, field_context);
 }
 
 static void checkAndClearExceptionFromCallback(JNIEnv* env, const char* methodName) {
@@ -106,15 +106,15 @@
 {
     const char *deviceNameStr = env->GetStringUTFChars(deviceName, NULL);
     if (deviceNameStr == NULL) {
-        return false;
+        return JNI_FALSE;
     }
 
     MtpDevice* device = MtpDevice::open(deviceNameStr, fd);
     env->ReleaseStringUTFChars(deviceName, deviceNameStr);
 
     if (device)
-        env->SetIntField(thiz, field_context, (int)device);
-    return (device != NULL);
+        env->SetLongField(thiz, field_context,  (jlong)device);
+    return (jboolean)(device != NULL);
 }
 
 static void
@@ -124,7 +124,7 @@
     if (device) {
         device->close();
         delete device;
-        env->SetIntField(thiz, field_context, 0);
+        env->SetLongField(thiz, field_context, 0);
     }
 }
 
@@ -356,10 +356,11 @@
 android_mtp_MtpDevice_delete_object(JNIEnv *env, jobject thiz, jint object_id)
 {
     MtpDevice* device = get_device_from_object(env, thiz);
-    if (device)
-        return device->deleteObject(object_id);
-    else
-        return NULL;
+    if (device && device->deleteObject(object_id)) {
+        return JNI_TRUE;
+    } else {
+        return JNI_FALSE;
+    }
 }
 
 static jlong
@@ -367,7 +368,7 @@
 {
     MtpDevice* device = get_device_from_object(env, thiz);
     if (device)
-        return device->getParent(object_id);
+        return (jlong)device->getParent(object_id);
     else
         return -1;
 }
@@ -377,7 +378,7 @@
 {
     MtpDevice* device = get_device_from_object(env, thiz);
     if (device)
-        return device->getStorageID(object_id);
+        return (jlong)device->getStorageID(object_id);
     else
         return -1;
 }
@@ -389,15 +390,15 @@
     if (device) {
         const char *destPathStr = env->GetStringUTFChars(dest_path, NULL);
         if (destPathStr == NULL) {
-            return false;
+            return JNI_FALSE;
         }
 
-        bool result = device->readObject(object_id, destPathStr, AID_SDCARD_RW, 0664);
+        jboolean result = device->readObject(object_id, destPathStr, AID_SDCARD_RW, 0664);
         env->ReleaseStringUTFChars(dest_path, destPathStr);
         return result;
     }
 
-    return false;
+    return JNI_FALSE;
 }
 
 // ----------------------------------------------------------------------------
@@ -618,7 +619,7 @@
         ALOGE("Can't find android/mtp/MtpDevice");
         return -1;
     }
-    field_context = env->GetFieldID(clazz, "mNativeContext", "I");
+    field_context = env->GetFieldID(clazz, "mNativeContext", "J");
     if (field_context == NULL) {
         ALOGE("Can't find MtpDevice.mNativeContext");
         return -1;
diff --git a/media/jni/android_mtp_MtpServer.cpp b/media/jni/android_mtp_MtpServer.cpp
index 5252a3a..9d7f1c2 100644
--- a/media/jni/android_mtp_MtpServer.cpp
+++ b/media/jni/android_mtp_MtpServer.cpp
@@ -53,7 +53,7 @@
 extern MtpDatabase* getMtpDatabase(JNIEnv *env, jobject database);
 
 static inline MtpServer* getMtpServer(JNIEnv *env, jobject thiz) {
-    return (MtpServer*)env->GetIntField(thiz, field_MtpServer_nativeContext);
+    return (MtpServer*)env->GetLongField(thiz, field_MtpServer_nativeContext);
 }
 
 static void
@@ -63,7 +63,7 @@
     if (fd >= 0) {
         MtpServer* server = new MtpServer(fd, getMtpDatabase(env, javaDatabase),
                 usePtp, AID_MEDIA_RW, 0664, 0775);
-        env->SetIntField(thiz, field_MtpServer_nativeContext, (int)server);
+        env->SetLongField(thiz, field_MtpServer_nativeContext, (jlong)server);
     } else {
         ALOGE("could not open MTP driver, errno: %d", errno);
     }
@@ -87,7 +87,7 @@
     MtpServer* server = getMtpServer(env, thiz);
     if (server) {
         delete server;
-        env->SetIntField(thiz, field_MtpServer_nativeContext, 0);
+        env->SetLongField(thiz, field_MtpServer_nativeContext, 0);
     } else {
         ALOGE("server is null in cleanup");
     }
@@ -226,7 +226,7 @@
         ALOGE("Can't find android/mtp/MtpServer");
         return -1;
     }
-    field_MtpServer_nativeContext = env->GetFieldID(clazz, "mNativeContext", "I");
+    field_MtpServer_nativeContext = env->GetFieldID(clazz, "mNativeContext", "J");
     if (field_MtpServer_nativeContext == NULL) {
         ALOGE("Can't find MtpServer.mNativeContext");
         return -1;