Commit 5bf0b48d authored by Ghislain MARY's avatar Ghislain MARY

Improve tunnel management.

parent cc1c4d07
......@@ -39,7 +39,7 @@ namespace Linphone.Model
Debug.WriteLine("[LinphoneManager] Network state changed:" + (lastNetworkState ? "Available" : "Unavailable"));
if (lastNetworkState)
{
NetworkSettingsManager.ConfigureTunnel();
ConfigureTunnel();
}
LinphoneCore.SetNetworkReachable(lastNetworkState);
}
......@@ -278,6 +278,7 @@ namespace Linphone.Model
lastNetworkState = DeviceNetworkInformation.IsNetworkAvailable;
server.LinphoneCore.SetNetworkReachable(lastNetworkState);
DeviceNetworkInformation.NetworkAvailabilityChanged += new EventHandler<NetworkNotificationEventArgs>(OnNetworkStatusChanged);
ConfigureTunnel();
isLinphoneRunning = true;
}
......@@ -331,6 +332,59 @@ namespace Linphone.Model
server.LinphoneCoreFactory.SetLogLevel(appSettings.LogLevel);
Logger.Instance.TraceListener = server.BackgroundModeLogger;
}
/// <summary>
/// Configures the Tunnel using the given mode
/// </summary>
/// <param name="mode">mode to apply</param>
public static void ConfigureTunnel(String mode)
{
if (LinphoneManager.Instance.LinphoneCore.IsTunnelAvailable())
{
Tunnel tunnel = LinphoneManager.Instance.LinphoneCore.GetTunnel();
if (tunnel != null)
{
if (mode == AppResources.TunnelModeDisabled)
{
tunnel.Enable(false);
}
else if (mode == AppResources.TunnelModeAlways)
{
tunnel.Enable(true);
}
else if (mode == AppResources.TunnelModeAuto)
{
tunnel.Enable(false);
tunnel.AutoDetect();
}
else if (mode == AppResources.TunnelMode3GOnly)
{
if (DeviceNetworkInformation.IsWiFiEnabled)
{
tunnel.Enable(false);
}
else if (DeviceNetworkInformation.IsCellularDataEnabled)
{
tunnel.Enable(true);
}
else
{
tunnel.Enable(false);
}
}
}
}
}
/// <summary>
/// Configures the Tunnel using the current setting value
/// </summary>
public void ConfigureTunnel()
{
NetworkSettingsManager settings = new NetworkSettingsManager();
settings.Load();
ConfigureTunnel(settings.TunnelMode);
}
#endregion
#region CallLogs
......
......@@ -996,56 +996,6 @@ namespace Linphone.Model
private const string TunnelModeKeyName = "TunnelMode";
#endregion
/// <summary>
/// Configures the Tunnel using the given mode
/// </summary>
/// <param name="mode">mode to apply</param>
public static void ConfigureTunnel(String mode)
{
if (LinphoneManager.Instance.LinphoneCore.IsTunnelAvailable()) {
Tunnel tunnel = LinphoneManager.Instance.LinphoneCore.GetTunnel();
if (tunnel != null)
{
if (mode == AppResources.TunnelModeDisabled)
{
tunnel.Enable(false);
}
else if (mode == AppResources.TunnelModeAlways)
{
tunnel.Enable(true);
}
else if (mode == AppResources.TunnelModeAuto)
{
tunnel.AutoDetect();
}
else if (mode == AppResources.TunnelMode3GOnly)
{
if (DeviceNetworkInformation.IsWiFiEnabled)
{
tunnel.Enable(false);
}
else if (DeviceNetworkInformation.IsCellularDataEnabled)
{
tunnel.Enable(true);
}
else
{
tunnel.Enable(false);
}
}
}
}
}
/// <summary>
/// Configures the Tunnel using the current setting value
/// </summary>
public static void ConfigureTunnel()
{
NetworkSettingsManager settings = new NetworkSettingsManager();
ConfigureTunnel(settings.TunnelMode);
}
/// <summary>
/// Public constructor.
/// </summary>
......@@ -1185,7 +1135,7 @@ namespace Linphone.Model
{
String mode = GetNew(TunnelModeKeyName);
Config.SetString(ApplicationSection, TunnelModeKeyName, TunnelModeToString[mode]);
ConfigureTunnel(mode);
LinphoneManager.Instance.ConfigureTunnel();
}
}
}
......
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