From faa60922366ddb62f35ec4fe05bfd4bc8fc87aa6 Mon Sep 17 00:00:00 2001 From: Simon Morlat Date: Tue, 3 Nov 2015 18:29:47 +0100 Subject: [PATCH] fix crashes in android when doing things with LinphoneCore within the globalStateChanged callbacks. Add wrappers for the http proxy api. --- coreapi/linphonecore_jni.cc | 55 +++++++++++++++++++ .../org/linphone/core/LinphoneCore.java | 18 ++++++ .../org/linphone/core/LinphoneCoreImpl.java | 23 ++++++++ 3 files changed, 96 insertions(+) diff --git a/coreapi/linphonecore_jni.cc b/coreapi/linphonecore_jni.cc index 6ff983bbc..df6699c40 100644 --- a/coreapi/linphonecore_jni.cc +++ b/coreapi/linphonecore_jni.cc @@ -659,6 +659,15 @@ public: env->DeleteLocalRef(d); } } + static void setCoreIfNotDone(JNIEnv *env, jobject jcore, LinphoneCore *lc){ + jclass objClass = env->GetObjectClass(jcore); + jfieldID myFieldID = env->GetFieldID(objClass, "nativePtr", "J"); + jlong fieldVal = env->GetLongField(jcore, myFieldID); + if (fieldVal == 0){ + env->SetLongField(jcore, myFieldID, (jlong)lc); + } + } + static void globalStateChange(LinphoneCore *lc, LinphoneGlobalState gstate,const char* message) { JNIEnv *env = 0; jint result = jvm->AttachCurrentThread(&env,NULL); @@ -668,6 +677,11 @@ public: } LinphoneCoreVTable *table = linphone_core_get_current_vtable(lc); LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_v_table_get_user_data(table); + + jobject jcore = lcData->core; + /*at this stage, the java object may not be aware of its C object, because linphone_core_new() hasn't returned yet.*/ + setCoreIfNotDone(env,jcore, lc); + jstring msg = message ? env->NewStringUTF(message) : NULL; env->CallVoidMethod(lcData->listener ,lcData->globalStateId @@ -6475,3 +6489,44 @@ JNIEXPORT jstring JNICALL Java_org_linphone_core_LinphoneCallLogImpl_getCallId(J return str ? env->NewStringUTF(str) : NULL; } +/* + * Class: org_linphone_core_LinphoneCoreImpl + * Method: setHttpProxyHost + * Signature: (JLjava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_org_linphone_core_LinphoneCoreImpl_setHttpProxyHost(JNIEnv *env, jobject jobj, jlong core, jstring jhost){ + const char *host = jhost ? env->GetStringUTFChars(jhost, NULL) : NULL; + linphone_core_set_http_proxy_host((LinphoneCore*)core, host); + if (host) env->ReleaseStringUTFChars(jhost, host); +} + +/* + * Class: org_linphone_core_LinphoneCoreImpl + * Method: setHttpProxyPort + * Signature: (JI)V + */ +JNIEXPORT void JNICALL Java_org_linphone_core_LinphoneCoreImpl_setHttpProxyPort(JNIEnv *env, jobject jobj, jlong core, jint port){ + linphone_core_set_http_proxy_port((LinphoneCore*)core, port); +} + +/* + * Class: org_linphone_core_LinphoneCoreImpl + * Method: getHttpProxyHost + * Signature: (J)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_org_linphone_core_LinphoneCoreImpl_getHttpProxyHost(JNIEnv *env , jobject jobj, jlong core){ + const char * host = linphone_core_get_http_proxy_host((LinphoneCore *)core); + return host ? env->NewStringUTF(host) : NULL; +} + +/* + * Class: org_linphone_core_LinphoneCoreImpl + * Method: getHttpProxyPort + * Signature: (J)I + */ +JNIEXPORT jint JNICALL Java_org_linphone_core_LinphoneCoreImpl_getHttpProxyPort(JNIEnv *env, jobject jobj, jlong core){ + return linphone_core_get_http_proxy_port((LinphoneCore *)core); +} + + + diff --git a/java/common/org/linphone/core/LinphoneCore.java b/java/common/org/linphone/core/LinphoneCore.java index 70c71d799..595b1a2e9 100644 --- a/java/common/org/linphone/core/LinphoneCore.java +++ b/java/common/org/linphone/core/LinphoneCore.java @@ -2179,4 +2179,22 @@ public interface LinphoneCore { * Get the provisioning URI previously set. **/ public String getProvisioningUri(); + + /** + * Set an http proxy hostname or IP address to use for SIP connection. + */ + public void setHttpProxyHost(String host); + /** + * Set an http proxy port to use for SIP connection. + */ + public void setHttpProxyPort(int port); + /** + * Get the http proxy host previously set. + **/ + public String getHttpProxyHost(); + /** + * Get the http proxy port previously set. + **/ + public int getHttpProxyPort(); + } diff --git a/java/impl/org/linphone/core/LinphoneCoreImpl.java b/java/impl/org/linphone/core/LinphoneCoreImpl.java index 297ebc0f1..7f2bdfd34 100644 --- a/java/impl/org/linphone/core/LinphoneCoreImpl.java +++ b/java/impl/org/linphone/core/LinphoneCoreImpl.java @@ -1535,4 +1535,27 @@ class LinphoneCoreImpl implements LinphoneCore { public GlobalState getGlobalState(){ return GlobalState.fromInt(getGlobalState(nativePtr)); } + private native void setHttpProxyHost(long nativePtr, String host); + @Override + public void setHttpProxyHost(String host){ + setHttpProxyHost(nativePtr, host); + } + + private native void setHttpProxyPort(long nativePtr, int port); + @Override + public void setHttpProxyPort(int port){ + setHttpProxyPort(nativePtr, port); + } + + private native String getHttpProxyHost(long nativePtr); + @Override + public String getHttpProxyHost(){ + return getHttpProxyHost(nativePtr); + } + + private native int getHttpProxyPort(long nativePtr); + @Override + public int getHttpProxyPort(){ + return getHttpProxyPort(nativePtr); + } }