From 6638137dcb941ad2ae51cf9bd36c6407075dc0d5 Mon Sep 17 00:00:00 2001 From: Erwan Croze Date: Sun, 15 Apr 2018 17:31:26 +0200 Subject: [PATCH] Fixing android test --- tester/liblinphone_tester.c | 12 ++++++++++++ tester/tester.c | 6 +++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/tester/liblinphone_tester.c b/tester/liblinphone_tester.c index 2557f8de0..d4f030bb8 100644 --- a/tester/liblinphone_tester.c +++ b/tester/liblinphone_tester.c @@ -31,6 +31,7 @@ static FILE * log_file = NULL; static JNIEnv *current_env = NULL; static jobject current_obj = 0; +jobject system_context = 0; // Application context static const char* LogDomain = "liblinphone_tester"; int main(int argc, char** argv); @@ -98,6 +99,17 @@ void bcunit_android_trace_handler(int level, const char *fmt, va_list args) { (*env)->DeleteLocalRef(env,cls); } +JNIEXPORT void JNICALL Java_org_linphone_tester_Tester_setApplicationContext(JNIEnv *env, jclass obj, jobject context) { + system_context = (jobject)(*env)->NewGlobalRef(env, context); +} + +JNIEXPORT void JNICALL Java_org_linphone_tester_Tester_removeApplicationContext(JNIEnv *env, jclass obj) { + if (system_context) { + (*env)->DeleteGlobalRef(env, system_context); + system_context = 0; + } +} + JNIEXPORT jint JNICALL Java_org_linphone_tester_Tester_run(JNIEnv *env, jobject obj, jobjectArray stringArray) { int i, ret; int argc = (*env)->GetArrayLength(env, stringArray); diff --git a/tester/tester.c b/tester/tester.c index 067ea1905..8d4e1b87d 100644 --- a/tester/tester.c +++ b/tester/tester.c @@ -29,7 +29,7 @@ #define unlink _unlink #endif - +extern jobject system_context; static int liblinphone_tester_keep_accounts_flag = 0; static bool_t liblinphone_tester_keep_record_files = FALSE; static bool_t liblinphone_tester_leak_detector_disabled = FALSE; @@ -143,9 +143,9 @@ LinphoneCore *configure_lc_from(LinphoneCoreCbs *cbs, const char *path, const ch lp_config_set_string(config, "sound", "remote_ring", ringbackpath); lp_config_set_string(config, "sound", "local_ring" , ringpath); lp_config_set_string(config, "sip", "root_ca" , rootcapath); - lc = linphone_factory_create_core_with_config_3(linphone_factory_get(), config, NULL); + lc = linphone_factory_create_core_with_config_3(linphone_factory_get(), config, system_context); } else { - lc = linphone_factory_create_core_3(linphone_factory_get(), NULL, (filepath && (filepath[0] != '\0')) ? filepath : NULL, NULL); + lc = linphone_factory_create_core_3(linphone_factory_get(), NULL, (filepath && (filepath[0] != '\0')) ? filepath : NULL, system_context); linphone_core_set_ring(lc, ringpath); linphone_core_set_ringback(lc, ringbackpath); linphone_core_set_root_ca(lc,rootcapath);