AArch64: Use long for pointers in media classes

For storing pointers, long is used in media 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: Idc4ca0124d03df7f9cef412488abafd020e5e774
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/core/jni/android_media_AudioRecord.cpp b/core/jni/android_media_AudioRecord.cpp
index 1c43cc5..b22668b 100644
--- a/core/jni/android_media_AudioRecord.cpp
+++ b/core/jni/android_media_AudioRecord.cpp
@@ -136,7 +136,7 @@
 {
     Mutex::Autolock l(sLock);
     AudioRecord* const ar =
-            (AudioRecord*)env->GetIntField(thiz, javaAudioRecordFields.nativeRecorderInJavaObj);
+            (AudioRecord*)env->GetLongField(thiz, javaAudioRecordFields.nativeRecorderInJavaObj);
     return sp<AudioRecord>(ar);
 }
 
@@ -144,19 +144,19 @@
 {
     Mutex::Autolock l(sLock);
     sp<AudioRecord> old =
-            (AudioRecord*)env->GetIntField(thiz, javaAudioRecordFields.nativeRecorderInJavaObj);
+            (AudioRecord*)env->GetLongField(thiz, javaAudioRecordFields.nativeRecorderInJavaObj);
     if (ar.get()) {
         ar->incStrong((void*)setAudioRecord);
     }
     if (old != 0) {
         old->decStrong((void*)setAudioRecord);
     }
-    env->SetIntField(thiz, javaAudioRecordFields.nativeRecorderInJavaObj, (int)ar.get());
+    env->SetLongField(thiz, javaAudioRecordFields.nativeRecorderInJavaObj, (jlong)ar.get());
     return old;
 }
 
 // ----------------------------------------------------------------------------
-static int
+static jint
 android_media_AudioRecord_setup(JNIEnv *env, jobject thiz, jobject weak_this,
         jint source, jint sampleRateInHertz, jint channelMask,
                 // Java channel masks map directly to the native definition
@@ -168,7 +168,7 @@
 
     if (!audio_is_input_channel(channelMask)) {
         ALOGE("Error creating AudioRecord: channel mask %#x is not valid.", channelMask);
-        return AUDIORECORD_ERROR_SETUP_INVALIDCHANNELMASK;
+        return (jint) AUDIORECORD_ERROR_SETUP_INVALIDCHANNELMASK;
     }
     uint32_t nbChannels = popcount(channelMask);
 
@@ -176,7 +176,7 @@
     if ((audioFormat != ENCODING_PCM_16BIT)
         && (audioFormat != ENCODING_PCM_8BIT)) {
         ALOGE("Error creating AudioRecord: unsupported audio format.");
-        return AUDIORECORD_ERROR_SETUP_INVALIDFORMAT;
+        return (jint) AUDIORECORD_ERROR_SETUP_INVALIDFORMAT;
     }
 
     int bytesPerSample = audioFormat == ENCODING_PCM_16BIT ? 2 : 1;
@@ -185,31 +185,31 @@
 
     if (buffSizeInBytes == 0) {
          ALOGE("Error creating AudioRecord: frameCount is 0.");
-        return AUDIORECORD_ERROR_SETUP_ZEROFRAMECOUNT;
+        return (jint) AUDIORECORD_ERROR_SETUP_ZEROFRAMECOUNT;
     }
     int frameSize = nbChannels * bytesPerSample;
     size_t frameCount = buffSizeInBytes / frameSize;
 
     if ((uint32_t(source) >= AUDIO_SOURCE_CNT) && (uint32_t(source) != AUDIO_SOURCE_HOTWORD)) {
         ALOGE("Error creating AudioRecord: unknown source.");
-        return AUDIORECORD_ERROR_SETUP_INVALIDSOURCE;
+        return (jint) AUDIORECORD_ERROR_SETUP_INVALIDSOURCE;
     }
 
     jclass clazz = env->GetObjectClass(thiz);
     if (clazz == NULL) {
         ALOGE("Can't find %s when setting up callback.", kClassPathName);
-        return AUDIORECORD_ERROR_SETUP_NATIVEINITFAILED;
+        return (jint) AUDIORECORD_ERROR_SETUP_NATIVEINITFAILED;
     }
 
     if (jSession == NULL) {
         ALOGE("Error creating AudioRecord: invalid session ID pointer");
-        return AUDIORECORD_ERROR;
+        return (jint) AUDIORECORD_ERROR;
     }
 
     jint* nSession = (jint *) env->GetPrimitiveArrayCritical(jSession, NULL);
     if (nSession == NULL) {
         ALOGE("Error creating AudioRecord: Error retrieving session id pointer");
-        return AUDIORECORD_ERROR;
+        return (jint) AUDIORECORD_ERROR;
     }
     int sessionId = nSession[0];
     env->ReleasePrimitiveArrayCritical(jSession, nSession, 0);
@@ -262,33 +262,33 @@
 
     // save our newly created callback information in the "nativeCallbackCookie" field
     // of the Java object (in mNativeCallbackCookie) so we can free the memory in finalize()
-    env->SetIntField(thiz, javaAudioRecordFields.nativeCallbackCookie, (int)lpCallbackData);
+    env->SetLongField(thiz, javaAudioRecordFields.nativeCallbackCookie, (jlong)lpCallbackData);
 
-    return AUDIORECORD_SUCCESS;
+    return (jint) AUDIORECORD_SUCCESS;
 
     // failure:
 native_init_failure:
     env->DeleteGlobalRef(lpCallbackData->audioRecord_class);
     env->DeleteGlobalRef(lpCallbackData->audioRecord_ref);
     delete lpCallbackData;
-    env->SetIntField(thiz, javaAudioRecordFields.nativeCallbackCookie, 0);
+    env->SetLongField(thiz, javaAudioRecordFields.nativeCallbackCookie, 0);
 
-    return AUDIORECORD_ERROR_SETUP_NATIVEINITFAILED;
+    return (jint) AUDIORECORD_ERROR_SETUP_NATIVEINITFAILED;
 }
 
 
 
 // ----------------------------------------------------------------------------
-static int
+static jint
 android_media_AudioRecord_start(JNIEnv *env, jobject thiz, jint event, jint triggerSession)
 {
     sp<AudioRecord> lpRecorder = getAudioRecord(env, thiz);
     if (lpRecorder == NULL ) {
         jniThrowException(env, "java/lang/IllegalStateException", NULL);
-        return AUDIORECORD_ERROR;
+        return (jint) AUDIORECORD_ERROR;
     }
 
-    return android_media_translateRecorderErrorCode(
+    return (jint) android_media_translateRecorderErrorCode(
             lpRecorder->start((AudioSystem::sync_event_t)event, triggerSession));
 }
 
@@ -319,12 +319,12 @@
     ALOGV("About to delete lpRecorder: %x\n", (int)lpRecorder.get());
     lpRecorder->stop();
 
-    audiorecord_callback_cookie *lpCookie = (audiorecord_callback_cookie *)env->GetIntField(
+    audiorecord_callback_cookie *lpCookie = (audiorecord_callback_cookie *)env->GetLongField(
         thiz, javaAudioRecordFields.nativeCallbackCookie);
 
     // reset the native resources in the Java object so any attempt to access
     // them after a call to release fails.
-    env->SetIntField(thiz, javaAudioRecordFields.nativeCallbackCookie, 0);
+    env->SetLongField(thiz, javaAudioRecordFields.nativeCallbackCookie, 0);
 
     // delete the callback information
     if (lpCookie) {
@@ -585,7 +585,7 @@
     //    mNativeRecorderInJavaObj
     javaAudioRecordFields.nativeRecorderInJavaObj =
         env->GetFieldID(audioRecordClass,
-                        JAVA_NATIVERECORDERINJAVAOBJ_FIELD_NAME, "I");
+                        JAVA_NATIVERECORDERINJAVAOBJ_FIELD_NAME, "J");
     if (javaAudioRecordFields.nativeRecorderInJavaObj == NULL) {
         ALOGE("Can't find AudioRecord.%s", JAVA_NATIVERECORDERINJAVAOBJ_FIELD_NAME);
         return -1;
@@ -593,7 +593,7 @@
     //     mNativeCallbackCookie
     javaAudioRecordFields.nativeCallbackCookie = env->GetFieldID(
             audioRecordClass,
-            JAVA_NATIVECALLBACKINFO_FIELD_NAME, "I");
+            JAVA_NATIVECALLBACKINFO_FIELD_NAME, "J");
     if (javaAudioRecordFields.nativeCallbackCookie == NULL) {
         ALOGE("Can't find AudioRecord.%s", JAVA_NATIVECALLBACKINFO_FIELD_NAME);
         return -1;
diff --git a/core/jni/android_media_AudioSystem.cpp b/core/jni/android_media_AudioSystem.cpp
index 7d99464..a19d111 100644
--- a/core/jni/android_media_AudioSystem.cpp
+++ b/core/jni/android_media_AudioSystem.cpp
@@ -52,10 +52,10 @@
     return kAudioStatusError;
 }
 
-static int
+static jint
 android_media_AudioSystem_muteMicrophone(JNIEnv *env, jobject thiz, jboolean on)
 {
-    return check_AudioSystem_Command(AudioSystem::muteMicrophone(on));
+    return (jint) check_AudioSystem_Command(AudioSystem::muteMicrophone(on));
 }
 
 static jboolean
@@ -91,7 +91,7 @@
     return state;
 }
 
-static int
+static jint
 android_media_AudioSystem_setParameters(JNIEnv *env, jobject thiz, jstring keyValuePairs)
 {
     const jchar* c_keyValuePairs = env->GetStringCritical(keyValuePairs, 0);
@@ -101,7 +101,7 @@
         env->ReleaseStringCritical(keyValuePairs, c_keyValuePairs);
     }
     int status = check_AudioSystem_Command(AudioSystem::setParameters(0, c_keyValuePairs8));
-    return status;
+    return (jint) status;
 }
 
 static jstring
@@ -131,7 +131,7 @@
                               check_AudioSystem_Command(err));
 }
 
-static int
+static jint
 android_media_AudioSystem_setDeviceConnectionState(JNIEnv *env, jobject thiz, jint device, jint state, jstring device_address)
 {
     const char *c_address = env->GetStringUTFChars(device_address, NULL);
@@ -139,60 +139,60 @@
                                           static_cast <audio_policy_dev_state_t>(state),
                                           c_address));
     env->ReleaseStringUTFChars(device_address, c_address);
-    return status;
+    return (jint) status;
 }
 
-static int
+static jint
 android_media_AudioSystem_getDeviceConnectionState(JNIEnv *env, jobject thiz, jint device, jstring device_address)
 {
     const char *c_address = env->GetStringUTFChars(device_address, NULL);
     int state = static_cast <int>(AudioSystem::getDeviceConnectionState(static_cast <audio_devices_t>(device),
                                           c_address));
     env->ReleaseStringUTFChars(device_address, c_address);
-    return state;
+    return (jint) state;
 }
 
-static int
+static jint
 android_media_AudioSystem_setPhoneState(JNIEnv *env, jobject thiz, jint state)
 {
-    return check_AudioSystem_Command(AudioSystem::setPhoneState((audio_mode_t) state));
+    return (jint) check_AudioSystem_Command(AudioSystem::setPhoneState((audio_mode_t) state));
 }
 
-static int
+static jint
 android_media_AudioSystem_setForceUse(JNIEnv *env, jobject thiz, jint usage, jint config)
 {
-    return check_AudioSystem_Command(AudioSystem::setForceUse(static_cast <audio_policy_force_use_t>(usage),
+    return (jint) check_AudioSystem_Command(AudioSystem::setForceUse(static_cast <audio_policy_force_use_t>(usage),
                                                            static_cast <audio_policy_forced_cfg_t>(config)));
 }
 
-static int
+static jint
 android_media_AudioSystem_getForceUse(JNIEnv *env, jobject thiz, jint usage)
 {
-    return static_cast <int>(AudioSystem::getForceUse(static_cast <audio_policy_force_use_t>(usage)));
+    return static_cast <jint>(AudioSystem::getForceUse(static_cast <audio_policy_force_use_t>(usage)));
 }
 
-static int
+static jint
 android_media_AudioSystem_initStreamVolume(JNIEnv *env, jobject thiz, jint stream, jint indexMin, jint indexMax)
 {
-    return check_AudioSystem_Command(AudioSystem::initStreamVolume(static_cast <audio_stream_type_t>(stream),
+    return (jint) check_AudioSystem_Command(AudioSystem::initStreamVolume(static_cast <audio_stream_type_t>(stream),
                                                                    indexMin,
                                                                    indexMax));
 }
 
-static int
+static jint
 android_media_AudioSystem_setStreamVolumeIndex(JNIEnv *env,
                                                jobject thiz,
                                                jint stream,
                                                jint index,
                                                jint device)
 {
-    return check_AudioSystem_Command(
+    return (jint) check_AudioSystem_Command(
             AudioSystem::setStreamVolumeIndex(static_cast <audio_stream_type_t>(stream),
                                               index,
                                               (audio_devices_t)device));
 }
 
-static int
+static jint
 android_media_AudioSystem_getStreamVolumeIndex(JNIEnv *env,
                                                jobject thiz,
                                                jint stream,
@@ -205,13 +205,13 @@
             != NO_ERROR) {
         index = -1;
     }
-    return index;
+    return (jint) index;
 }
 
-static int
+static jint
 android_media_AudioSystem_setMasterVolume(JNIEnv *env, jobject thiz, jfloat value)
 {
-    return check_AudioSystem_Command(AudioSystem::setMasterVolume(value));
+    return (jint) check_AudioSystem_Command(AudioSystem::setMasterVolume(value));
 }
 
 static jfloat
@@ -224,10 +224,10 @@
     return value;
 }
 
-static int
+static jint
 android_media_AudioSystem_setMasterMute(JNIEnv *env, jobject thiz, jboolean mute)
 {
-    return check_AudioSystem_Command(AudioSystem::setMasterMute(mute));
+    return (jint) check_AudioSystem_Command(AudioSystem::setMasterMute(mute));
 }
 
 static jfloat
@@ -275,10 +275,10 @@
     return (jint) AudioSystem::setLowRamDevice((bool) isLowRamDevice);
 }
 
-static int
+static jint
 android_media_AudioSystem_checkAudioFlinger(JNIEnv *env, jobject clazz)
 {
-    return check_AudioSystem_Command(AudioSystem::checkAudioFlinger());
+    return (jint) check_AudioSystem_Command(AudioSystem::checkAudioFlinger());
 }
 
 // ----------------------------------------------------------------------------
diff --git a/core/jni/android_media_AudioTrack.cpp b/core/jni/android_media_AudioTrack.cpp
index 225bf06..dc8d9d8 100644
--- a/core/jni/android_media_AudioTrack.cpp
+++ b/core/jni/android_media_AudioTrack.cpp
@@ -174,7 +174,7 @@
 {
     Mutex::Autolock l(sLock);
     AudioTrack* const at =
-            (AudioTrack*)env->GetIntField(thiz, javaAudioTrackFields.nativeTrackInJavaObj);
+            (AudioTrack*)env->GetLongField(thiz, javaAudioTrackFields.nativeTrackInJavaObj);
     return sp<AudioTrack>(at);
 }
 
@@ -182,19 +182,19 @@
 {
     Mutex::Autolock l(sLock);
     sp<AudioTrack> old =
-            (AudioTrack*)env->GetIntField(thiz, javaAudioTrackFields.nativeTrackInJavaObj);
+            (AudioTrack*)env->GetLongField(thiz, javaAudioTrackFields.nativeTrackInJavaObj);
     if (at.get()) {
         at->incStrong((void*)setAudioTrack);
     }
     if (old != 0) {
         old->decStrong((void*)setAudioTrack);
     }
-    env->SetIntField(thiz, javaAudioTrackFields.nativeTrackInJavaObj, (int)at.get());
+    env->SetLongField(thiz, javaAudioTrackFields.nativeTrackInJavaObj, (jlong)at.get());
     return old;
 }
 
 // ----------------------------------------------------------------------------
-static int
+static jint
 android_media_AudioTrack_native_setup(JNIEnv *env, jobject thiz, jobject weak_this,
         jint streamType, jint sampleRateInHertz, jint javaChannelMask,
         jint audioFormat, jint buffSizeInBytes, jint memoryMode, jintArray jSession)
@@ -206,11 +206,11 @@
 
     if (AudioSystem::getOutputFrameCount(&afFrameCount, (audio_stream_type_t) streamType) != NO_ERROR) {
         ALOGE("Error creating AudioTrack: Could not get AudioSystem frame count.");
-        return AUDIOTRACK_ERROR_SETUP_AUDIOSYSTEM;
+        return (jint) AUDIOTRACK_ERROR_SETUP_AUDIOSYSTEM;
     }
     if (AudioSystem::getOutputSamplingRate(&afSampleRate, (audio_stream_type_t) streamType) != NO_ERROR) {
         ALOGE("Error creating AudioTrack: Could not get AudioSystem sampling rate.");
-        return AUDIOTRACK_ERROR_SETUP_AUDIOSYSTEM;
+        return (jint) AUDIOTRACK_ERROR_SETUP_AUDIOSYSTEM;
     }
 
     // Java channel masks don't map directly to the native definition, but it's a simple shift
@@ -219,7 +219,7 @@
 
     if (!audio_is_output_channel(nativeChannelMask)) {
         ALOGE("Error creating AudioTrack: invalid channel mask %#x.", javaChannelMask);
-        return AUDIOTRACK_ERROR_SETUP_INVALIDCHANNELMASK;
+        return (jint) AUDIOTRACK_ERROR_SETUP_INVALIDCHANNELMASK;
     }
 
     int nbChannels = popcount(nativeChannelMask);
@@ -239,7 +239,7 @@
         break;
     default:
         ALOGE("Error creating AudioTrack: unknown stream type.");
-        return AUDIOTRACK_ERROR_SETUP_INVALIDSTREAMTYPE;
+        return (jint) AUDIOTRACK_ERROR_SETUP_INVALIDSTREAMTYPE;
     }
 
     // check the format.
@@ -247,7 +247,7 @@
     if ((audioFormat != ENCODING_PCM_16BIT) && (audioFormat != ENCODING_PCM_8BIT)) {
 
         ALOGE("Error creating AudioTrack: unsupported audio format.");
-        return AUDIOTRACK_ERROR_SETUP_INVALIDFORMAT;
+        return (jint) AUDIOTRACK_ERROR_SETUP_INVALIDFORMAT;
     }
 
     // for the moment 8bitPCM in MODE_STATIC is not supported natively in the AudioTrack C++ class
@@ -272,18 +272,18 @@
     jclass clazz = env->GetObjectClass(thiz);
     if (clazz == NULL) {
         ALOGE("Can't find %s when setting up callback.", kClassPathName);
-        return AUDIOTRACK_ERROR_SETUP_NATIVEINITFAILED;
+        return (jint) AUDIOTRACK_ERROR_SETUP_NATIVEINITFAILED;
     }
 
     if (jSession == NULL) {
         ALOGE("Error creating AudioTrack: invalid session ID pointer");
-        return AUDIOTRACK_ERROR;
+        return (jint) AUDIOTRACK_ERROR;
     }
 
     jint* nSession = (jint *) env->GetPrimitiveArrayCritical(jSession, NULL);
     if (nSession == NULL) {
         ALOGE("Error creating AudioTrack: Error retrieving session id pointer");
-        return AUDIOTRACK_ERROR;
+        return (jint) AUDIOTRACK_ERROR;
     }
     int sessionId = nSession[0];
     env->ReleasePrimitiveArrayCritical(jSession, nSession, 0);
@@ -370,10 +370,10 @@
     setAudioTrack(env, thiz, lpTrack);
 
     // save the JNI resources so we can free them later
-    //ALOGV("storing lpJniStorage: %x\n", (int)lpJniStorage);
-    env->SetIntField(thiz, javaAudioTrackFields.jniData, (int)lpJniStorage);
+    //ALOGV("storing lpJniStorage: %x\n", (long)lpJniStorage);
+    env->SetLongField(thiz, javaAudioTrackFields.jniData, (jlong)lpJniStorage);
 
-    return AUDIOTRACK_SUCCESS;
+    return (jint) AUDIOTRACK_SUCCESS;
 
     // failures:
 native_init_failure:
@@ -383,9 +383,9 @@
     env->DeleteGlobalRef(lpJniStorage->mCallbackData.audioTrack_class);
     env->DeleteGlobalRef(lpJniStorage->mCallbackData.audioTrack_ref);
     delete lpJniStorage;
-    env->SetIntField(thiz, javaAudioTrackFields.jniData, 0);
+    env->SetLongField(thiz, javaAudioTrackFields.jniData, 0);
 
-    return AUDIOTRACK_ERROR_SETUP_NATIVEINITFAILED;
+    return (jint) AUDIOTRACK_ERROR_SETUP_NATIVEINITFAILED;
 }
 
 
@@ -474,11 +474,11 @@
     lpTrack->stop();
 
     // delete the JNI data
-    AudioTrackJniStorage* pJniStorage = (AudioTrackJniStorage *)env->GetIntField(
+    AudioTrackJniStorage* pJniStorage = (AudioTrackJniStorage *)env->GetLongField(
         thiz, javaAudioTrackFields.jniData);
     // reset the native resources in the Java object so any attempt to access
     // them after a call to release fails.
-    env->SetIntField(thiz, javaAudioTrackFields.jniData, 0);
+    env->SetLongField(thiz, javaAudioTrackFields.jniData, 0);
 
     if (pJniStorage) {
         Mutex::Autolock l(sLock);
@@ -955,7 +955,7 @@
     //      nativeTrackInJavaObj
     javaAudioTrackFields.nativeTrackInJavaObj = env->GetFieldID(
             audioTrackClass,
-            JAVA_NATIVETRACKINJAVAOBJ_FIELD_NAME, "I");
+            JAVA_NATIVETRACKINJAVAOBJ_FIELD_NAME, "J");
     if (javaAudioTrackFields.nativeTrackInJavaObj == NULL) {
         ALOGE("Can't find AudioTrack.%s", JAVA_NATIVETRACKINJAVAOBJ_FIELD_NAME);
         return -1;
@@ -963,7 +963,7 @@
     //      jniData;
     javaAudioTrackFields.jniData = env->GetFieldID(
             audioTrackClass,
-            JAVA_JNIDATA_FIELD_NAME, "I");
+            JAVA_JNIDATA_FIELD_NAME, "J");
     if (javaAudioTrackFields.jniData == NULL) {
         ALOGE("Can't find AudioTrack.%s", JAVA_JNIDATA_FIELD_NAME);
         return -1;
diff --git a/core/jni/android_media_JetPlayer.cpp b/core/jni/android_media_JetPlayer.cpp
index 5795aba..69f5711 100644
--- a/core/jni/android_media_JetPlayer.cpp
+++ b/core/jni/android_media_JetPlayer.cpp
@@ -87,12 +87,12 @@
     if (result==EAS_SUCCESS) {
         // save our newly created C++ JetPlayer in the "nativePlayerInJavaObj" field
         // of the Java object (in mNativePlayerInJavaObj)
-        env->SetIntField(thiz, javaJetPlayerFields.nativePlayerInJavaObj, (int)lpJet);
+        env->SetLongField(thiz, javaJetPlayerFields.nativePlayerInJavaObj, (jlong)lpJet);
         return JNI_TRUE;
     } else {
         ALOGE("android_media_JetPlayer_setup(): initialization failed with EAS error code %d", (int)result);
         delete lpJet;
-        env->SetIntField(weak_this, javaJetPlayerFields.nativePlayerInJavaObj, 0);
+        env->SetLongField(weak_this, javaJetPlayerFields.nativePlayerInJavaObj, 0);
         return JNI_FALSE;
     }
 }
@@ -103,7 +103,7 @@
 android_media_JetPlayer_finalize(JNIEnv *env, jobject thiz)
 {
     ALOGV("android_media_JetPlayer_finalize(): entering.");
-    JetPlayer *lpJet = (JetPlayer *)env->GetIntField(
+    JetPlayer *lpJet = (JetPlayer *)env->GetLongField(
         thiz, javaJetPlayerFields.nativePlayerInJavaObj);
     if (lpJet != NULL) {
         lpJet->release();
@@ -119,7 +119,7 @@
 android_media_JetPlayer_release(JNIEnv *env, jobject thiz)
 {
     android_media_JetPlayer_finalize(env, thiz);
-    env->SetIntField(thiz, javaJetPlayerFields.nativePlayerInJavaObj, 0);
+    env->SetLongField(thiz, javaJetPlayerFields.nativePlayerInJavaObj, 0);
     ALOGV("android_media_JetPlayer_release() done");
 }
 
@@ -128,7 +128,7 @@
 static jboolean
 android_media_JetPlayer_loadFromFile(JNIEnv *env, jobject thiz, jstring path)
 {
-    JetPlayer *lpJet = (JetPlayer *)env->GetIntField(
+    JetPlayer *lpJet = (JetPlayer *)env->GetLongField(
         thiz, javaJetPlayerFields.nativePlayerInJavaObj);
     if (lpJet == NULL) {
         jniThrowException(env, "java/lang/IllegalStateException",
@@ -165,7 +165,7 @@
 android_media_JetPlayer_loadFromFileD(JNIEnv *env, jobject thiz,
     jobject fileDescriptor, jlong offset, jlong length)
 {
-    JetPlayer *lpJet = (JetPlayer *)env->GetIntField(
+    JetPlayer *lpJet = (JetPlayer *)env->GetLongField(
         thiz, javaJetPlayerFields.nativePlayerInJavaObj);
     if (lpJet == NULL) {
         jniThrowException(env, "java/lang/IllegalStateException",
@@ -195,7 +195,7 @@
 static jboolean
 android_media_JetPlayer_closeFile(JNIEnv *env, jobject thiz)
 {
-    JetPlayer *lpJet = (JetPlayer *)env->GetIntField(
+    JetPlayer *lpJet = (JetPlayer *)env->GetLongField(
         thiz, javaJetPlayerFields.nativePlayerInJavaObj);
     if (lpJet == NULL) {
         jniThrowException(env, "java/lang/IllegalStateException",
@@ -217,7 +217,7 @@
 static jboolean
 android_media_JetPlayer_play(JNIEnv *env, jobject thiz)
 {
-    JetPlayer *lpJet = (JetPlayer *)env->GetIntField(
+    JetPlayer *lpJet = (JetPlayer *)env->GetLongField(
         thiz, javaJetPlayerFields.nativePlayerInJavaObj);
     if (lpJet == NULL) {
         jniThrowException(env, "java/lang/IllegalStateException",
@@ -241,7 +241,7 @@
 static jboolean
 android_media_JetPlayer_pause(JNIEnv *env, jobject thiz)
 {
-    JetPlayer *lpJet = (JetPlayer *)env->GetIntField(
+    JetPlayer *lpJet = (JetPlayer *)env->GetLongField(
         thiz, javaJetPlayerFields.nativePlayerInJavaObj);
     if (lpJet == NULL) {
         jniThrowException(env, "java/lang/IllegalStateException",
@@ -271,7 +271,7 @@
         jint segmentNum, jint libNum, jint repeatCount, jint transpose, jint muteFlags,
         jbyte userID)
 {
-    JetPlayer *lpJet = (JetPlayer *)env->GetIntField(
+    JetPlayer *lpJet = (JetPlayer *)env->GetLongField(
         thiz, javaJetPlayerFields.nativePlayerInJavaObj);
     if (lpJet == NULL) {
         jniThrowException(env, "java/lang/IllegalStateException",
@@ -298,7 +298,7 @@
         jint segmentNum, jint libNum, jint repeatCount, jint transpose, jbooleanArray muteArray,
         jbyte userID)
 {
-    JetPlayer *lpJet = (JetPlayer *)env->GetIntField(
+    JetPlayer *lpJet = (JetPlayer *)env->GetLongField(
         thiz, javaJetPlayerFields.nativePlayerInJavaObj);
     if (lpJet == NULL) {
         jniThrowException(env, "java/lang/IllegalStateException",
@@ -344,7 +344,7 @@
 android_media_JetPlayer_setMuteFlags(JNIEnv *env, jobject thiz,
          jint muteFlags /*unsigned?*/, jboolean bSync)
 {
-    JetPlayer *lpJet = (JetPlayer *)env->GetIntField(
+    JetPlayer *lpJet = (JetPlayer *)env->GetLongField(
         thiz, javaJetPlayerFields.nativePlayerInJavaObj);
     if (lpJet == NULL) {
         jniThrowException(env, "java/lang/IllegalStateException",
@@ -369,7 +369,7 @@
 android_media_JetPlayer_setMuteArray(JNIEnv *env, jobject thiz,
         jbooleanArray muteArray, jboolean bSync)
 {
-    JetPlayer *lpJet = (JetPlayer *)env->GetIntField(
+    JetPlayer *lpJet = (JetPlayer *)env->GetLongField(
         thiz, javaJetPlayerFields.nativePlayerInJavaObj);
     if (lpJet == NULL) {
         jniThrowException(env, "java/lang/IllegalStateException",
@@ -415,7 +415,7 @@
 android_media_JetPlayer_setMuteFlag(JNIEnv *env, jobject thiz,
          jint trackId, jboolean muteFlag, jboolean bSync)
 {
-    JetPlayer *lpJet = (JetPlayer *)env->GetIntField(
+    JetPlayer *lpJet = (JetPlayer *)env->GetLongField(
         thiz, javaJetPlayerFields.nativePlayerInJavaObj);
     if (lpJet == NULL) {
         jniThrowException(env, "java/lang/IllegalStateException",
@@ -441,7 +441,7 @@
 static jboolean
 android_media_JetPlayer_triggerClip(JNIEnv *env, jobject thiz, jint clipId)
 {
-    JetPlayer *lpJet = (JetPlayer *)env->GetIntField(
+    JetPlayer *lpJet = (JetPlayer *)env->GetLongField(
         thiz, javaJetPlayerFields.nativePlayerInJavaObj);
     if (lpJet == NULL) {
         jniThrowException(env, "java/lang/IllegalStateException",
@@ -466,7 +466,7 @@
 static jboolean
 android_media_JetPlayer_clearQueue(JNIEnv *env, jobject thiz)
 {
-    JetPlayer *lpJet = (JetPlayer *)env->GetIntField(
+    JetPlayer *lpJet = (JetPlayer *)env->GetLongField(
         thiz, javaJetPlayerFields.nativePlayerInJavaObj);
     if (lpJet == NULL) {
         jniThrowException(env, "java/lang/IllegalStateException",
@@ -533,7 +533,7 @@
     // Get the mNativePlayerInJavaObj variable field
     javaJetPlayerFields.nativePlayerInJavaObj = env->GetFieldID(
             jetPlayerClass,
-            JAVA_NATIVEJETPLAYERINJAVAOBJ_FIELD_NAME, "I");
+            JAVA_NATIVEJETPLAYERINJAVAOBJ_FIELD_NAME, "J");
     if (javaJetPlayerFields.nativePlayerInJavaObj == NULL) {
         ALOGE("Can't find JetPlayer.%s", JAVA_NATIVEJETPLAYERINJAVAOBJ_FIELD_NAME);
         return -1;
diff --git a/core/jni/android_media_RemoteDisplay.cpp b/core/jni/android_media_RemoteDisplay.cpp
index 463be5e..1cd3fbb 100644
--- a/core/jni/android_media_RemoteDisplay.cpp
+++ b/core/jni/android_media_RemoteDisplay.cpp
@@ -134,7 +134,7 @@
 
 // ----------------------------------------------------------------------------
 
-static jint nativeListen(JNIEnv* env, jobject remoteDisplayObj, jstring ifaceStr) {
+static jlong nativeListen(JNIEnv* env, jobject remoteDisplayObj, jstring ifaceStr) {
     ScopedUtfChars iface(env, ifaceStr);
 
     sp<IServiceManager> sm = defaultServiceManager();
@@ -155,20 +155,20 @@
     }
 
     NativeRemoteDisplay* wrapper = new NativeRemoteDisplay(display, client);
-    return reinterpret_cast<jint>(wrapper);
+    return reinterpret_cast<jlong>(wrapper);
 }
 
-static void nativePause(JNIEnv* env, jobject remoteDisplayObj, jint ptr) {
+static void nativePause(JNIEnv* env, jobject remoteDisplayObj, jlong ptr) {
     NativeRemoteDisplay* wrapper = reinterpret_cast<NativeRemoteDisplay*>(ptr);
     wrapper->pause();
 }
 
-static void nativeResume(JNIEnv* env, jobject remoteDisplayObj, jint ptr) {
+static void nativeResume(JNIEnv* env, jobject remoteDisplayObj, jlong ptr) {
     NativeRemoteDisplay* wrapper = reinterpret_cast<NativeRemoteDisplay*>(ptr);
     wrapper->resume();
 }
 
-static void nativeDispose(JNIEnv* env, jobject remoteDisplayObj, jint ptr) {
+static void nativeDispose(JNIEnv* env, jobject remoteDisplayObj, jlong ptr) {
     NativeRemoteDisplay* wrapper = reinterpret_cast<NativeRemoteDisplay*>(ptr);
     delete wrapper;
 }
@@ -176,13 +176,13 @@
 // ----------------------------------------------------------------------------
 
 static JNINativeMethod gMethods[] = {
-    {"nativeListen", "(Ljava/lang/String;)I",
+    {"nativeListen", "(Ljava/lang/String;)J",
             (void*)nativeListen },
-    {"nativeDispose", "(I)V",
+    {"nativeDispose", "(J)V",
             (void*)nativeDispose },
-    {"nativePause", "(I)V",
+    {"nativePause", "(J)V",
             (void*)nativePause },
-    {"nativeResume", "(I)V",
+    {"nativeResume", "(J)V",
             (void*)nativeResume },
 };
 
diff --git a/core/jni/android_media_ToneGenerator.cpp b/core/jni/android_media_ToneGenerator.cpp
index 76e42bc..ca00709 100644
--- a/core/jni/android_media_ToneGenerator.cpp
+++ b/core/jni/android_media_ToneGenerator.cpp
@@ -39,9 +39,9 @@
 static fields_t fields;
 
 static jboolean android_media_ToneGenerator_startTone(JNIEnv *env, jobject thiz, jint toneType, jint durationMs) {
-    ALOGV("android_media_ToneGenerator_startTone: %x", (int)thiz);
+    ALOGV("android_media_ToneGenerator_startTone: %p", thiz);
 
-    ToneGenerator *lpToneGen = (ToneGenerator *)env->GetIntField(thiz,
+    ToneGenerator *lpToneGen = (ToneGenerator *)env->GetLongField(thiz,
             fields.context);
     if (lpToneGen == NULL) {
         jniThrowRuntimeException(env, "Method called after release()");
@@ -52,12 +52,12 @@
 }
 
 static void android_media_ToneGenerator_stopTone(JNIEnv *env, jobject thiz) {
-    ALOGV("android_media_ToneGenerator_stopTone: %x", (int)thiz);
+    ALOGV("android_media_ToneGenerator_stopTone: %p", thiz);
 
-    ToneGenerator *lpToneGen = (ToneGenerator *)env->GetIntField(thiz,
+    ToneGenerator *lpToneGen = (ToneGenerator *)env->GetLongField(thiz,
             fields.context);
 
-    ALOGV("ToneGenerator lpToneGen: %x", (unsigned int)lpToneGen);
+    ALOGV("ToneGenerator lpToneGen: %p", lpToneGen);
     if (lpToneGen == NULL) {
         jniThrowRuntimeException(env, "Method called after release()");
         return;
@@ -66,7 +66,7 @@
 }
 
 static jint android_media_ToneGenerator_getAudioSessionId(JNIEnv *env, jobject thiz) {
-    ToneGenerator *lpToneGen = (ToneGenerator *)env->GetIntField(thiz,
+    ToneGenerator *lpToneGen = (ToneGenerator *)env->GetLongField(thiz,
             fields.context);
     if (lpToneGen == NULL) {
         jniThrowRuntimeException(env, "Method called after release()");
@@ -76,11 +76,11 @@
 }
 
 static void android_media_ToneGenerator_release(JNIEnv *env, jobject thiz) {
-    ToneGenerator *lpToneGen = (ToneGenerator *)env->GetIntField(thiz,
+    ToneGenerator *lpToneGen = (ToneGenerator *)env->GetLongField(thiz,
             fields.context);
-    ALOGV("android_media_ToneGenerator_release lpToneGen: %x", (int)lpToneGen);
+    ALOGV("android_media_ToneGenerator_release lpToneGen: %p", lpToneGen);
 
-    env->SetIntField(thiz, fields.context, 0);
+    env->SetLongField(thiz, fields.context, 0);
 
     delete lpToneGen;
 }
@@ -89,11 +89,11 @@
         jint streamType, jint volume) {
     ToneGenerator *lpToneGen = new ToneGenerator((audio_stream_type_t) streamType, AudioSystem::linearToLog(volume), true);
 
-    env->SetIntField(thiz, fields.context, 0);
+    env->SetLongField(thiz, fields.context, 0);
 
-    ALOGV("android_media_ToneGenerator_native_setup jobject: %x", (int)thiz);
+    ALOGV("android_media_ToneGenerator_native_setup jobject: %p", thiz);
 
-    ALOGV("ToneGenerator lpToneGen: %x", (unsigned int)lpToneGen);
+    ALOGV("ToneGenerator lpToneGen: %p", lpToneGen);
 
     if (!lpToneGen->isInited()) {
         ALOGE("ToneGenerator init failed");
@@ -103,16 +103,16 @@
     }
 
     // Stow our new C++ ToneGenerator in an opaque field in the Java object.
-    env->SetIntField(thiz, fields.context, (int)lpToneGen);
+    env->SetLongField(thiz, fields.context, (jlong)lpToneGen);
 
-    ALOGV("ToneGenerator fields.context: %x", env->GetIntField(thiz, fields.context));
+    ALOGV("ToneGenerator fields.context: %p", (void*) env->GetLongField(thiz, fields.context));
 }
 
 static void android_media_ToneGenerator_native_finalize(JNIEnv *env,
         jobject thiz) {
-    ALOGV("android_media_ToneGenerator_native_finalize jobject: %x", (int)thiz);
+    ALOGV("android_media_ToneGenerator_native_finalize jobject: %p", thiz);
 
-    ToneGenerator *lpToneGen = (ToneGenerator *)env->GetIntField(thiz,
+    ToneGenerator *lpToneGen = (ToneGenerator *)env->GetLongField(thiz,
             fields.context);
 
     if (lpToneGen != NULL) {
@@ -142,12 +142,12 @@
         return -1;
     }
 
-    fields.context = env->GetFieldID(clazz, "mNativeContext", "I");
+    fields.context = env->GetFieldID(clazz, "mNativeContext", "J");
     if (fields.context == NULL) {
         ALOGE("Can't find ToneGenerator.mNativeContext");
         return -1;
     }
-    ALOGV("register_android_media_ToneGenerator ToneGenerator fields.context: %x", (unsigned int)fields.context);
+    ALOGV("register_android_media_ToneGenerator ToneGenerator fields.context: %p", fields.context);
 
     return AndroidRuntime::registerNativeMethods(env,
             "android/media/ToneGenerator", gMethods, NELEM(gMethods));