From b76a4fad3dc67dca5a3711ab0a7cd8a3977d0a10 Mon Sep 17 00:00:00 2001 From: chleun-moon <32117100+chleun-moon@users.noreply.github.com> Date: Wed, 18 Jul 2018 08:56:24 +0900 Subject: [PATCH] [TCSACR-160] Add ForgetAPAsync (#332) --- .../Interop/Interop.WiFi.cs | 2 + .../Tizen.Network.WiFi/WiFiAP.cs | 73 +++++++++++++++++++ 2 files changed, 75 insertions(+) diff --git a/src/Tizen.Network.WiFi/Interop/Interop.WiFi.cs b/src/Tizen.Network.WiFi/Interop/Interop.WiFi.cs index c23461d81..448dce8d4 100755 --- a/src/Tizen.Network.WiFi/Interop/Interop.WiFi.cs +++ b/src/Tizen.Network.WiFi/Interop/Interop.WiFi.cs @@ -86,6 +86,8 @@ internal static partial class Interop internal static extern int CancelWps(SafeWiFiManagerHandle wifi); [DllImport(Libraries.WiFi, EntryPoint = "wifi_manager_forget_ap")] internal static extern int RemoveAP(SafeWiFiManagerHandle wifi, IntPtr ap); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_manager_forget_ap_async")] + internal static extern int ForgetAP(SafeWiFiManagerHandle wifi, IntPtr ap, VoidCallback callback, IntPtr userData); [DllImport(Libraries.WiFi, EntryPoint = "wifi_manager_update_ap")] internal static extern int UpdateAP(SafeWiFiManagerHandle wifi, IntPtr ap); diff --git a/src/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiAP.cs b/src/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiAP.cs index 72ecd2b27..b5be8a3b3 100644 --- a/src/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiAP.cs +++ b/src/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiAP.cs @@ -622,6 +622,79 @@ namespace Tizen.Network.WiFi } } + /// + /// Deletes the information of a stored access point and disconnects it when the AP is connected asyncronously. + /// If an AP is connected, then the connection information will be stored. This information is used when a connection to that AP is established automatically. + /// + /// A task indicating whether the disconnect method is done or not. + /// + /// This method must be called from MainThread. + /// + /// 5 + /// http://tizen.org/feature/network.wifi + /// http://tizen.org/privilege/network.profile + /// http://tizen.org/privilege/network.get + /// Thrown when the Wi-Fi is not supported. + /// Thrown when permission is denied. + /// Thrown when the object instance is disposed or released. + /// Thrown when the method failed due to an invalid operation. + public Task ForgetAPAsync() + { + Log.Debug(Globals.LogTag, "ForgetAPAsync"); + if (_disposed) + { + throw new ObjectDisposedException("Invalid AP instance (Object may have been disposed or released)"); + } + TaskCompletionSource task = new TaskCompletionSource(); + IntPtr id; + lock (_callback_map) + { + id = (IntPtr)_requestId++; + _callback_map[id] = (error, key) => + { + Log.Info(Globals.LogTag, "ForgetAPAsync done"); + if (error != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Error occurs during WiFi disconnecting, " + (WiFiError)error); + task.SetException(new InvalidOperationException("Error occurs during WiFi disconnecting, " + (WiFiError)error)); + } + else + { + task.SetResult(true); + } + lock (_callback_map) + { + _callback_map.Remove(key); + } + }; + } + + context.Post((x) => + { + Log.Info(Globals.LogTag, "Interop.WiFi.ForgetAP"); + try + { + int ret = Interop.WiFi.ForgetAP(WiFiManagerImpl.Instance.GetSafeHandle(), _apHandle, _callback_map[id], id); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to forget wifi, Error - " + (WiFiError)ret); + if (ret == (int)WiFiError.InvalidParameterError) + { + throw new InvalidOperationException("Invalid handle"); + } + WiFiErrorFactory.ThrowWiFiException(ret, WiFiManagerImpl.Instance.GetSafeHandle().DangerousGetHandle(), _apHandle); + } + } + catch (Exception e) + { + Log.Error(Globals.LogTag, "Exception on ForgetAPAsync\n" + e.ToString()); + task.SetException(e); + } + }, null); + + return task.Task; + } + /// /// Update the information of a stored access point. /// When a AP information is changed, the change will not be applied until this method is called. -- 2.34.1