internal System.Net.IPAddress GetIPAddress(AddressFamily family) { Log.Info(Globals.LogTag, "GetIPAddress " + family); IntPtr ip; int ret = Interop.Connection.GetIPAddress(GetHandle(), (int)family, out ip); if ((ConnectionError)ret != ConnectionError.None) { Log.Error(Globals.LogTag, "It failed to get IP address, " + (ConnectionError)ret); ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.telephony " + "http://tizen.org/feature/network.wifi " + "http://tizen.org/feature/network.tethering.bluetooth " + "http://tizen.org/feature/network.ethernet"); ConnectionErrorFactory.CheckHandleNullException(ret, (GetHandle() == IntPtr.Zero), "Connection Handle may have been disposed or released"); ConnectionErrorFactory.ThrowConnectionException(ret); } string result = Marshal.PtrToStringAnsi(ip); Interop.Libc.Free(ip); Log.Info(Globals.LogTag, "IPAddress " + result + " (" + result.Length + ")"); if (result.Length == 0) { if (family == AddressFamily.IPv4) { return(System.Net.IPAddress.Parse("0.0.0.0")); } else { return(System.Net.IPAddress.Parse("::")); } } return(System.Net.IPAddress.Parse(result)); }
internal ConnectionProfile GetCurrentProfile() { Log.Info(Globals.LogTag, "GetCurrentProfile"); IntPtr ProfileHandle; int ret = Interop.Connection.GetCurrentProfile(GetHandle(), out ProfileHandle); if ((ConnectionError)ret != ConnectionError.None) { if ((ConnectionError)ret == ConnectionError.NoConnection) { Log.Error(Globals.LogTag, "No connection " + (ConnectionError)ret); return(null); } else if ((ConnectionError)ret == ConnectionError.InvalidParameter) { throw new InvalidOperationException("Invalid handle"); } else { Log.Error(Globals.LogTag, "It failed to get current profile, " + (ConnectionError)ret); ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.telephony " + "http://tizen.org/feature/network.wifi " + "http://tizen.org/feature/network.tethering.bluetooth " + "http://tizen.org/feature/network.ethernet"); ConnectionErrorFactory.CheckPermissionDeniedException(ret, "(http://tizen.org/privilege/network.get)"); ConnectionErrorFactory.CheckHandleNullException(ret, (GetHandle() == IntPtr.Zero), "Connection Handle may have been disposed or released"); ConnectionErrorFactory.ThrowConnectionException(ret); } } ConnectionProfile Profile = new ConnectionProfile(ProfileHandle); return(Profile); }
internal void AddCellularProfile(CellularProfile profile) { Log.Debug(Globals.LogTag, "AddCellularProfile"); if (profile != null) { if (profile.Type == ConnectionProfileType.Cellular) { int ret = Interop.Connection.AddProfile(GetHandle(), profile.ProfileHandle); if ((ConnectionError)ret != ConnectionError.None) { Log.Error(Globals.LogTag, "Failed to add cellular profile, " + (ConnectionError)ret); ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.telephony"); ConnectionErrorFactory.CheckPermissionDeniedException(ret, "(http://tizen.org/privilege/network.profile)"); ConnectionErrorFactory.CheckHandleNullException(ret, (GetHandle() == IntPtr.Zero || profile.ProfileHandle == IntPtr.Zero), "Connection or Profile Handle may have been disposed or released"); ConnectionErrorFactory.ThrowConnectionException(ret); } } else { throw new ArgumentException("Profile type is not cellular"); } } else { throw new ArgumentNullException("Profile is null"); } }
internal IEnumerable <System.Net.IPAddress> GetAllIPv6Addresses(ConnectionType type) { Log.Debug(Globals.LogTag, "GetAllIPv6Addresses"); List <System.Net.IPAddress> ipList = new List <System.Net.IPAddress>(); Interop.Connection.IPv6AddressCallback callback = (IntPtr ipv6Address, IntPtr userData) => { if (ipv6Address != IntPtr.Zero) { string ipv6 = Marshal.PtrToStringAnsi(ipv6Address); if (ipv6.Length == 0) { ipList.Add(System.Net.IPAddress.Parse("::")); } else { ipList.Add(System.Net.IPAddress.Parse(ipv6)); } return(true); } return(false); }; int ret = Interop.Connection.GetAllIPv6Addresses(GetHandle(), (int)type, callback, IntPtr.Zero); if (ret != (int)ConnectionError.None) { Log.Error(Globals.LogTag, "Failed to get all IPv6 addresses, Error - " + (ConnectionError)ret); ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.telephony " + "http://tizen.org/feature/network.wifi " + "http://tizen.org/feature/network.tethering.bluetooth " + "http://tizen.org/feature/network.ethernet"); ConnectionErrorFactory.CheckHandleNullException(ret, (GetHandle() == IntPtr.Zero), "Connection Handle may have been disposed or released"); ConnectionErrorFactory.ThrowConnectionException(ret); } return(ipList); }
/// <summary> /// Gets the network state. /// </summary> /// <since_tizen> 3 </since_tizen> /// <param name="family">The address family.</param> /// <returns>The network state.</returns> /// <feature>http://tizen.org/feature/network.ethernet</feature> /// <feature>http://tizen.org/feature/network.telephony</feature> /// <feature>http://tizen.org/feature/network.tethering.bluetooth</feature> /// <feature>http://tizen.org/feature/network.wifi</feature> /// <exception cref="System.NotSupportedException">Thrown when a feature is not supported.</exception> /// <exception cref="System.ArgumentException">Thrown when a value is an invalid parameter.</exception> /// <exception cref="System.InvalidOperationException">Thrown when a profile instance is invalid or when a method fails due to an invalid operation.</exception> /// <exception cref="System.ObjectDisposedException">Thrown when an operation is performed on a disposed object.</exception> public ProfileState GetState(AddressFamily family) { CheckDisposed(); int Value; int ret = (int)ConnectionError.None; if (family == AddressFamily.IPv4) { ret = Interop.ConnectionProfile.GetState(ProfileHandle, out Value); } else { ret = Interop.ConnectionProfile.GetIPv6State(ProfileHandle, out Value); } if ((ConnectionError)ret != ConnectionError.None) { Log.Error(Globals.LogTag, "It failed to get profile state, " + (ConnectionError)ret); ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.telephony " + "http://tizen.org/feature/network.wifi " + "http://tizen.org/feature/network.tethering.bluetooth " + "http://tizen.org/feature/network.ethernet"); ConnectionErrorFactory.CheckHandleNullException(ret, (ProfileHandle == IntPtr.Zero), "ProfileHandle may have been disposed or released"); ConnectionErrorFactory.ThrowConnectionException(ret); } return((ProfileState)Value); }
internal Task CloseProfileAsync(ConnectionProfile profile) { Log.Info(Globals.LogTag, "CloseProfileAsync"); if (profile != null) { Log.Info(Globals.LogTag, "CloseProfileAsync " + profile.Name); TaskCompletionSource <bool> task = new TaskCompletionSource <bool>(); IntPtr id; lock (_callback_map) { id = (IntPtr)_requestId++; _callback_map[id] = (error, key) => { Log.Info(Globals.LogTag, "CloseProfileAsync done " + profile.Name); if (error != ConnectionError.None) { Log.Error(Globals.LogTag, "Error occurs during disconnecting profile, " + error); task.SetException(new InvalidOperationException("Error occurs during disconnecting profile, " + error)); } else { task.SetResult(true); } lock (_callback_map) { _callback_map.Remove(key); } }; } context.Post((x) => { Log.Info(Globals.LogTag, "Interop.Connection.CloseProfile " + profile.Name); try { int ret = Interop.Connection.CloseProfile(GetHandle(), profile.ProfileHandle, _callback_map[id], id); if ((ConnectionError)ret != ConnectionError.None) { Log.Error(Globals.LogTag, "It failed to disconnect profile, " + (ConnectionError)ret); ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.telephony " + "http://tizen.org/feature/network.wifi " + "http://tizen.org/feature/network.tethering.bluetooth"); ConnectionErrorFactory.CheckPermissionDeniedException(ret, "(http://tizen.org/privilege/network.set)"); ConnectionErrorFactory.CheckHandleNullException(ret, (GetHandle() == IntPtr.Zero || profile.ProfileHandle == IntPtr.Zero), "Connection or Profile Handle may have been disposed or released"); ConnectionErrorFactory.ThrowConnectionException(ret); } } catch (Exception e) { Log.Error(Globals.LogTag, "Exception on CloseProfile\n" + e.ToString()); task.SetException(e); } }, null); return(task.Task); } else { throw new ArgumentNullException("Profile is null"); } }
internal Task SetDefaultCellularProfile(CellularServiceType type, ConnectionProfile profile) { Log.Info(Globals.LogTag, "SetDefaultCellularProfile"); if (profile != null) { TaskCompletionSource <bool> task = new TaskCompletionSource <bool>(); IntPtr id; lock (_callback_map) { id = (IntPtr)_requestId++; _callback_map[id] = (error, key) => { Log.Info(Globals.LogTag, "SetDefaultCellularProfile done " + profile.Name); if (error != ConnectionError.None) { Log.Error(Globals.LogTag, "Error occurs during set default cellular profile, " + error); task.SetException(new InvalidOperationException("Error occurs during set default cellular profile, " + error)); } else { task.SetResult(true); } lock (_callback_map) { _callback_map.Remove(key); } }; } context.Post((x) => { Log.Info(Globals.LogTag, "Interop.Connection.SetDefaultCellularServiceProfileAsync " + profile.Name); try { int ret = Interop.Connection.SetDefaultCellularServiceProfileAsync(GetHandle(), (int)type, profile.ProfileHandle, _callback_map[id], id); if ((ConnectionError)ret != ConnectionError.None) { Log.Error(Globals.LogTag, "It failed to set default cellular profile, " + (ConnectionError)ret); ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.telephony"); ConnectionErrorFactory.CheckHandleNullException(ret, (GetHandle() == IntPtr.Zero || profile.ProfileHandle == IntPtr.Zero), "Connection or Profile Handle may have been disposed or released"); ConnectionErrorFactory.ThrowConnectionException(ret); } } catch (Exception e) { Log.Error(Globals.LogTag, "Exception on SetDefaultCellularServiceProfileAsync\n" + e.ToString()); task.SetException(e); } }, null); return(task.Task); } else { throw new ArgumentNullException("Profile is null"); } }
public HandleHolder() { Log.Debug(Globals.LogTag, "Handle: " + Handle); int ret = Interop.Connection.Create(out Handle); if (ret != (int)ConnectionError.None) { ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.telephony " + "http://tizen.org/feature/network.wifi " + "http://tizen.org/feature/network.tethering.bluetooth " + "http://tizen.org/feature/network.ethernet"); ConnectionErrorFactory.CheckPermissionDeniedException(ret, "(http://tizen.org/privilege/network.get)"); ConnectionErrorFactory.ThrowConnectionException(ret); } }
public HandleHolder() { _tid = Thread.CurrentThread.ManagedThreadId; Log.Info(Globals.LogTag, "PInvoke connection_create for Thread " + _tid); int ret = Interop.Connection.Create(out Handle); Log.Info(Globals.LogTag, "Handle: " + Handle); if(ret != (int)ConnectionError.None) { ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.telephony " + "http://tizen.org/feature/network.wifi " + "http://tizen.org/feature/network.tethering.bluetooth " + "http://tizen.org/feature/network.ethernet"); ConnectionErrorFactory.CheckPermissionDeniedException(ret, "(http://tizen.org/privilege/network.get)"); ConnectionErrorFactory.ThrowConnectionException(ret); } }
internal void ResetStatistics(ConnectionType connectionType, StatisticsType statisticsType) { Log.Debug(Globals.LogTag, "ResetStatistics " + connectionType + ", " + statisticsType); int ret = Interop.Connection.ResetStatistics(GetHandle(), (int)connectionType, (int)statisticsType); if ((ConnectionError)ret != ConnectionError.None) { Log.Error(Globals.LogTag, "It failed to reset statistics, " + (ConnectionError)ret); ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.wifi " + "http://tizen.org/feature/network.telephony"); ConnectionErrorFactory.CheckPermissionDeniedException(ret, "(http://tizen.org/privilege/network.set)"); ConnectionErrorFactory.CheckHandleNullException(ret, (GetHandle() == IntPtr.Zero), "Connection Handle may have been disposed or released"); ConnectionErrorFactory.ThrowConnectionException(ret); } }
/// <summary> /// Refreshes the profile information. /// </summary> /// <since_tizen> 3 </since_tizen> /// <privilege>http://tizen.org/privilege/network.get</privilege> /// <feature>http://tizen.org/feature/network.ethernet</feature> /// <feature>http://tizen.org/feature/network.telephony</feature> /// <feature>http://tizen.org/feature/network.tethering.bluetooth</feature> /// <feature>http://tizen.org/feature/network.wifi</feature> /// <exception cref="System.NotSupportedException">Thrown when a feature is not supported.</exception> /// <exception cref="System.UnauthorizedAccessException">Thrown when a permission is denied.</exception> /// <exception cref="System.ArgumentException">Thrown when a value is an invalid parameter.</exception> /// <exception cref="System.InvalidOperationException">Thrown when a profile instance is invalid or when a method fails due to an invalid operation.</exception> /// <exception cref="System.ObjectDisposedException">Thrown when an operation is performed on a disposed object.</exception> public void Refresh() { CheckDisposed(); int ret = Interop.ConnectionProfile.Refresh(ProfileHandle); if ((ConnectionError)ret != ConnectionError.None) { Log.Error(Globals.LogTag, "It failed to get network interface name, " + (ConnectionError)ret); ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.telephony " + "http://tizen.org/feature/network.wifi " + "http://tizen.org/feature/network.tethering.bluetooth " + "http://tizen.org/feature/network.ethernet"); ConnectionErrorFactory.CheckPermissionDeniedException(ret, "(http://tizen.org/privilege/network.get)"); ConnectionErrorFactory.CheckHandleNullException(ret, (ProfileHandle == IntPtr.Zero), "ProfileHandle may have been disposed or released"); ConnectionErrorFactory.ThrowConnectionException(ret); } }
internal Task OpenProfileAsync(ConnectionProfile profile) { Log.Info(Globals.LogTag, "OpenProfileAsync"); if (profile != null) { Log.Debug(Globals.LogTag, "OpenProfileAsync " + profile.Name); TaskCompletionSource <bool> task = new TaskCompletionSource <bool>(); Interop.Connection.ConnectionCallback Callback = (ConnectionError Result, IntPtr Data) => { Log.Info(Globals.LogTag, "OpenProfileAsync done " + profile.Name); if (Result != ConnectionError.None) { Log.Error(Globals.LogTag, "Error occurs during connecting profile, " + Result); task.SetException(new InvalidOperationException("Error occurs during connecting profile, " + Result)); } else { task.SetResult(true); } }; context.Post((x) => { Log.Info(Globals.LogTag, "Interop.Connection.OpenProfile " + profile.Name); try { int ret = Interop.Connection.OpenProfile(GetHandle(), profile.ProfileHandle, Callback, IntPtr.Zero); if ((ConnectionError)ret != ConnectionError.None) { Log.Error(Globals.LogTag, "It failed to connect profile, " + (ConnectionError)ret); ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.telephony " + "http://tizen.org/feature/network.wifi " + "http://tizen.org/feature/network.tethering.bluetooth"); ConnectionErrorFactory.CheckHandleNullException(ret, (GetHandle() == IntPtr.Zero || profile.ProfileHandle == IntPtr.Zero), "Connection or Profile Handle may have been disposed or released"); ConnectionErrorFactory.ThrowConnectionException(ret); } } catch (Exception e) { Log.Error(Globals.LogTag, "Exception on OpenProfile\n" + e.ToString()); task.SetException(e); } }, null); return(task.Task); } else { throw new ArgumentNullException("Profile is null"); } }
internal Task <IEnumerable <ConnectionProfile> > GetProfileListAsync(ProfileListType type) { Log.Debug(Globals.LogTag, "GetProfileListAsync"); var task = new TaskCompletionSource <IEnumerable <ConnectionProfile> >(); List <ConnectionProfile> Result = new List <ConnectionProfile>(); IntPtr iterator; int ret = Interop.Connection.GetProfileIterator(GetHandle(), (int)type, out iterator); if ((ConnectionError)ret != ConnectionError.None) { Log.Error(Globals.LogTag, "It failed to get profile iterator, " + (ConnectionError)ret); ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.telephony " + "http://tizen.org/feature/network.wifi " + "http://tizen.org/feature/network.tethering.bluetooth " + "http://tizen.org/feature/network.ethernet"); ConnectionErrorFactory.CheckPermissionDeniedException(ret, "(http://tizen.org/privilege/network.get)"); ConnectionErrorFactory.CheckHandleNullException(ret, (GetHandle() == IntPtr.Zero), "Connection Handle may have been disposed or released"); ConnectionErrorFactory.ThrowConnectionException(ret); } while (Interop.Connection.HasNextProfileIterator(iterator)) { IntPtr nextH; IntPtr profileH; Interop.Connection.GetNextProfileIterator(iterator, out nextH); Interop.ConnectionProfile.Clone(out profileH, nextH); int profileType; Interop.ConnectionProfile.GetType(profileH, out profileType); if ((ConnectionProfileType)profileType == ConnectionProfileType.WiFi) { WiFiProfile cur = new WiFiProfile(profileH); Result.Add(cur); } else if ((ConnectionProfileType)profileType == ConnectionProfileType.Cellular) { CellularProfile cur = new CellularProfile(profileH); Result.Add(cur); } else { ConnectionProfile cur = new ConnectionProfile(profileH); Result.Add(cur); } } Interop.Connection.DestroyProfileIterator(iterator); task.SetResult(Result); return(task.Task); }
internal string GetMacAddress(ConnectionType type) { Log.Info(Globals.LogTag, "GetMacAddress " + type); IntPtr mac; int ret = Interop.Connection.GetMacAddress(GetHandle(), (int)type, out mac); if ((ConnectionError)ret != ConnectionError.None) { Log.Error(Globals.LogTag, "It failed to get mac address, " + (ConnectionError)ret); ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.wifi " + "http://tizen.org/feature/network.ethernet"); ConnectionErrorFactory.CheckHandleNullException(ret, (GetHandle() == IntPtr.Zero), "Connection Handle may have been disposed or released"); ConnectionErrorFactory.ThrowConnectionException(ret); } string result = Marshal.PtrToStringAnsi(mac); Interop.Libc.Free(mac); return result; }
internal string GetProxy(AddressFamily family) { Log.Debug(Globals.LogTag, "GetProxy " + family); IntPtr ip; int ret = Interop.Connection.GetProxy(GetHandle(), (int)family, out ip); if ((ConnectionError)ret != ConnectionError.None) { Log.Error(Globals.LogTag, "It failed to get proxy, " + (ConnectionError)ret); ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.telephony " + "http://tizen.org/feature/network.wifi " + "http://tizen.org/feature/network.tethering.bluetooth " + "http://tizen.org/feature/network.ethernet"); ConnectionErrorFactory.CheckHandleNullException(ret, (GetHandle() == IntPtr.Zero), "Connection Handle may have been disposed or released"); ConnectionErrorFactory.ThrowConnectionException(ret); } string result = Marshal.PtrToStringAnsi(ip); Interop.Libc.Free(ip); return result; }
internal ConnectionProfile GetDefaultCellularProfile(CellularServiceType type) { Log.Debug(Globals.LogTag, "GetDefaultCellularProfile"); IntPtr ProfileHandle; int ret = Interop.Connection.GetDefaultCellularServiceProfile(GetHandle(), (int)type, out ProfileHandle); if ((ConnectionError)ret != ConnectionError.None) { Log.Error(Globals.LogTag, "Error: " + ret); Log.Error(Globals.LogTag, "It failed to get default cellular profile, " + (ConnectionError)ret); ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.telephony"); ConnectionErrorFactory.CheckPermissionDeniedException(ret, "(http://tizen.org/privilege/network.get)"); ConnectionErrorFactory.CheckHandleNullException(ret, (GetHandle() == IntPtr.Zero), "Connection Handle may have been disposed or released"); ConnectionErrorFactory.ThrowConnectionException(ret); } CellularProfile Profile = new CellularProfile(ProfileHandle); return Profile; }
internal void UpdateProfile(ConnectionProfile profile) { Log.Info(Globals.LogTag, "UpdateProfile"); if (profile != null) { int ret = Interop.Connection.UpdateProfile(GetHandle(), profile.ProfileHandle); if ((ConnectionError)ret != ConnectionError.None) { Log.Error(Globals.LogTag, "It failed to update profile, " + (ConnectionError)ret); ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.telephony " + "http://tizen.org/feature/network.wifi " + "http://tizen.org/feature/network.ethernet"); ConnectionErrorFactory.CheckHandleNullException(ret, (GetHandle() == IntPtr.Zero || profile.ProfileHandle == IntPtr.Zero), "Connection or Profile Handle may have been disposed or released"); ConnectionErrorFactory.ThrowConnectionException(ret); } } else { throw new ArgumentNullException("Profile is null"); } }
/// <summary> /// Sets the passphrase of the Wi-Fi WPA. /// </summary> /// <since_tizen> 3 </since_tizen> /// <param name="passphrase">The passphrase of Wi-Fi security.</param> /// <feature>http://tizen.org/feature/network.wifi</feature> /// <exception cref="System.NotSupportedException">Thrown when a feature is not supported.</exception> /// <exception cref="System.ArgumentException">Thrown when a value is an invalid parameter.</exception> /// <exception cref="System.ArgumentNullException">Thrown when a passphrase is null.</exception> /// <exception cref="System.InvalidOperationException">Thrown when a profile instance is invalid or when a method fails due to an invalid operation.</exception> /// <exception cref="System.ObjectDisposedException">Thrown when an operation is performed on a disposed object.</exception> public void SetPassphrase(string passphrase) { CheckDisposed(); if (passphrase != null) { int ret = Interop.ConnectionWiFiProfile.SetPassphrase(ProfileHandle, passphrase); if ((ConnectionError)ret != ConnectionError.None) { Log.Error(Globals.LogTag, "It failed to set passphrase, " + (ConnectionError)ret); ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.wifi"); ConnectionErrorFactory.CheckHandleNullException(ret, (ProfileHandle == IntPtr.Zero), "ProfileHandle may have been disposed or released"); ConnectionErrorFactory.ThrowConnectionException(ret); } } else { throw new ArgumentNullException("Value of passphrase is null"); } }
internal void RemoveRoute(AddressFamily family, string interfaceName, System.Net.IPAddress address, System.Net.IPAddress gateway) { if (interfaceName != null && address != null && gateway != null) { Log.Debug(Globals.LogTag, "RemoveRoute " + family + ", " + interfaceName + ", " + address + ", " + gateway); int ret = Interop.Connection.RemoveRoute(GetHandle(), family, interfaceName, address.ToString(), gateway.ToString()); if ((ConnectionError)ret != ConnectionError.None) { Log.Error(Globals.LogTag, "It failed to remove route from the routing table, " + (ConnectionError)ret); ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.telephony " + "http://tizen.org/feature/network.wifi " + "http://tizen.org/feature/network.tethering.bluetooth " + "http://tizen.org/feature/network.ethernet"); ConnectionErrorFactory.CheckPermissionDeniedException(ret, "(http://tizen.org/privilege/network.set)"); ConnectionErrorFactory.CheckHandleNullException(ret, (GetHandle() == IntPtr.Zero), "Connection Handle may have been disposed or released"); ConnectionErrorFactory.ThrowConnectionException(ret); } } else { throw new ArgumentNullException("Arguments are null"); } }
internal Task CloseProfileAsync(ConnectionProfile profile) { Log.Debug(Globals.LogTag, "CloseProfileAsync"); if (profile != null) { Log.Debug(Globals.LogTag, "CloseProfileAsync " + profile.Name); TaskCompletionSource <bool> task = new TaskCompletionSource <bool>(); Interop.Connection.ConnectionCallback Callback = (ConnectionError Result, IntPtr Data) => { if (Result != ConnectionError.None) { Log.Error(Globals.LogTag, "Error occurs during disconnecting profile, " + Result); task.SetException(new InvalidOperationException("Error occurs during disconnecting profile, " + Result)); } else { task.SetResult(true); } }; int ret = Interop.Connection.CloseProfile(GetHandle(), profile.ProfileHandle, Callback, IntPtr.Zero); if ((ConnectionError)ret != ConnectionError.None) { Log.Error(Globals.LogTag, "It failed to disconnect profile, " + (ConnectionError)ret); ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.telephony " + "http://tizen.org/feature/network.wifi " + "http://tizen.org/feature/network.tethering.bluetooth"); ConnectionErrorFactory.CheckPermissionDeniedException(ret, "(http://tizen.org/privilege/network.set)"); ConnectionErrorFactory.CheckHandleNullException(ret, (GetHandle() == IntPtr.Zero || profile.ProfileHandle == IntPtr.Zero), "Connection or Profile Handle may have been disposed or released"); ConnectionErrorFactory.ThrowConnectionException(ret); } return(task.Task); } else { throw new ArgumentNullException("Profile is null"); } }
internal IntPtr CreateCellularProfile(ConnectionProfileType type, string keyword) { Log.Debug(Globals.LogTag, "CreateCellularProfile, " + type + ", " + keyword); if (keyword != null) { IntPtr handle = IntPtr.Zero; int ret = Interop.ConnectionProfile.Create((int)type, keyword, out handle); if ((ConnectionError)ret != ConnectionError.None) { Log.Error(Globals.LogTag, "It failed to Create profile, " + (ConnectionError)ret); ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.wifi " + "http://tizen.org/feature/network.telephony"); ConnectionErrorFactory.CheckPermissionDeniedException(ret, "(http://tizen.org/privilege/network.get)"); ConnectionErrorFactory.ThrowConnectionException(ret); } return(handle); } else { throw new ArgumentNullException("Keyword is null"); } }
internal Task SetDefaultCellularProfile(CellularServiceType type, ConnectionProfile profile) { Log.Debug(Globals.LogTag, "SetDefaultCellularProfile"); if (profile != null) { TaskCompletionSource <bool> task = new TaskCompletionSource <bool>(); Interop.Connection.ConnectionCallback Callback = (ConnectionError Result, IntPtr Data) => { if (Result != ConnectionError.None) { Log.Error(Globals.LogTag, "Error occurs during set default cellular profile, " + Result); task.SetException(new InvalidOperationException("Error occurs during set default cellular profile, " + Result)); } else { task.SetResult(true); } }; int ret = Interop.Connection.SetDefaultCellularServiceProfileAsync(GetHandle(), (int)type, profile.ProfileHandle, Callback, (IntPtr)0); if ((ConnectionError)ret != ConnectionError.None) { Log.Error(Globals.LogTag, "It failed to set default cellular profile, " + (ConnectionError)ret); ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.telephony"); ConnectionErrorFactory.CheckHandleNullException(ret, (GetHandle() == IntPtr.Zero || profile.ProfileHandle == IntPtr.Zero), "Connection or Profile Handle may have been disposed or released"); ConnectionErrorFactory.ThrowConnectionException(ret); } return(task.Task); } else { throw new ArgumentNullException("Profile is null"); } }