Commit 2aa71018 authored by Ghislain MARY's avatar Ghislain MARY

Handle build for Android with CMake.

parent 6d06e4e1
......@@ -174,6 +174,9 @@ if(MSVC)
endif()
add_definitions("-DHAVE_CONFIG_H")
if(ANDROID)
add_definitions("-DANDROID")
endif()
set(STRICT_OPTIONS_CPP )
set(STRICT_OPTIONS_C )
set(STRICT_OPTIONS_OBJC "-fmodules")
......
......@@ -27,8 +27,8 @@ list(APPEND INCLUDES ${BCTOOLBOX_CORE_INCLUDE_DIR})
list(APPEND LIBS ${BCTOOLBOX_CORE_LIBRARIES})
if(Threads_FOUND)
if(CMAKE_USE_PTHREADS_INIT AND NOT CMAKE_SYSTEM_NAME MATCHES "QNX")
list(APPEND LIBS pthread)
if(CMAKE_USE_PTHREADS_INIT AND NOT CMAKE_SYSTEM_NAME MATCHES "QNX" AND NOT ANDROID)
list(APPEND LIBS ${CMAKE_THREAD_LIBS_INIT})
endif()
endif()
if(HAVE_LIBDL)
......@@ -137,6 +137,9 @@ set(BELLE_SIP_SOURCE_FILES_C
${SIP_MESSAGE_GENERATED_SOURCE_FILES_C}
${TUNNEL_SOURCE_FILES_C}
)
if(ANDROID)
list(APPEND BELLE_SIP_SOURCE_FILES_C wakelock.c)
endif()
set(BELLE_SIP_SOURCE_FILES_CXX
${TUNNEL_SOURCE_FILES_CXX}
)
......
......@@ -24,13 +24,17 @@ static void jni_key_cleanup(void *data);
void belle_sip_wake_lock_init(JNIEnv *env, jobject pm) {
if(ctx.jvm == NULL) {
jclass powerManagerClass;
jclass wakeLockClass;
jfieldID fieldID;
(*env)->GetJavaVM(env, &ctx.jvm);
ctx.powerManager = (*env)->NewGlobalRef(env, pm);
pthread_key_create(&ctx.jniEnvKey, jni_key_cleanup);
jclass powerManagerClass = (*env)->FindClass(env, "android/os/PowerManager");
jclass wakeLockClass = (*env)->FindClass(env, "android/os/PowerManager$WakeLock");
jfieldID fieldID = (*env)->GetStaticFieldID(env, powerManagerClass, "PARTIAL_WAKE_LOCK", "I");
powerManagerClass = (*env)->FindClass(env, "android/os/PowerManager");
wakeLockClass = (*env)->FindClass(env, "android/os/PowerManager$WakeLock");
fieldID = (*env)->GetStaticFieldID(env, powerManagerClass, "PARTIAL_WAKE_LOCK", "I");
ctx.PARTIAL_WAKE_LOCK = (*env)->GetStaticIntField(env, powerManagerClass, fieldID);
ctx.newWakeLockID = (*env)->GetMethodID(env, powerManagerClass, "newWakeLock", "(ILjava/lang/String;)Landroid/os/PowerManager$WakeLock;");
......@@ -57,8 +61,8 @@ void belle_sip_wake_lock_uninit(JNIEnv *env) {
* @param data Unused.
*/
static void jni_key_cleanup(void *data) {
belle_sip_message("Thread end. Cleanup wake lock jni environment");
JNIEnv *env = pthread_getspecific(ctx.jniEnvKey);
belle_sip_message("Thread end. Cleanup wake lock jni environment");
if(env != NULL) {
if(ctx.jvm != NULL) {
(*ctx.jvm)->DetachCurrentThread(ctx.jvm);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment