Android: use the same naming for JNI env local variables

This commit is contained in:
Sylvain Becker 2019-01-11 15:36:16 +01:00
parent 3cfd907df7
commit dc10d96cde
1 changed files with 141 additions and 141 deletions

View File

@ -68,7 +68,7 @@
/* Java class SDLActivity */ /* Java class SDLActivity */
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeSetupJNI)( JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeSetupJNI)(
JNIEnv *mEnv, jclass cls); JNIEnv *env, jclass cls);
JNIEXPORT int JNICALL SDL_JAVA_INTERFACE(nativeRunMain)( JNIEXPORT int JNICALL SDL_JAVA_INTERFACE(nativeRunMain)(
JNIEnv *env, jclass cls, JNIEnv *env, jclass cls,
@ -350,7 +350,7 @@ void checkJNIReady()
} }
/* Activity initialization -- called before SDL_main() to initialize JNI bindings */ /* Activity initialization -- called before SDL_main() to initialize JNI bindings */
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeSetupJNI)(JNIEnv *mEnv, jclass cls) JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeSetupJNI)(JNIEnv *env, jclass cls)
{ {
__android_log_print(ANDROID_LOG_VERBOSE, "SDL", "nativeSetupJNI()"); __android_log_print(ANDROID_LOG_VERBOSE, "SDL", "nativeSetupJNI()");
@ -367,57 +367,57 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeSetupJNI)(JNIEnv *mEnv, jclass c
Android_JNI_SetupThread(); Android_JNI_SetupThread();
mActivityClass = (jclass)((*mEnv)->NewGlobalRef(mEnv, cls)); mActivityClass = (jclass)((*env)->NewGlobalRef(env, cls));
midGetNativeSurface = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass, midGetNativeSurface = (*env)->GetStaticMethodID(env, mActivityClass,
"getNativeSurface","()Landroid/view/Surface;"); "getNativeSurface","()Landroid/view/Surface;");
midSetSurfaceViewFormat = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass, midSetSurfaceViewFormat = (*env)->GetStaticMethodID(env, mActivityClass,
"setSurfaceViewFormat","(I)V"); "setSurfaceViewFormat","(I)V");
midSetActivityTitle = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass, midSetActivityTitle = (*env)->GetStaticMethodID(env, mActivityClass,
"setActivityTitle","(Ljava/lang/String;)Z"); "setActivityTitle","(Ljava/lang/String;)Z");
midSetWindowStyle = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass, midSetWindowStyle = (*env)->GetStaticMethodID(env, mActivityClass,
"setWindowStyle","(Z)V"); "setWindowStyle","(Z)V");
midSetOrientation = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass, midSetOrientation = (*env)->GetStaticMethodID(env, mActivityClass,
"setOrientation","(IIZLjava/lang/String;)V"); "setOrientation","(IIZLjava/lang/String;)V");
midGetContext = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass, midGetContext = (*env)->GetStaticMethodID(env, mActivityClass,
"getContext","()Landroid/content/Context;"); "getContext","()Landroid/content/Context;");
midIsTablet = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass, midIsTablet = (*env)->GetStaticMethodID(env, mActivityClass,
"isTablet", "()Z"); "isTablet", "()Z");
midIsAndroidTV = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass, midIsAndroidTV = (*env)->GetStaticMethodID(env, mActivityClass,
"isAndroidTV","()Z"); "isAndroidTV","()Z");
midIsChromebook = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass, midIsChromebook = (*env)->GetStaticMethodID(env, mActivityClass,
"isChromebook", "()Z"); "isChromebook", "()Z");
midIsDeXMode = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass, midIsDeXMode = (*env)->GetStaticMethodID(env, mActivityClass,
"isDeXMode", "()Z"); "isDeXMode", "()Z");
midManualBackButton = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass, midManualBackButton = (*env)->GetStaticMethodID(env, mActivityClass,
"manualBackButton", "()V"); "manualBackButton", "()V");
midInitTouch = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass, midInitTouch = (*env)->GetStaticMethodID(env, mActivityClass,
"initTouch", "()V"); "initTouch", "()V");
midSendMessage = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass, midSendMessage = (*env)->GetStaticMethodID(env, mActivityClass,
"sendMessage", "(II)Z"); "sendMessage", "(II)Z");
midShowTextInput = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass, midShowTextInput = (*env)->GetStaticMethodID(env, mActivityClass,
"showTextInput", "(IIII)Z"); "showTextInput", "(IIII)Z");
midIsScreenKeyboardShown = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass, midIsScreenKeyboardShown = (*env)->GetStaticMethodID(env, mActivityClass,
"isScreenKeyboardShown","()Z"); "isScreenKeyboardShown","()Z");
midClipboardSetText = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass, midClipboardSetText = (*env)->GetStaticMethodID(env, mActivityClass,
"clipboardSetText", "(Ljava/lang/String;)V"); "clipboardSetText", "(Ljava/lang/String;)V");
midClipboardGetText = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass, midClipboardGetText = (*env)->GetStaticMethodID(env, mActivityClass,
"clipboardGetText", "()Ljava/lang/String;"); "clipboardGetText", "()Ljava/lang/String;");
midClipboardHasText = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass, midClipboardHasText = (*env)->GetStaticMethodID(env, mActivityClass,
"clipboardHasText", "()Z"); "clipboardHasText", "()Z");
midOpenAPKExpansionInputStream = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass, midOpenAPKExpansionInputStream = (*env)->GetStaticMethodID(env, mActivityClass,
"openAPKExpansionInputStream", "(Ljava/lang/String;)Ljava/io/InputStream;"); "openAPKExpansionInputStream", "(Ljava/lang/String;)Ljava/io/InputStream;");
midGetManifestEnvironmentVariables = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass, midGetManifestEnvironmentVariables = (*env)->GetStaticMethodID(env, mActivityClass,
"getManifestEnvironmentVariables", "()Z"); "getManifestEnvironmentVariables", "()Z");
midGetDisplayDPI = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass, "getDisplayDPI", "()Landroid/util/DisplayMetrics;"); midGetDisplayDPI = (*env)->GetStaticMethodID(env, mActivityClass, "getDisplayDPI", "()Landroid/util/DisplayMetrics;");
midCreateCustomCursor = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass, "createCustomCursor", "([IIIII)I"); midCreateCustomCursor = (*env)->GetStaticMethodID(env, mActivityClass, "createCustomCursor", "([IIIII)I");
midSetCustomCursor = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass, "setCustomCursor", "(I)Z"); midSetCustomCursor = (*env)->GetStaticMethodID(env, mActivityClass, "setCustomCursor", "(I)Z");
midSetSystemCursor = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass, "setSystemCursor", "(I)Z"); midSetSystemCursor = (*env)->GetStaticMethodID(env, mActivityClass, "setSystemCursor", "(I)Z");
midSupportsRelativeMouse = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass, "supportsRelativeMouse", "()Z"); midSupportsRelativeMouse = (*env)->GetStaticMethodID(env, mActivityClass, "supportsRelativeMouse", "()Z");
midSetRelativeMouseEnabled = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass, "setRelativeMouseEnabled", "(Z)Z"); midSetRelativeMouseEnabled = (*env)->GetStaticMethodID(env, mActivityClass, "setRelativeMouseEnabled", "(Z)Z");
if (!midGetNativeSurface || !midSetSurfaceViewFormat || if (!midGetNativeSurface || !midSetSurfaceViewFormat ||
@ -430,7 +430,7 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeSetupJNI)(JNIEnv *mEnv, jclass c
__android_log_print(ANDROID_LOG_WARN, "SDL", "Missing some Java callbacks, do you have the latest version of SDLActivity.java?"); __android_log_print(ANDROID_LOG_WARN, "SDL", "Missing some Java callbacks, do you have the latest version of SDLActivity.java?");
} }
fidSeparateMouseAndTouch = (*mEnv)->GetStaticFieldID(mEnv, mActivityClass, "mSeparateMouseAndTouch", "Z"); fidSeparateMouseAndTouch = (*env)->GetStaticFieldID(env, mActivityClass, "mSeparateMouseAndTouch", "Z");
if (!fidSeparateMouseAndTouch) { if (!fidSeparateMouseAndTouch) {
__android_log_print(ANDROID_LOG_WARN, "SDL", "Missing some Java static fields, do you have the latest version of SDLActivity.java?"); __android_log_print(ANDROID_LOG_WARN, "SDL", "Missing some Java static fields, do you have the latest version of SDLActivity.java?");
@ -440,35 +440,35 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeSetupJNI)(JNIEnv *mEnv, jclass c
} }
/* Audio initialization -- called before SDL_main() to initialize JNI bindings */ /* Audio initialization -- called before SDL_main() to initialize JNI bindings */
JNIEXPORT void JNICALL SDL_JAVA_AUDIO_INTERFACE(nativeSetupJNI)(JNIEnv *mEnv, jclass cls) JNIEXPORT void JNICALL SDL_JAVA_AUDIO_INTERFACE(nativeSetupJNI)(JNIEnv *env, jclass cls)
{ {
__android_log_print(ANDROID_LOG_VERBOSE, "SDL", "AUDIO nativeSetupJNI()"); __android_log_print(ANDROID_LOG_VERBOSE, "SDL", "AUDIO nativeSetupJNI()");
Android_JNI_SetupThread(); Android_JNI_SetupThread();
mAudioManagerClass = (jclass)((*mEnv)->NewGlobalRef(mEnv, cls)); mAudioManagerClass = (jclass)((*env)->NewGlobalRef(env, cls));
midAudioOpen = (*mEnv)->GetStaticMethodID(mEnv, mAudioManagerClass, midAudioOpen = (*env)->GetStaticMethodID(env, mAudioManagerClass,
"audioOpen", "(IIII)[I"); "audioOpen", "(IIII)[I");
midAudioWriteByteBuffer = (*mEnv)->GetStaticMethodID(mEnv, mAudioManagerClass, midAudioWriteByteBuffer = (*env)->GetStaticMethodID(env, mAudioManagerClass,
"audioWriteByteBuffer", "([B)V"); "audioWriteByteBuffer", "([B)V");
midAudioWriteShortBuffer = (*mEnv)->GetStaticMethodID(mEnv, mAudioManagerClass, midAudioWriteShortBuffer = (*env)->GetStaticMethodID(env, mAudioManagerClass,
"audioWriteShortBuffer", "([S)V"); "audioWriteShortBuffer", "([S)V");
midAudioWriteFloatBuffer = (*mEnv)->GetStaticMethodID(mEnv, mAudioManagerClass, midAudioWriteFloatBuffer = (*env)->GetStaticMethodID(env, mAudioManagerClass,
"audioWriteFloatBuffer", "([F)V"); "audioWriteFloatBuffer", "([F)V");
midAudioClose = (*mEnv)->GetStaticMethodID(mEnv, mAudioManagerClass, midAudioClose = (*env)->GetStaticMethodID(env, mAudioManagerClass,
"audioClose", "()V"); "audioClose", "()V");
midCaptureOpen = (*mEnv)->GetStaticMethodID(mEnv, mAudioManagerClass, midCaptureOpen = (*env)->GetStaticMethodID(env, mAudioManagerClass,
"captureOpen", "(IIII)[I"); "captureOpen", "(IIII)[I");
midCaptureReadByteBuffer = (*mEnv)->GetStaticMethodID(mEnv, mAudioManagerClass, midCaptureReadByteBuffer = (*env)->GetStaticMethodID(env, mAudioManagerClass,
"captureReadByteBuffer", "([BZ)I"); "captureReadByteBuffer", "([BZ)I");
midCaptureReadShortBuffer = (*mEnv)->GetStaticMethodID(mEnv, mAudioManagerClass, midCaptureReadShortBuffer = (*env)->GetStaticMethodID(env, mAudioManagerClass,
"captureReadShortBuffer", "([SZ)I"); "captureReadShortBuffer", "([SZ)I");
midCaptureReadFloatBuffer = (*mEnv)->GetStaticMethodID(mEnv, mAudioManagerClass, midCaptureReadFloatBuffer = (*env)->GetStaticMethodID(env, mAudioManagerClass,
"captureReadFloatBuffer", "([FZ)I"); "captureReadFloatBuffer", "([FZ)I");
midCaptureClose = (*mEnv)->GetStaticMethodID(mEnv, mAudioManagerClass, midCaptureClose = (*env)->GetStaticMethodID(env, mAudioManagerClass,
"captureClose", "()V"); "captureClose", "()V");
midAudioSetThreadPriority = (*mEnv)->GetStaticMethodID(mEnv, mAudioManagerClass, midAudioSetThreadPriority = (*env)->GetStaticMethodID(env, mAudioManagerClass,
"audioSetThreadPriority", "(ZI)V"); "audioSetThreadPriority", "(ZI)V");
if (!midAudioOpen || !midAudioWriteByteBuffer || !midAudioWriteShortBuffer || !midAudioWriteFloatBuffer || !midAudioClose || if (!midAudioOpen || !midAudioWriteByteBuffer || !midAudioWriteShortBuffer || !midAudioWriteFloatBuffer || !midAudioClose ||
@ -480,21 +480,21 @@ JNIEXPORT void JNICALL SDL_JAVA_AUDIO_INTERFACE(nativeSetupJNI)(JNIEnv *mEnv, jc
} }
/* Controller initialization -- called before SDL_main() to initialize JNI bindings */ /* Controller initialization -- called before SDL_main() to initialize JNI bindings */
JNIEXPORT void JNICALL SDL_JAVA_CONTROLLER_INTERFACE(nativeSetupJNI)(JNIEnv *mEnv, jclass cls) JNIEXPORT void JNICALL SDL_JAVA_CONTROLLER_INTERFACE(nativeSetupJNI)(JNIEnv *env, jclass cls)
{ {
__android_log_print(ANDROID_LOG_VERBOSE, "SDL", "CONTROLLER nativeSetupJNI()"); __android_log_print(ANDROID_LOG_VERBOSE, "SDL", "CONTROLLER nativeSetupJNI()");
Android_JNI_SetupThread(); Android_JNI_SetupThread();
mControllerManagerClass = (jclass)((*mEnv)->NewGlobalRef(mEnv, cls)); mControllerManagerClass = (jclass)((*env)->NewGlobalRef(env, cls));
midPollInputDevices = (*mEnv)->GetStaticMethodID(mEnv, mControllerManagerClass, midPollInputDevices = (*env)->GetStaticMethodID(env, mControllerManagerClass,
"pollInputDevices", "()V"); "pollInputDevices", "()V");
midPollHapticDevices = (*mEnv)->GetStaticMethodID(mEnv, mControllerManagerClass, midPollHapticDevices = (*env)->GetStaticMethodID(env, mControllerManagerClass,
"pollHapticDevices", "()V"); "pollHapticDevices", "()V");
midHapticRun = (*mEnv)->GetStaticMethodID(mEnv, mControllerManagerClass, midHapticRun = (*env)->GetStaticMethodID(env, mControllerManagerClass,
"hapticRun", "(IFI)V"); "hapticRun", "(IFI)V");
midHapticStop = (*mEnv)->GetStaticMethodID(mEnv, mControllerManagerClass, midHapticStop = (*env)->GetStaticMethodID(env, mControllerManagerClass,
"hapticStop", "(I)V"); "hapticStop", "(I)V");
if (!midPollInputDevices || !midPollHapticDevices || !midHapticRun || !midHapticStop) { if (!midPollInputDevices || !midPollHapticDevices || !midHapticRun || !midHapticStop) {
@ -1087,7 +1087,7 @@ ANativeWindow* Android_JNI_GetNativeWindow(void)
void Android_JNI_SetSurfaceViewFormat(int format) void Android_JNI_SetSurfaceViewFormat(int format)
{ {
JNIEnv *mEnv = Android_JNI_GetEnv(); JNIEnv *env = Android_JNI_GetEnv();
int new_format = 0; int new_format = 0;
/* Format from android/native_window.h, /* Format from android/native_window.h,
@ -1102,31 +1102,31 @@ void Android_JNI_SetSurfaceViewFormat(int format)
new_format = 0; new_format = 0;
} }
(*mEnv)->CallStaticVoidMethod(mEnv, mActivityClass, midSetSurfaceViewFormat, new_format); (*env)->CallStaticVoidMethod(env, mActivityClass, midSetSurfaceViewFormat, new_format);
} }
void Android_JNI_SetActivityTitle(const char *title) void Android_JNI_SetActivityTitle(const char *title)
{ {
JNIEnv *mEnv = Android_JNI_GetEnv(); JNIEnv *env = Android_JNI_GetEnv();
jstring jtitle = (jstring)((*mEnv)->NewStringUTF(mEnv, title)); jstring jtitle = (jstring)((*env)->NewStringUTF(env, title));
(*mEnv)->CallStaticBooleanMethod(mEnv, mActivityClass, midSetActivityTitle, jtitle); (*env)->CallStaticBooleanMethod(env, mActivityClass, midSetActivityTitle, jtitle);
(*mEnv)->DeleteLocalRef(mEnv, jtitle); (*env)->DeleteLocalRef(env, jtitle);
} }
void Android_JNI_SetWindowStyle(SDL_bool fullscreen) void Android_JNI_SetWindowStyle(SDL_bool fullscreen)
{ {
JNIEnv *mEnv = Android_JNI_GetEnv(); JNIEnv *env = Android_JNI_GetEnv();
(*mEnv)->CallStaticVoidMethod(mEnv, mActivityClass, midSetWindowStyle, fullscreen ? 1 : 0); (*env)->CallStaticVoidMethod(env, mActivityClass, midSetWindowStyle, fullscreen ? 1 : 0);
} }
void Android_JNI_SetOrientation(int w, int h, int resizable, const char *hint) void Android_JNI_SetOrientation(int w, int h, int resizable, const char *hint)
{ {
JNIEnv *mEnv = Android_JNI_GetEnv(); JNIEnv *env = Android_JNI_GetEnv();
jstring jhint = (jstring)((*mEnv)->NewStringUTF(mEnv, (hint ? hint : ""))); jstring jhint = (jstring)((*env)->NewStringUTF(env, (hint ? hint : "")));
(*mEnv)->CallStaticVoidMethod(mEnv, mActivityClass, midSetOrientation, w, h, (resizable? 1 : 0), jhint); (*env)->CallStaticVoidMethod(env, mActivityClass, midSetOrientation, w, h, (resizable? 1 : 0), jhint);
(*mEnv)->DeleteLocalRef(mEnv, jhint); (*env)->DeleteLocalRef(env, jhint);
} }
SDL_bool Android_JNI_GetAccelerometerValues(float values[3]) SDL_bool Android_JNI_GetAccelerometerValues(float values[3])
@ -1522,42 +1522,42 @@ void Android_JNI_AudioSetThreadPriority(int iscapture, int device_id)
/* If the parameter silent is truthy then SDL_SetError() will not be called. */ /* If the parameter silent is truthy then SDL_SetError() will not be called. */
static SDL_bool Android_JNI_ExceptionOccurred(SDL_bool silent) static SDL_bool Android_JNI_ExceptionOccurred(SDL_bool silent)
{ {
JNIEnv *mEnv = Android_JNI_GetEnv(); JNIEnv *env = Android_JNI_GetEnv();
jthrowable exception; jthrowable exception;
/* Detect mismatch LocalReferenceHolder_Init/Cleanup */ /* Detect mismatch LocalReferenceHolder_Init/Cleanup */
SDL_assert((s_active > 0)); SDL_assert((s_active > 0));
exception = (*mEnv)->ExceptionOccurred(mEnv); exception = (*env)->ExceptionOccurred(env);
if (exception != NULL) { if (exception != NULL) {
jmethodID mid; jmethodID mid;
/* Until this happens most JNI operations have undefined behaviour */ /* Until this happens most JNI operations have undefined behaviour */
(*mEnv)->ExceptionClear(mEnv); (*env)->ExceptionClear(env);
if (!silent) { if (!silent) {
jclass exceptionClass = (*mEnv)->GetObjectClass(mEnv, exception); jclass exceptionClass = (*env)->GetObjectClass(env, exception);
jclass classClass = (*mEnv)->FindClass(mEnv, "java/lang/Class"); jclass classClass = (*env)->FindClass(env, "java/lang/Class");
jstring exceptionName; jstring exceptionName;
const char *exceptionNameUTF8; const char *exceptionNameUTF8;
jstring exceptionMessage; jstring exceptionMessage;
mid = (*mEnv)->GetMethodID(mEnv, classClass, "getName", "()Ljava/lang/String;"); mid = (*env)->GetMethodID(env, classClass, "getName", "()Ljava/lang/String;");
exceptionName = (jstring)(*mEnv)->CallObjectMethod(mEnv, exceptionClass, mid); exceptionName = (jstring)(*env)->CallObjectMethod(env, exceptionClass, mid);
exceptionNameUTF8 = (*mEnv)->GetStringUTFChars(mEnv, exceptionName, 0); exceptionNameUTF8 = (*env)->GetStringUTFChars(env, exceptionName, 0);
mid = (*mEnv)->GetMethodID(mEnv, exceptionClass, "getMessage", "()Ljava/lang/String;"); mid = (*env)->GetMethodID(env, exceptionClass, "getMessage", "()Ljava/lang/String;");
exceptionMessage = (jstring)(*mEnv)->CallObjectMethod(mEnv, exception, mid); exceptionMessage = (jstring)(*env)->CallObjectMethod(env, exception, mid);
if (exceptionMessage != NULL) { if (exceptionMessage != NULL) {
const char *exceptionMessageUTF8 = (*mEnv)->GetStringUTFChars(mEnv, exceptionMessage, 0); const char *exceptionMessageUTF8 = (*env)->GetStringUTFChars(env, exceptionMessage, 0);
SDL_SetError("%s: %s", exceptionNameUTF8, exceptionMessageUTF8); SDL_SetError("%s: %s", exceptionNameUTF8, exceptionMessageUTF8);
(*mEnv)->ReleaseStringUTFChars(mEnv, exceptionMessage, exceptionMessageUTF8); (*env)->ReleaseStringUTFChars(env, exceptionMessage, exceptionMessageUTF8);
} else { } else {
SDL_SetError("%s", exceptionNameUTF8); SDL_SetError("%s", exceptionNameUTF8);
} }
(*mEnv)->ReleaseStringUTFChars(mEnv, exceptionName, exceptionNameUTF8); (*env)->ReleaseStringUTFChars(env, exceptionName, exceptionNameUTF8);
} }
return SDL_TRUE; return SDL_TRUE;
@ -1583,8 +1583,8 @@ static int Internal_Android_JNI_FileOpen(SDL_RWops *ctx)
jclass fdCls; jclass fdCls;
jfieldID descriptor; jfieldID descriptor;
JNIEnv *mEnv = Android_JNI_GetEnv(); JNIEnv *env = Android_JNI_GetEnv();
if (!LocalReferenceHolder_Init(&refs, mEnv)) { if (!LocalReferenceHolder_Init(&refs, env)) {
goto failure; goto failure;
} }
@ -1592,40 +1592,40 @@ static int Internal_Android_JNI_FileOpen(SDL_RWops *ctx)
ctx->hidden.androidio.position = 0; ctx->hidden.androidio.position = 0;
/* context = SDLActivity.getContext(); */ /* context = SDLActivity.getContext(); */
context = (*mEnv)->CallStaticObjectMethod(mEnv, mActivityClass, midGetContext); context = (*env)->CallStaticObjectMethod(env, mActivityClass, midGetContext);
/* assetManager = context.getAssets(); */ /* assetManager = context.getAssets(); */
mid = (*mEnv)->GetMethodID(mEnv, (*mEnv)->GetObjectClass(mEnv, context), mid = (*env)->GetMethodID(env, (*env)->GetObjectClass(env, context),
"getAssets", "()Landroid/content/res/AssetManager;"); "getAssets", "()Landroid/content/res/AssetManager;");
assetManager = (*mEnv)->CallObjectMethod(mEnv, context, mid); assetManager = (*env)->CallObjectMethod(env, context, mid);
/* First let's try opening the file to obtain an AssetFileDescriptor. /* First let's try opening the file to obtain an AssetFileDescriptor.
* This method reads the files directly from the APKs using standard *nix calls * This method reads the files directly from the APKs using standard *nix calls
*/ */
mid = (*mEnv)->GetMethodID(mEnv, (*mEnv)->GetObjectClass(mEnv, assetManager), "openFd", "(Ljava/lang/String;)Landroid/content/res/AssetFileDescriptor;"); mid = (*env)->GetMethodID(env, (*env)->GetObjectClass(env, assetManager), "openFd", "(Ljava/lang/String;)Landroid/content/res/AssetFileDescriptor;");
inputStream = (*mEnv)->CallObjectMethod(mEnv, assetManager, mid, fileNameJString); inputStream = (*env)->CallObjectMethod(env, assetManager, mid, fileNameJString);
if (Android_JNI_ExceptionOccurred(SDL_TRUE)) { if (Android_JNI_ExceptionOccurred(SDL_TRUE)) {
goto fallback; goto fallback;
} }
mid = (*mEnv)->GetMethodID(mEnv, (*mEnv)->GetObjectClass(mEnv, inputStream), "getStartOffset", "()J"); mid = (*env)->GetMethodID(env, (*env)->GetObjectClass(env, inputStream), "getStartOffset", "()J");
ctx->hidden.androidio.offset = (long)(*mEnv)->CallLongMethod(mEnv, inputStream, mid); ctx->hidden.androidio.offset = (long)(*env)->CallLongMethod(env, inputStream, mid);
if (Android_JNI_ExceptionOccurred(SDL_TRUE)) { if (Android_JNI_ExceptionOccurred(SDL_TRUE)) {
goto fallback; goto fallback;
} }
mid = (*mEnv)->GetMethodID(mEnv, (*mEnv)->GetObjectClass(mEnv, inputStream), "getDeclaredLength", "()J"); mid = (*env)->GetMethodID(env, (*env)->GetObjectClass(env, inputStream), "getDeclaredLength", "()J");
ctx->hidden.androidio.size = (long)(*mEnv)->CallLongMethod(mEnv, inputStream, mid); ctx->hidden.androidio.size = (long)(*env)->CallLongMethod(env, inputStream, mid);
if (Android_JNI_ExceptionOccurred(SDL_TRUE)) { if (Android_JNI_ExceptionOccurred(SDL_TRUE)) {
goto fallback; goto fallback;
} }
mid = (*mEnv)->GetMethodID(mEnv, (*mEnv)->GetObjectClass(mEnv, inputStream), "getFileDescriptor", "()Ljava/io/FileDescriptor;"); mid = (*env)->GetMethodID(env, (*env)->GetObjectClass(env, inputStream), "getFileDescriptor", "()Ljava/io/FileDescriptor;");
fd = (*mEnv)->CallObjectMethod(mEnv, inputStream, mid); fd = (*env)->CallObjectMethod(env, inputStream, mid);
fdCls = (*mEnv)->GetObjectClass(mEnv, fd); fdCls = (*env)->GetObjectClass(env, fd);
descriptor = (*mEnv)->GetFieldID(mEnv, fdCls, "descriptor", "I"); descriptor = (*env)->GetFieldID(env, fdCls, "descriptor", "I");
ctx->hidden.androidio.fd = (*mEnv)->GetIntField(mEnv, fd, descriptor); ctx->hidden.androidio.fd = (*env)->GetIntField(env, fd, descriptor);
ctx->hidden.androidio.assetFileDescriptorRef = (*mEnv)->NewGlobalRef(mEnv, inputStream); ctx->hidden.androidio.assetFileDescriptorRef = (*env)->NewGlobalRef(env, inputStream);
/* Seek to the correct offset in the file. */ /* Seek to the correct offset in the file. */
lseek(ctx->hidden.androidio.fd, (off_t)ctx->hidden.androidio.offset, SEEK_SET); lseek(ctx->hidden.androidio.fd, (off_t)ctx->hidden.androidio.offset, SEEK_SET);
@ -1639,12 +1639,12 @@ fallback:
ctx->hidden.androidio.assetFileDescriptorRef = NULL; ctx->hidden.androidio.assetFileDescriptorRef = NULL;
/* inputStream = assetManager.open(<filename>); */ /* inputStream = assetManager.open(<filename>); */
mid = (*mEnv)->GetMethodID(mEnv, (*mEnv)->GetObjectClass(mEnv, assetManager), mid = (*env)->GetMethodID(env, (*env)->GetObjectClass(env, assetManager),
"open", "(Ljava/lang/String;I)Ljava/io/InputStream;"); "open", "(Ljava/lang/String;I)Ljava/io/InputStream;");
inputStream = (*mEnv)->CallObjectMethod(mEnv, assetManager, mid, fileNameJString, 1 /* ACCESS_RANDOM */); inputStream = (*env)->CallObjectMethod(env, assetManager, mid, fileNameJString, 1 /* ACCESS_RANDOM */);
if (Android_JNI_ExceptionOccurred(SDL_FALSE)) { if (Android_JNI_ExceptionOccurred(SDL_FALSE)) {
/* Try fallback to APK expansion files */ /* Try fallback to APK expansion files */
inputStream = (*mEnv)->CallStaticObjectMethod(mEnv, mActivityClass, midOpenAPKExpansionInputStream, fileNameJString); inputStream = (*env)->CallStaticObjectMethod(env, mActivityClass, midOpenAPKExpansionInputStream, fileNameJString);
/* Exception is checked first because it always needs to be cleared. /* Exception is checked first because it always needs to be cleared.
* If no exception occurred then the last SDL error message is kept. * If no exception occurred then the last SDL error message is kept.
@ -1654,7 +1654,7 @@ fallback:
} }
} }
ctx->hidden.androidio.inputStreamRef = (*mEnv)->NewGlobalRef(mEnv, inputStream); ctx->hidden.androidio.inputStreamRef = (*env)->NewGlobalRef(env, inputStream);
/* Despite all the visible documentation on [Asset]InputStream claiming /* Despite all the visible documentation on [Asset]InputStream claiming
* that the .available() method is not guaranteed to return the entire file * that the .available() method is not guaranteed to return the entire file
@ -1664,29 +1664,29 @@ fallback:
*/ */
/* size = inputStream.available(); */ /* size = inputStream.available(); */
mid = (*mEnv)->GetMethodID(mEnv, (*mEnv)->GetObjectClass(mEnv, inputStream), mid = (*env)->GetMethodID(env, (*env)->GetObjectClass(env, inputStream),
"available", "()I"); "available", "()I");
ctx->hidden.androidio.size = (long)(*mEnv)->CallIntMethod(mEnv, inputStream, mid); ctx->hidden.androidio.size = (long)(*env)->CallIntMethod(env, inputStream, mid);
if (Android_JNI_ExceptionOccurred(SDL_FALSE)) { if (Android_JNI_ExceptionOccurred(SDL_FALSE)) {
goto failure; goto failure;
} }
/* readableByteChannel = Channels.newChannel(inputStream); */ /* readableByteChannel = Channels.newChannel(inputStream); */
channels = (*mEnv)->FindClass(mEnv, "java/nio/channels/Channels"); channels = (*env)->FindClass(env, "java/nio/channels/Channels");
mid = (*mEnv)->GetStaticMethodID(mEnv, channels, mid = (*env)->GetStaticMethodID(env, channels,
"newChannel", "newChannel",
"(Ljava/io/InputStream;)Ljava/nio/channels/ReadableByteChannel;"); "(Ljava/io/InputStream;)Ljava/nio/channels/ReadableByteChannel;");
readableByteChannel = (*mEnv)->CallStaticObjectMethod( readableByteChannel = (*env)->CallStaticObjectMethod(
mEnv, channels, mid, inputStream); env, channels, mid, inputStream);
if (Android_JNI_ExceptionOccurred(SDL_FALSE)) { if (Android_JNI_ExceptionOccurred(SDL_FALSE)) {
goto failure; goto failure;
} }
ctx->hidden.androidio.readableByteChannelRef = ctx->hidden.androidio.readableByteChannelRef =
(*mEnv)->NewGlobalRef(mEnv, readableByteChannel); (*env)->NewGlobalRef(env, readableByteChannel);
/* Store .read id for reading purposes */ /* Store .read id for reading purposes */
mid = (*mEnv)->GetMethodID(mEnv, (*mEnv)->GetObjectClass(mEnv, readableByteChannel), mid = (*env)->GetMethodID(env, (*env)->GetObjectClass(env, readableByteChannel),
"read", "(Ljava/nio/ByteBuffer;)I"); "read", "(Ljava/nio/ByteBuffer;)I");
ctx->hidden.androidio.readMethod = mid; ctx->hidden.androidio.readMethod = mid;
} }
@ -1695,18 +1695,18 @@ fallback:
failure: failure:
result = -1; result = -1;
(*mEnv)->DeleteGlobalRef(mEnv, (jobject)ctx->hidden.androidio.fileNameRef); (*env)->DeleteGlobalRef(env, (jobject)ctx->hidden.androidio.fileNameRef);
if(ctx->hidden.androidio.inputStreamRef != NULL) { if(ctx->hidden.androidio.inputStreamRef != NULL) {
(*mEnv)->DeleteGlobalRef(mEnv, (jobject)ctx->hidden.androidio.inputStreamRef); (*env)->DeleteGlobalRef(env, (jobject)ctx->hidden.androidio.inputStreamRef);
} }
if(ctx->hidden.androidio.readableByteChannelRef != NULL) { if(ctx->hidden.androidio.readableByteChannelRef != NULL) {
(*mEnv)->DeleteGlobalRef(mEnv, (jobject)ctx->hidden.androidio.readableByteChannelRef); (*env)->DeleteGlobalRef(env, (jobject)ctx->hidden.androidio.readableByteChannelRef);
} }
if(ctx->hidden.androidio.assetFileDescriptorRef != NULL) { if(ctx->hidden.androidio.assetFileDescriptorRef != NULL) {
(*mEnv)->DeleteGlobalRef(mEnv, (jobject)ctx->hidden.androidio.assetFileDescriptorRef); (*env)->DeleteGlobalRef(env, (jobject)ctx->hidden.androidio.assetFileDescriptorRef);
} }
} }
@ -1719,11 +1719,11 @@ int Android_JNI_FileOpen(SDL_RWops *ctx,
const char *fileName, const char *mode) const char *fileName, const char *mode)
{ {
struct LocalReferenceHolder refs = LocalReferenceHolder_Setup(__FUNCTION__); struct LocalReferenceHolder refs = LocalReferenceHolder_Setup(__FUNCTION__);
JNIEnv *mEnv = Android_JNI_GetEnv(); JNIEnv *env = Android_JNI_GetEnv();
int retval; int retval;
jstring fileNameJString; jstring fileNameJString;
if (!LocalReferenceHolder_Init(&refs, mEnv)) { if (!LocalReferenceHolder_Init(&refs, env)) {
LocalReferenceHolder_Cleanup(&refs); LocalReferenceHolder_Cleanup(&refs);
return -1; return -1;
} }
@ -1733,8 +1733,8 @@ int Android_JNI_FileOpen(SDL_RWops *ctx,
return -1; return -1;
} }
fileNameJString = (*mEnv)->NewStringUTF(mEnv, fileName); fileNameJString = (*env)->NewStringUTF(env, fileName);
ctx->hidden.androidio.fileNameRef = (*mEnv)->NewGlobalRef(mEnv, fileNameJString); ctx->hidden.androidio.fileNameRef = (*env)->NewGlobalRef(env, fileNameJString);
ctx->hidden.androidio.inputStreamRef = NULL; ctx->hidden.androidio.inputStreamRef = NULL;
ctx->hidden.androidio.readableByteChannelRef = NULL; ctx->hidden.androidio.readableByteChannelRef = NULL;
ctx->hidden.androidio.readMethod = NULL; ctx->hidden.androidio.readMethod = NULL;
@ -1768,7 +1768,7 @@ size_t Android_JNI_FileRead(SDL_RWops *ctx, void *buffer,
jlong bytesRemaining = (jlong) (size * maxnum); jlong bytesRemaining = (jlong) (size * maxnum);
jlong bytesMax = (jlong) (ctx->hidden.androidio.size - ctx->hidden.androidio.position); jlong bytesMax = (jlong) (ctx->hidden.androidio.size - ctx->hidden.androidio.position);
int bytesRead = 0; int bytesRead = 0;
JNIEnv *mEnv; JNIEnv *env;
jobject readableByteChannel; jobject readableByteChannel;
jmethodID readMethod; jmethodID readMethod;
jobject byteBuffer; jobject byteBuffer;
@ -1776,19 +1776,19 @@ size_t Android_JNI_FileRead(SDL_RWops *ctx, void *buffer,
/* Don't read more bytes than those that remain in the file, otherwise we get an exception */ /* Don't read more bytes than those that remain in the file, otherwise we get an exception */
if (bytesRemaining > bytesMax) bytesRemaining = bytesMax; if (bytesRemaining > bytesMax) bytesRemaining = bytesMax;
mEnv = Android_JNI_GetEnv(); env = Android_JNI_GetEnv();
if (!LocalReferenceHolder_Init(&refs, mEnv)) { if (!LocalReferenceHolder_Init(&refs, env)) {
LocalReferenceHolder_Cleanup(&refs); LocalReferenceHolder_Cleanup(&refs);
return 0; return 0;
} }
readableByteChannel = (jobject)ctx->hidden.androidio.readableByteChannelRef; readableByteChannel = (jobject)ctx->hidden.androidio.readableByteChannelRef;
readMethod = (jmethodID)ctx->hidden.androidio.readMethod; readMethod = (jmethodID)ctx->hidden.androidio.readMethod;
byteBuffer = (*mEnv)->NewDirectByteBuffer(mEnv, buffer, bytesRemaining); byteBuffer = (*env)->NewDirectByteBuffer(env, buffer, bytesRemaining);
while (bytesRemaining > 0) { while (bytesRemaining > 0) {
/* result = readableByteChannel.read(...); */ /* result = readableByteChannel.read(...); */
int result = (*mEnv)->CallIntMethod(mEnv, readableByteChannel, readMethod, byteBuffer); int result = (*env)->CallIntMethod(env, readableByteChannel, readMethod, byteBuffer);
if (Android_JNI_ExceptionOccurred(SDL_FALSE)) { if (Android_JNI_ExceptionOccurred(SDL_FALSE)) {
LocalReferenceHolder_Cleanup(&refs); LocalReferenceHolder_Cleanup(&refs);
@ -1820,24 +1820,24 @@ static int Internal_Android_JNI_FileClose(SDL_RWops *ctx, SDL_bool release)
struct LocalReferenceHolder refs = LocalReferenceHolder_Setup(__FUNCTION__); struct LocalReferenceHolder refs = LocalReferenceHolder_Setup(__FUNCTION__);
int result = 0; int result = 0;
JNIEnv *mEnv = Android_JNI_GetEnv(); JNIEnv *env = Android_JNI_GetEnv();
if (!LocalReferenceHolder_Init(&refs, mEnv)) { if (!LocalReferenceHolder_Init(&refs, env)) {
LocalReferenceHolder_Cleanup(&refs); LocalReferenceHolder_Cleanup(&refs);
return SDL_SetError("Failed to allocate enough JVM local references"); return SDL_SetError("Failed to allocate enough JVM local references");
} }
if (ctx) { if (ctx) {
if (release) { if (release) {
(*mEnv)->DeleteGlobalRef(mEnv, (jobject)ctx->hidden.androidio.fileNameRef); (*env)->DeleteGlobalRef(env, (jobject)ctx->hidden.androidio.fileNameRef);
} }
if (ctx->hidden.androidio.assetFileDescriptorRef) { if (ctx->hidden.androidio.assetFileDescriptorRef) {
jobject inputStream = (jobject)ctx->hidden.androidio.assetFileDescriptorRef; jobject inputStream = (jobject)ctx->hidden.androidio.assetFileDescriptorRef;
jmethodID mid = (*mEnv)->GetMethodID(mEnv, (*mEnv)->GetObjectClass(mEnv, inputStream), jmethodID mid = (*env)->GetMethodID(env, (*env)->GetObjectClass(env, inputStream),
"close", "()V"); "close", "()V");
(*mEnv)->CallVoidMethod(mEnv, inputStream, mid); (*env)->CallVoidMethod(env, inputStream, mid);
(*mEnv)->DeleteGlobalRef(mEnv, (jobject)ctx->hidden.androidio.assetFileDescriptorRef); (*env)->DeleteGlobalRef(env, (jobject)ctx->hidden.androidio.assetFileDescriptorRef);
if (Android_JNI_ExceptionOccurred(SDL_FALSE)) { if (Android_JNI_ExceptionOccurred(SDL_FALSE)) {
result = -1; result = -1;
} }
@ -1846,11 +1846,11 @@ static int Internal_Android_JNI_FileClose(SDL_RWops *ctx, SDL_bool release)
jobject inputStream = (jobject)ctx->hidden.androidio.inputStreamRef; jobject inputStream = (jobject)ctx->hidden.androidio.inputStreamRef;
/* inputStream.close(); */ /* inputStream.close(); */
jmethodID mid = (*mEnv)->GetMethodID(mEnv, (*mEnv)->GetObjectClass(mEnv, inputStream), jmethodID mid = (*env)->GetMethodID(env, (*env)->GetObjectClass(env, inputStream),
"close", "()V"); "close", "()V");
(*mEnv)->CallVoidMethod(mEnv, inputStream, mid); (*env)->CallVoidMethod(env, inputStream, mid);
(*mEnv)->DeleteGlobalRef(mEnv, (jobject)ctx->hidden.androidio.inputStreamRef); (*env)->DeleteGlobalRef(env, (jobject)ctx->hidden.androidio.inputStreamRef);
(*mEnv)->DeleteGlobalRef(mEnv, (jobject)ctx->hidden.androidio.readableByteChannelRef); (*env)->DeleteGlobalRef(env, (jobject)ctx->hidden.androidio.readableByteChannelRef);
if (Android_JNI_ExceptionOccurred(SDL_FALSE)) { if (Android_JNI_ExceptionOccurred(SDL_FALSE)) {
result = -1; result = -1;
} }
@ -2189,9 +2189,9 @@ void Android_JNI_HideTextInput(void)
SDL_bool Android_JNI_IsScreenKeyboardShown() SDL_bool Android_JNI_IsScreenKeyboardShown()
{ {
JNIEnv *mEnv = Android_JNI_GetEnv(); JNIEnv *env = Android_JNI_GetEnv();
jboolean is_shown = 0; jboolean is_shown = 0;
is_shown = (*mEnv)->CallStaticBooleanMethod(mEnv, mActivityClass, midIsScreenKeyboardShown); is_shown = (*env)->CallStaticBooleanMethod(env, mActivityClass, midIsScreenKeyboardShown);
return is_shown; return is_shown;
} }
@ -2492,14 +2492,14 @@ void Android_JNI_GetManifestEnvironmentVariables(void)
int Android_JNI_CreateCustomCursor(SDL_Surface *surface, int hot_x, int hot_y) int Android_JNI_CreateCustomCursor(SDL_Surface *surface, int hot_x, int hot_y)
{ {
JNIEnv *mEnv = Android_JNI_GetEnv(); JNIEnv *env = Android_JNI_GetEnv();
int custom_cursor = 0; int custom_cursor = 0;
jintArray pixels; jintArray pixels;
pixels = (*mEnv)->NewIntArray(mEnv, surface->w * surface->h); pixels = (*env)->NewIntArray(env, surface->w * surface->h);
if (pixels) { if (pixels) {
(*mEnv)->SetIntArrayRegion(mEnv, pixels, 0, surface->w * surface->h, (int *)surface->pixels); (*env)->SetIntArrayRegion(env, pixels, 0, surface->w * surface->h, (int *)surface->pixels);
custom_cursor = (*mEnv)->CallStaticIntMethod(mEnv, mActivityClass, midCreateCustomCursor, pixels, surface->w, surface->h, hot_x, hot_y); custom_cursor = (*env)->CallStaticIntMethod(env, mActivityClass, midCreateCustomCursor, pixels, surface->w, surface->h, hot_x, hot_y);
(*mEnv)->DeleteLocalRef(mEnv, pixels); (*env)->DeleteLocalRef(env, pixels);
} else { } else {
SDL_OutOfMemory(); SDL_OutOfMemory();
} }
@ -2509,26 +2509,26 @@ int Android_JNI_CreateCustomCursor(SDL_Surface *surface, int hot_x, int hot_y)
SDL_bool Android_JNI_SetCustomCursor(int cursorID) SDL_bool Android_JNI_SetCustomCursor(int cursorID)
{ {
JNIEnv *mEnv = Android_JNI_GetEnv(); JNIEnv *env = Android_JNI_GetEnv();
return (*mEnv)->CallStaticBooleanMethod(mEnv, mActivityClass, midSetCustomCursor, cursorID); return (*env)->CallStaticBooleanMethod(env, mActivityClass, midSetCustomCursor, cursorID);
} }
SDL_bool Android_JNI_SetSystemCursor(int cursorID) SDL_bool Android_JNI_SetSystemCursor(int cursorID)
{ {
JNIEnv *mEnv = Android_JNI_GetEnv(); JNIEnv *env = Android_JNI_GetEnv();
return (*mEnv)->CallStaticBooleanMethod(mEnv, mActivityClass, midSetSystemCursor, cursorID); return (*env)->CallStaticBooleanMethod(env, mActivityClass, midSetSystemCursor, cursorID);
} }
SDL_bool Android_JNI_SupportsRelativeMouse() SDL_bool Android_JNI_SupportsRelativeMouse()
{ {
JNIEnv *mEnv = Android_JNI_GetEnv(); JNIEnv *env = Android_JNI_GetEnv();
return (*mEnv)->CallStaticBooleanMethod(mEnv, mActivityClass, midSupportsRelativeMouse); return (*env)->CallStaticBooleanMethod(env, mActivityClass, midSupportsRelativeMouse);
} }
SDL_bool Android_JNI_SetRelativeMouseEnabled(SDL_bool enabled) SDL_bool Android_JNI_SetRelativeMouseEnabled(SDL_bool enabled)
{ {
JNIEnv *mEnv = Android_JNI_GetEnv(); JNIEnv *env = Android_JNI_GetEnv();
return (*mEnv)->CallStaticBooleanMethod(mEnv, mActivityClass, midSetRelativeMouseEnabled, (enabled == 1)); return (*env)->CallStaticBooleanMethod(env, mActivityClass, midSetRelativeMouseEnabled, (enabled == 1));
} }