Commit cd25aca9 authored by Sylvain Berfini's avatar Sylvain Berfini 🎩

Fixes & improvements on Android platform helper

parent 0fd45a67
......@@ -120,7 +120,7 @@ AndroidPlatformHelpers::AndroidPlatformHelpers (LinphoneCore *lc, void *systemCo
lFatal() << "Could not find java AndroidPlatformHelper class.";
jmethodID ctor = env->GetMethodID(klass, "<init>", "(JLjava/lang/Object;Z)V");
mJavaHelper = env->NewObject(klass, ctor, (jlong)this, (jobject)systemContext, (jboolean)linphone_core_wifi_only_enabled(lc));
mJavaHelper = env->NewObject(klass, ctor, (jlong)this, (jobject)systemContext, (jboolean)linphone_core_wifi_only_enabled(getCore()));
if (!mJavaHelper) {
lError() << "Could not instanciate AndroidPlatformHelper object.";
return;
......@@ -291,17 +291,19 @@ void AndroidPlatformHelpers::onWifiOnlyEnabled(bool enabled) {
}
void AndroidPlatformHelpers::setHttpProxy(string host, int port) {
linphone_core_set_http_proxy_host(mCore, host.c_str());
linphone_core_set_http_proxy_port(mCore, port);
linphone_core_set_http_proxy_host(getCore(), host.c_str());
linphone_core_set_http_proxy_port(getCore(), port);
}
void AndroidPlatformHelpers::setDnsServers () {
if (!mJavaHelper || linphone_core_get_dns_set_by_app(mCore)) {
if (!mJavaHelper) {
lError() << "AndroidPlatformHelpers' mJavaHelper is null.";
return;
}
if (linphone_core_get_dns_set_by_app(getCore())) return;
JNIEnv *env = ms_get_jni_env();
if (env && mJavaHelper) {
if (env) {
jobjectArray jservers = (jobjectArray)env->CallObjectMethod(mJavaHelper, mGetDnsServersId);
bctbx_list_t *l = nullptr;
if (env->ExceptionCheck()) {
......@@ -323,15 +325,16 @@ void AndroidPlatformHelpers::setDnsServers () {
}
} else {
lError() << "AndroidPlatformHelpers::setDnsServers() failed to get DNS servers list";
return;
}
linphone_core_set_dns_servers(mCore, l);
linphone_core_set_dns_servers(getCore(), l);
bctbx_list_free_with_data(l, ms_free);
}
}
void AndroidPlatformHelpers::setNetworkReachable(bool reachable) {
mNetworkReachable = reachable;
linphone_core_set_network_reachable_internal(mCore, reachable ? 1 : 0);
linphone_core_set_network_reachable_internal(getCore(), reachable ? 1 : 0);
}
// -----------------------------------------------------------------------------
......
......@@ -109,7 +109,9 @@ public class AndroidPlatformHelper {
mNetworkUpdateRunner = new Runnable() {
@Override
public void run() {
updateNetworkReachability();
synchronized(AndroidPlatformHelper.this) {
updateNetworkReachability();
}
}
};
......@@ -142,28 +144,27 @@ public class AndroidPlatformHelper {
}
}
public void onLinphoneCoreStart(boolean monitoringEnabled) {
public synchronized void onLinphoneCoreStart(boolean monitoringEnabled) {
mMonitoringEnabled = monitoringEnabled;
startNetworkMonitoring();
}
public synchronized void onLinphoneCoreStop() {
stopNetworkMonitoring();
mNativePtr = 0;
mMainHandler.removeCallbacks(mNetworkUpdateRunner);
mMainHandler.removeCallbacksAndMessages(null);
stopNetworkMonitoring();
}
public void onWifiOnlyEnabled(boolean enabled) {
public synchronized void onWifiOnlyEnabled(boolean enabled) {
mWifiOnly = enabled;
postNetworkUpdateRunner();
}
public Object getPowerManager() {
public synchronized Object getPowerManager() {
return mPowerManager;
}
public String[] getDnsServers() {
public synchronized String[] getDnsServers() {
if (mConnectivityManager == null || Build.VERSION.SDK_INT < Version.API23_MARSHMALLOW_60)
return null;
......@@ -243,10 +244,10 @@ public class AndroidPlatformHelper {
private int getResourceIdentifierFromName(String name) {
int resId = mResources.getIdentifier(name, "raw", mContext.getPackageName());
if (resId == 0) {
Log.d("App doesn't seem to embed resource " + name + "in it's res/raw/ directory, use linphone's instead");
Log.d("App doesn't seem to embed resource " + name + " in it's res/raw/ directory, use linphone's instead");
resId = mResources.getIdentifier(name, "raw", "org.linphone");
if (resId == 0) {
Log.i("App doesn't seem to embed resource " + name + "in it's res/raw/ directory. Make sure this file is either brought as an asset or a resource");
Log.i("App doesn't seem to embed resource " + name + " in it's res/raw/ directory. Make sure this file is either brought as an asset or a resource");
}
}
return resId;
......@@ -411,7 +412,8 @@ public class AndroidPlatformHelper {
}
}
public void postNetworkUpdateRunner() {
public synchronized void postNetworkUpdateRunner() {
mMainHandler.removeCallbacksAndMessages(null);
mMainHandler.post(mNetworkUpdateRunner);
}
......@@ -467,11 +469,11 @@ public class AndroidPlatformHelper {
}
}
public void setDozeModeEnabled(boolean b) {
public synchronized void setDozeModeEnabled(boolean b) {
dozeModeEnabled = b;
}
private void startNetworkMonitoring() {
private synchronized void startNetworkMonitoring() {
if (!mMonitoringEnabled) return;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
......@@ -494,7 +496,7 @@ public class AndroidPlatformHelper {
postNetworkUpdateRunner();
}
private void stopNetworkMonitoring() {
private synchronized void stopNetworkMonitoring() {
if (!mMonitoringEnabled) return;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
......
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