Commit 7dbb7a4a authored by Mickaël Turnel's avatar Mickaël Turnel

Set http proxy if there is one

parent 91d14a29
......@@ -51,6 +51,7 @@ public:
void setNetworkReachable (bool reachable) override;
void onLinphoneCoreReady () override;
void onWifiOnlyEnabled (bool enabled) override;
void setHttpProxy (string host, int port) override;
void _setPreviewVideoWindow(jobject window);
void _setVideoWindow(jobject window);
......@@ -321,6 +322,11 @@ 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);
}
PlatformHelpers *createAndroidPlatformHelpers (LinphoneCore *lc, void *systemContext) {
return new AndroidPlatformHelpers(lc, systemContext);
}
......@@ -340,4 +346,10 @@ extern "C" JNIEXPORT void JNICALL Java_org_linphone_core_tools_AndroidPlatformHe
androidPlatformHelper->setNetworkReachable(reachable);
}
extern "C" JNIEXPORT void JNICALL Java_org_linphone_core_tools_AndroidPlatformHelper_setHttpProxy(JNIEnv* env, jobject thiz, jlong ptr, jstring host, jint port) {
AndroidPlatformHelpers *androidPlatformHelper = (AndroidPlatformHelpers *)ptr;
const char *hostC = GetStringUTFChars(env, host);
androidPlatformHelper->setHttpProxy(hostC, port);
}
LINPHONE_END_NAMESPACE
......@@ -59,4 +59,6 @@ void StubbedPlatformHelpers::onLinphoneCoreReady () {}
void StubbedPlatformHelpers::onWifiOnlyEnabled (bool enabled) {}
void StubbedPlatformHelpers::setHttpProxy (string host, int port) {}
LINPHONE_END_NAMESPACE
......@@ -55,6 +55,7 @@ public:
virtual void setNetworkReachable (bool reachable) = 0;
virtual void onLinphoneCoreReady () = 0;
virtual void onWifiOnlyEnabled (bool enabled) = 0;
virtual void setHttpProxy (std::string host, int port) = 0;
protected:
inline explicit PlatformHelpers (LinphoneCore *lc) : mCore(lc) {}
......@@ -81,6 +82,7 @@ public:
void setNetworkReachable (bool reachable) override;
void onLinphoneCoreReady () override;
void onWifiOnlyEnabled (bool enabled) override;
void setHttpProxy (std::string host, int port) override;
};
PlatformHelpers *createAndroidPlatformHelpers (LinphoneCore *lc, void *systemContext);
......
......@@ -40,6 +40,7 @@ import android.net.ConnectivityManager;
import android.net.Network;
import android.net.NetworkInfo;
import android.net.NetworkRequest;
import android.net.ProxyInfo;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
import android.os.Build;
......@@ -85,10 +86,12 @@ public class AndroidPlatformHelper {
private IntentFilter mDozeIntentFilter;
private IntentFilter mNetworkIntentFilter;
private boolean mWifiOnly;
private boolean mUsingHttpProxy;
private native void setNativePreviewWindowId(long nativePtr, Object view);
private native void setNativeVideoWindowId(long nativePtr, Object view);
private native void setNetworkReachable(long nativePtr, boolean reachable);
private native void setHttpProxy(long nativePtr, String host, int port);
public AndroidPlatformHelper(long nativePtr, Object ctx_obj, boolean wifiOnly) {
mNativePtr = nativePtr;
......@@ -416,10 +419,23 @@ public class AndroidPlatformHelper {
public void updateNetworkReachability() {
if (mConnectivityManager == null) return;
boolean usingHttpProxyBefore = mUsingHttpProxy;
boolean connected = false;
NetworkInfo networkInfo = mConnectivityManager.getActiveNetworkInfo();
connected = networkInfo != null && networkInfo.isConnected();
if (connected){
ProxyInfo proxy = mConnectivityManager.getDefaultProxy();
if (proxy != null && proxy.getHost() != null){
Log.i("The active network is using an http proxy: " + proxy.toString());
setHttpProxy(mNativePtr, proxy.getHost(), proxy.getPort());
mUsingHttpProxy = true;
}else{
setHttpProxy(mNativePtr, "", 0);
mUsingHttpProxy = false;
}
}
if (networkInfo == null || !connected) {
Log.i("No connectivity: setting network unreachable");
setNetworkReachable(mNativePtr, false);
......@@ -437,7 +453,7 @@ public class AndroidPlatformHelper {
} else {
int curtype = networkInfo.getType();
if (curtype != mLastNetworkType) {
if (curtype != mLastNetworkType || mUsingHttpProxy != usingHttpProxyBefore) {
//if kind of network has changed, we need to notify network_reachable(false) to make sure all current connections are destroyed.
//they will be re-created during setNetworkReachable(true).
Log.i("Connectivity has changed.");
......
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