Commit b54f55cd authored by Mickaël Turnel's avatar Mickaël Turnel

Add wifi_only option in core instead of app

parent 5305754f
......@@ -3231,6 +3231,17 @@ void linphone_core_enable_ipv6(LinphoneCore *lc, bool_t val){
}
}
bool_t linphone_core_wifi_only_enabled(LinphoneCore *lc) {
return (bool_t)lp_config_get_int(lc->config, "net", "wifi_only", 0);
}
void linphone_core_enable_wifi_only(LinphoneCore *lc, bool_t val) {
if (linphone_core_ready(lc)) {
lp_config_set_int(lc->config, "net", "wifi_only", (int)val);
getPlatformHelpers(lc)->onWifiOnlyEnabled(val);
}
}
bool_t linphone_core_content_encoding_supported(const LinphoneCore *lc, const char *content_encoding) {
const char *handle_content_encoding = lp_config_get_string(lc->config, "sip", "handle_content_encoding", "deflate");
return (strcmp(handle_content_encoding, content_encoding) == 0) && lc->sal->isContentEncodingAvailable(content_encoding);
......
......@@ -1555,6 +1555,22 @@ LINPHONE_PUBLIC bool_t linphone_core_ipv6_enabled(LinphoneCore *lc);
**/
LINPHONE_PUBLIC void linphone_core_enable_ipv6(LinphoneCore *lc, bool_t val);
/**
* Tells whether Wifi only mode is enabled or not
* @param[in] lc #LinphoneCore object
* @return A boolean value telling whether Wifi only mode is enabled or not
* @ingroup network_parameters
**/
LINPHONE_PUBLIC bool_t linphone_core_wifi_only_enabled(LinphoneCore *lc);
/**
* Turns Wifi only mode on or off
* @param[in] lc #LinphoneCore object
* @param[in] val A boolean value telling whether to enable IPv6 support
* @ingroup network_parameters
**/
LINPHONE_PUBLIC void linphone_core_enable_wifi_only(LinphoneCore *lc, bool_t val);
/**
* Same as linphone_core_get_primary_contact() but the result is a #LinphoneAddress object
* instead of const char *.
......
......@@ -50,6 +50,7 @@ public:
void setVideoPreviewWindow (void *windowId) override;
void setNetworkReachable (bool reachable) override;
void onLinphoneCoreReady () override;
void onWifiOnlyEnabled (bool enabled) override;
void _setPreviewVideoWindow(jobject window);
void _setVideoWindow(jobject window);
......@@ -74,6 +75,7 @@ private:
jmethodID mSetNativePreviewVideoWindowId;
jmethodID mUpdateNetworkReachabilityId;
jmethodID mOnLinphoneCoreReadyId;
jmethodID mOnWifiOnlyEnabledId;
jobject mPreviewVideoWindow;
jobject mVideoWindow;
};
......@@ -123,6 +125,7 @@ AndroidPlatformHelpers::AndroidPlatformHelpers (LinphoneCore *lc, void *systemCo
mSetNativePreviewVideoWindowId = getMethodId(env, klass, "setVideoPreviewView", "(Ljava/lang/Object;)V");
mUpdateNetworkReachabilityId = getMethodId(env, klass, "updateNetworkReachability", "()V");
mOnLinphoneCoreReadyId = getMethodId(env, klass, "onLinphoneCoreReady", "()V");
mOnWifiOnlyEnabledId = getMethodId(env, klass, "onWifiOnlyEnabled", "(Z)V");
jobject pm = env->CallObjectMethod(mJavaHelper, mGetPowerManagerId);
belle_sip_wake_lock_init(env, pm);
......@@ -311,6 +314,13 @@ void AndroidPlatformHelpers::onLinphoneCoreReady() {
}
}
void AndroidPlatformHelpers::onWifiOnlyEnabled(bool enabled) {
JNIEnv *env = ms_get_jni_env();
if (env && mJavaHelper) {
env->CallVoidMethod(mJavaHelper, mOnWifiOnlyEnabledId, (jboolean)enabled);
}
}
PlatformHelpers *createAndroidPlatformHelpers (LinphoneCore *lc, void *systemContext) {
return new AndroidPlatformHelpers(lc, systemContext);
}
......
......@@ -57,4 +57,6 @@ void StubbedPlatformHelpers::setNetworkReachable (bool reachable) {}
void StubbedPlatformHelpers::onLinphoneCoreReady () {}
void StubbedPlatformHelpers::onWifiOnlyEnabled (bool enabled) {}
LINPHONE_END_NAMESPACE
......@@ -54,6 +54,7 @@ public:
virtual void setVideoPreviewWindow (void *windowId) = 0;
virtual void setNetworkReachable (bool reachable) = 0;
virtual void onLinphoneCoreReady () = 0;
virtual void onWifiOnlyEnabled (bool enabled) = 0;
protected:
inline explicit PlatformHelpers (LinphoneCore *lc) : mCore(lc) {}
......@@ -79,6 +80,7 @@ public:
void setVideoPreviewWindow (void *windowId) override;
void setNetworkReachable (bool reachable) override;
void onLinphoneCoreReady () override;
void onWifiOnlyEnabled (bool enabled) override;
};
PlatformHelpers *createAndroidPlatformHelpers (LinphoneCore *lc, void *systemContext);
......
......@@ -84,14 +84,16 @@ public class AndroidPlatformHelper {
private BroadcastReceiver mNetworkReceiver;
private IntentFilter mDozeIntentFilter;
private IntentFilter mNetworkIntentFilter;
private boolean mWifiOnly;
private native void setNativePreviewWindowId(long nativePtr, Object view);
private native void setNativeVideoWindowId(long nativePtr, Object view);
private native void setNetworkReachable(long nativePtr, boolean reachable);
public AndroidPlatformHelper(long nativePtr, Object ctx_obj) {
public AndroidPlatformHelper(long nativePtr, Object ctx_obj, boolean wifiOnly) {
mNativePtr = nativePtr;
mContext = (Context) ctx_obj;
mWifiOnly = wifiOnly;
mResources = mContext.getResources();
MediastreamerAndroidContext.setContext(mContext);
......@@ -168,6 +170,9 @@ public class AndroidPlatformHelper {
updateNetworkReachability();
}
public void onWifiOnlyEnabled(boolean enabled) {
mWifiOnly = enabled;
updateNetworkReachability();
}
public Object getPowerManager() {
......@@ -422,6 +427,14 @@ public class AndroidPlatformHelper {
Log.i("Doze Mode enabled: shutting down network");
setNetworkReachable(mNativePtr, false);
} else if (connected) {
if (mWifiOnly) {
if (networkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
setNetworkReachable(mNativePtr, true);
} else {
Log.i("Wifi-only mode, setting network not reachable");
setNetworkReachable(mNativePtr, false);
}
} else {
int curtype = networkInfo.getType();
if (curtype != mLastNetworkType) {
......@@ -432,6 +445,7 @@ public class AndroidPlatformHelper {
}
setNetworkReachable(mNativePtr, true);
mLastNetworkType = curtype;
}
}
}
......
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