(Android) Simplify intent grabbing with JNI

This commit is contained in:
twinaphex 2013-11-24 16:43:57 +01:00
parent 2501f69178
commit 47c8c26511
2 changed files with 36 additions and 62 deletions

View File

@ -19,22 +19,6 @@
#include <jni.h>
struct jni_params
{
char class_name[128];
char method_name[128];
char method_signature[128];
char submethod_name[128];
char submethod_signature[128];
};
struct jni_out_params_char
{
char *out;
size_t out_sizeof;
char in[128];
};
#define JNI_EXCEPTION(env) \
if ((*env)->ExceptionOccurred(env)) \
{ \

View File

@ -375,12 +375,10 @@ static bool android_run_events (void *data)
return true;
}
static void jni_get_intent_variable(void *data, void *data_in, void *data_out)
static void get_environment_settings(int argc, char *argv[], void *data)
{
JNIEnv *env;
struct android_app* android_app = (struct android_app*)data;
struct jni_params *in_params = (struct jni_params*)data_in;
struct jni_out_params_char *out_args = (struct jni_out_params_char*)data_out;
jclass class = NULL;
jobject obj = NULL;
jmethodID giid = NULL;
@ -394,71 +392,63 @@ static void jni_get_intent_variable(void *data, void *data_in, void *data_out)
return;
GET_OBJECT_CLASS(env, class, android_app->activity->clazz);
GET_METHOD_ID(env, giid, class, in_params->method_name, in_params->method_signature);
GET_METHOD_ID(env, giid, class, "getIntent", "()Landroid/content/Intent;");
CALL_OBJ_METHOD(env, obj, android_app->activity->clazz, giid);
if (in_params->submethod_name &&
in_params->submethod_signature)
{
GET_OBJECT_CLASS(env, class, obj);
GET_METHOD_ID(env, giid, class, in_params->submethod_name, in_params->submethod_signature);
GET_OBJECT_CLASS(env, class, obj);
GET_METHOD_ID(env, giid, class, "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
CALL_OBJ_METHOD_PARAM(env, jstr, obj, giid, (*env)->NewStringUTF(env, out_args->in));
}
// ROM
CALL_OBJ_METHOD_PARAM(env, jstr, obj, giid, (*env)->NewStringUTF(env, "ROM"));
if (giid && jstr)
{
const char *argv = (*env)->GetStringUTFChars(env, jstr, 0);
strlcpy(out_args->out, argv, out_args->out_sizeof);
strlcpy(g_extern.fullpath, argv, sizeof(g_extern.fullpath));
(*env)->ReleaseStringUTFChars(env, jstr, argv);
}
}
static void get_environment_settings(int argc, char *argv[], void *data)
{
struct android_app* android_app = (struct android_app*)data;
struct jni_params in_params;
struct jni_out_params_char out_args;
strlcpy(in_params.method_name, "getIntent", sizeof(in_params.method_name));
strlcpy(in_params.method_signature, "()Landroid/content/Intent;", sizeof(in_params.method_signature));
strlcpy(in_params.submethod_name, "getStringExtra", sizeof(in_params.submethod_name));
strlcpy(in_params.submethod_signature, "(Ljava/lang/String;)Ljava/lang/String;", sizeof(in_params.submethod_signature));
// ROM
out_args.out = g_extern.fullpath;
out_args.out_sizeof = sizeof(g_extern.fullpath);
strlcpy(out_args.in, "ROM", sizeof(out_args.in));
jni_get_intent_variable(android_app, &in_params, &out_args);
// Config file
out_args.out = g_extern.config_path;
out_args.out_sizeof = sizeof(g_extern.config_path);
strlcpy(out_args.in, "CONFIGFILE", sizeof(out_args.in));
jni_get_intent_variable(android_app, &in_params, &out_args);
CALL_OBJ_METHOD_PARAM(env, jstr, obj, giid, (*env)->NewStringUTF(env, "CONFIGFILE"));
if (giid && jstr)
{
const char *argv = (*env)->GetStringUTFChars(env, jstr, 0);
strlcpy(g_extern.config_path, argv, sizeof(g_extern.config_path));
(*env)->ReleaseStringUTFChars(env, jstr, argv);
}
// Current IME
out_args.out = android_app->current_ime;
out_args.out_sizeof = sizeof(android_app->current_ime);
strlcpy(out_args.in, "IME", sizeof(out_args.in));
jni_get_intent_variable(android_app, &in_params, &out_args);
CALL_OBJ_METHOD_PARAM(env, jstr, obj, giid, (*env)->NewStringUTF(env, "IME"));
RARCH_LOG("Checking arguments passed ...\n");
if (giid && jstr)
{
const char *argv = (*env)->GetStringUTFChars(env, jstr, 0);
strlcpy(android_app->current_ime, argv, sizeof(android_app->current_ime));
(*env)->ReleaseStringUTFChars(env, jstr, argv);
}
RARCH_LOG("Checking arguments passed from intent...\n");
RARCH_LOG("ROM Filename: [%s].\n", g_extern.fullpath);
RARCH_LOG("Config file: [%s].\n", g_extern.config_path);
RARCH_LOG("Current IME: [%s].\n", android_app->current_ime);
g_extern.block_config_read = false;
config_load();
g_extern.block_config_read = true;
// libretro
out_args.out = g_settings.libretro;
out_args.out_sizeof = sizeof(g_settings.libretro);
strlcpy(out_args.in, "LIBRETRO", sizeof(out_args.in));
jni_get_intent_variable(android_app, &in_params, &out_args);
//LIBRETRO
CALL_OBJ_METHOD_PARAM(env, jstr, obj, giid, (*env)->NewStringUTF(env, "LIBRETRO"));
if (giid && jstr)
{
const char *argv = (*env)->GetStringUTFChars(env, jstr, 0);
strlcpy(g_settings.libretro, argv, sizeof(g_settings.libretro));
(*env)->ReleaseStringUTFChars(env, jstr, argv);
}
RARCH_LOG("Checking arguments passed ...\n");
RARCH_LOG("Libretro path: [%s].\n", g_settings.libretro);
}
static int process_events(void *data)