Commit 08be1ad6 authored by Mickaël Turnel's avatar Mickaël Turnel

Added an internal network reachable function used by platform helpers

If net_auto_state_mon is activated then the network would be reachable only if
both of network_reachable and network_reachable_internal are set to TRUE.
If not only network_reachable will be used.
parent 7dbb7a4a
......@@ -2096,7 +2096,7 @@ void linphone_configuring_terminated(LinphoneCore *lc, LinphoneConfiguringState
lc->provisioning_http_listener = NULL;
}
getPlatformHelpers(lc)->onLinphoneCoreReady();
getPlatformHelpers(lc)->onLinphoneCoreReady(lc->auto_net_state_mon);
linphone_core_set_state(lc,LinphoneGlobalOn,"Ready");
}
......@@ -2378,6 +2378,10 @@ static void linphone_core_init(LinphoneCore * lc, LinphoneCoreCbs *cbs, LpConfig
lc->network_last_check = 0;
lc->network_last_status = FALSE;
lc->network_reachable = TRUE;
lc->sip_network_reachable = TRUE;
lc->media_network_reachable = TRUE;
/* Create the http provider in dual stack mode (ipv4 and ipv6.
* If this creates problem, we may need to implement parallel ipv6/ ipv4 http requests in belle-sip.
*/
......@@ -3433,7 +3437,7 @@ void linphone_core_iterate(LinphoneCore *lc){
lc->sal->iterate();
if (lc->msevq) ms_event_queue_pump(lc->msevq);
if (lc->auto_net_state_mon) monitor_network_state(lc, current_real_time);
//if (lc->auto_net_state_mon) monitor_network_state(lc, current_real_time);
proxy_update(lc);
......@@ -6401,20 +6405,29 @@ static void disable_internal_network_reachability_detection(LinphoneCore *lc){
}
}
void linphone_core_set_network_reachable(LinphoneCore *lc, bool_t isReachable) {
disable_internal_network_reachability_detection(lc);
set_network_reachable(lc, isReachable, ms_time(NULL));
void linphone_core_set_network_reachable_internal(LinphoneCore *lc, bool_t is_reachable) {
if (lc->auto_net_state_mon) {
set_network_reachable(lc, lc->network_reachable && is_reachable, ms_time(NULL));
notify_network_reachable_change(lc);
}
}
void linphone_core_set_network_reachable(LinphoneCore *lc, bool_t is_reachable) {
bool_t reachable = is_reachable;
if (lc->auto_net_state_mon) reachable = reachable && getPlatformHelpers(lc)->isNetworkReachable();
lc->network_reachable = is_reachable;
set_network_reachable(lc, reachable, ms_time(NULL));
notify_network_reachable_change(lc);
}
void linphone_core_set_media_network_reachable(LinphoneCore *lc, bool_t is_reachable){
disable_internal_network_reachability_detection(lc);
set_media_network_reachable(lc, is_reachable);
notify_network_reachable_change(lc);
}
void linphone_core_set_sip_network_reachable(LinphoneCore *lc, bool_t is_reachable){
disable_internal_network_reachability_detection(lc);
set_sip_network_reachable(lc, is_reachable, ms_time(NULL));
notify_network_reachable_change(lc);
}
......
......@@ -189,6 +189,8 @@ int parse_hostname_to_addr(const char *server, struct sockaddr_storage *ss, sock
bool_t host_has_ipv6_network(void);
bool_t lp_spawn_command_line_sync(const char *command, char **result,int *command_ret);
void linphone_core_set_network_reachable_internal(LinphoneCore *lc, bool_t is_reachable);
static MS2_INLINE void set_string(char **dest, const char *src, bool_t lowercase){
if (*dest){
ms_free(*dest);
......
......@@ -778,6 +778,7 @@ namespace LinphonePrivate {
bool_t bl_refresh; \
bool_t preview_finished; \
bool_t auto_net_state_mon; \
bool_t network_reachable; \
bool_t sip_network_reachable; \
bool_t media_network_reachable; \
bool_t network_reachable_to_be_notified; \
......
......@@ -49,7 +49,8 @@ public:
void setVideoWindow (void *windowId) override;
void setVideoPreviewWindow (void *windowId) override;
void setNetworkReachable (bool reachable) override;
void onLinphoneCoreReady () override;
bool isNetworkReachable () override;
void onLinphoneCoreReady (bool monitoringEnabled) override;
void onWifiOnlyEnabled (bool enabled) override;
void setHttpProxy (string host, int port) override;
......@@ -60,6 +61,7 @@ private:
int callVoidMethod (jmethodID id);
static jmethodID getMethodId (JNIEnv *env, jclass klass, const char *method, const char *signature);
string getNativeLibraryDir();
jobject mJavaHelper;
jmethodID mWifiLockAcquireId;
jmethodID mWifiLockReleaseId;
......@@ -79,6 +81,8 @@ private:
jmethodID mOnWifiOnlyEnabledId;
jobject mPreviewVideoWindow;
jobject mVideoWindow;
bool mNetworkReachable;
};
static const char *GetStringUTFChars (JNIEnv *env, jstring string) {
......@@ -125,7 +129,7 @@ AndroidPlatformHelpers::AndroidPlatformHelpers (LinphoneCore *lc, void *systemCo
mSetNativeVideoWindowId = getMethodId(env, klass, "setVideoRenderingView", "(Ljava/lang/Object;)V");
mSetNativePreviewVideoWindowId = getMethodId(env, klass, "setVideoPreviewView", "(Ljava/lang/Object;)V");
mUpdateNetworkReachabilityId = getMethodId(env, klass, "updateNetworkReachability", "()V");
mOnLinphoneCoreReadyId = getMethodId(env, klass, "onLinphoneCoreReady", "()V");
mOnLinphoneCoreReadyId = getMethodId(env, klass, "onLinphoneCoreReady", "(Z)V");
mOnWifiOnlyEnabledId = getMethodId(env, klass, "onWifiOnlyEnabled", "(Z)V");
jobject pm = env->CallObjectMethod(mJavaHelper, mGetPowerManagerId);
......@@ -137,6 +141,7 @@ AndroidPlatformHelpers::AndroidPlatformHelpers (LinphoneCore *lc, void *systemCo
mPreviewVideoWindow = nullptr;
mVideoWindow = nullptr;
mNetworkReachable = false;
}
AndroidPlatformHelpers::~AndroidPlatformHelpers () {
......@@ -305,13 +310,18 @@ void AndroidPlatformHelpers::_setVideoWindow(jobject window) {
}
void AndroidPlatformHelpers::setNetworkReachable(bool reachable) {
linphone_core_set_network_reachable(mCore, reachable);
mNetworkReachable = reachable;
linphone_core_set_network_reachable_internal(mCore, reachable ? 1 : 0);
}
bool AndroidPlatformHelpers::isNetworkReachable() {
return mNetworkReachable;
}
void AndroidPlatformHelpers::onLinphoneCoreReady() {
void AndroidPlatformHelpers::onLinphoneCoreReady(bool monitoringEnabled) {
JNIEnv *env = ms_get_jni_env();
if (env && mJavaHelper) {
env->CallVoidMethod(mJavaHelper, mOnLinphoneCoreReadyId);
env->CallVoidMethod(mJavaHelper, mOnLinphoneCoreReadyId, (jboolean)monitoringEnabled);
}
}
......
......@@ -57,6 +57,11 @@ public:
string getConfigPath () override {return Utils::getEmptyConstRefObject<string>();}
void setVideoWindow (void *windowId) override {}
void setVideoPreviewWindow (void *windowId) override {}
void setNetworkReachable (bool reachable) override {}
bool isNetworkReachable () override {}
void onLinphoneCoreReady (bool monitoringEnabled) override {}
void onWifiOnlyEnabled (bool enabled) override {}
void setHttpProxy (string host, int port) override {}
private:
void bgTaskTimeout ();
......
......@@ -55,7 +55,11 @@ void StubbedPlatformHelpers::setVideoWindow (void *windowId) {}
void StubbedPlatformHelpers::setNetworkReachable (bool reachable) {}
void StubbedPlatformHelpers::onLinphoneCoreReady () {}
bool StubbedPlatformHelpers::isNetworkReachable () {
return true;
}
void StubbedPlatformHelpers::onLinphoneCoreReady (bool monitoringEnabled) {}
void StubbedPlatformHelpers::onWifiOnlyEnabled (bool enabled) {}
......
......@@ -53,7 +53,8 @@ public:
virtual void setVideoWindow (void *windowId) = 0;
virtual void setVideoPreviewWindow (void *windowId) = 0;
virtual void setNetworkReachable (bool reachable) = 0;
virtual void onLinphoneCoreReady () = 0;
virtual bool isNetworkReachable () = 0;
virtual void onLinphoneCoreReady (bool monitoringEnabled) = 0;
virtual void onWifiOnlyEnabled (bool enabled) = 0;
virtual void setHttpProxy (std::string host, int port) = 0;
......@@ -80,7 +81,8 @@ public:
void setVideoWindow (void *windowId) override;
void setVideoPreviewWindow (void *windowId) override;
void setNetworkReachable (bool reachable) override;
void onLinphoneCoreReady () override;
bool isNetworkReachable () override;
void onLinphoneCoreReady (bool monitoringEnabled) override;
void onWifiOnlyEnabled (bool enabled) override;
void setHttpProxy (std::string host, int port) override;
};
......
......@@ -140,7 +140,9 @@ public class AndroidPlatformHelper {
return instance;
}
public void onLinphoneCoreReady() {
public void onLinphoneCoreReady(boolean monitoringEnabled) {
if (!monitoringEnabled) return;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
mNetworkReceiver = new NetworkManager();
mNetworkIntentFilter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
......
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