[WiFi] Added wifi-manager changes and fix for multi-thread support.
[platform/core/csapi/tizenfx.git] / src / Tizen.Network.WiFi / Tizen.Network.WiFi / WiFiManager.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 using System;
18 using System.Collections.Generic;
19 using System.Threading.Tasks;
20
21 namespace Tizen.Network.WiFi
22 {
23     /// <summary>
24     /// A manager class which allows applications to connect to a Wireless Local Area Network (WLAN) and to transfer data over the network.<br>
25     /// The Wi-Fi Manager enables your application to activate and deactivate a local Wi-Fi device, and to connect to a WLAN network in the infrastructure mode.
26     /// </summary>
27     static public class WiFiManager
28     {
29         /// <summary>
30         /// The local MAC address.
31         /// </summary>
32         static public string MacAddress
33         {
34             get
35             {
36                 return WiFiManagerImpl.Instance.MacAddress;
37             }
38         }
39         /// <summary>
40         /// The name of the network interface.
41         /// </summary>
42         static public string InterfaceName
43         {
44             get
45             {
46                 return WiFiManagerImpl.Instance.InterfaceName;
47             }
48         }
49         /// <summary>
50         /// The networtk connection state.
51         /// </summary>
52         static public WiFiConnectionState ConnectionState
53         {
54             get
55             {
56                 return WiFiManagerImpl.Instance.ConnectionState;
57             }
58         }
59         /// <summary>
60         /// A property to Check whether Wi-Fi is activated.
61         /// </summary>
62         static public bool IsActivated
63         {
64             get
65             {
66                 return WiFiManagerImpl.Instance.IsActivated;
67             }
68         }
69
70         /// <summary>
71         /// (event) DeviceStateChanged is raised when the device state is changed.
72         /// </summary>
73         static public event EventHandler<DeviceStateChangedEventArgs> DeviceStateChanged
74         {
75             add
76             {
77                 WiFiManagerImpl.Instance.DeviceStateChanged += value;
78             }
79             remove
80             {
81                 WiFiManagerImpl.Instance.DeviceStateChanged -= value;
82             }
83         }
84         /// <summary>
85         /// (event) ConnectionStateChanged is rasied when the connection state is changed.
86         /// </summary>
87         static public event EventHandler<ConnectionStateChangedEventArgs> ConnectionStateChanged
88         {
89             add
90             {
91                 WiFiManagerImpl.Instance.ConnectionStateChanged += value;
92             }
93             remove
94             {
95                 WiFiManagerImpl.Instance.ConnectionStateChanged -= value;
96             }
97         }
98         /// <summary>
99         /// (event) RssiLevelChanged is rasied when the RSSI of connected Wi-Fi is changed.
100         /// </summary>
101         static public event EventHandler<RssiLevelChangedEventArgs> RssiLevelChanged
102         {
103             add
104             {
105                 WiFiManagerImpl.Instance.RssiLevelChanged += value;
106             }
107             remove
108             {
109                 WiFiManagerImpl.Instance.RssiLevelChanged -= value;
110             }
111         }
112         /// <summary>
113         /// (event) BackgroundScanFinished is rasied when the background scan is finished.
114         /// The background scan starts automatically when wifi is activated. The callback will be invoked periodically.
115         /// </summary>
116         static public event EventHandler BackgroundScanFinished
117         {
118             add
119             {
120                 WiFiManagerImpl.Instance.BackgroundScanFinished += value;
121             }
122             remove
123             {
124                 WiFiManagerImpl.Instance.BackgroundScanFinished -= value;
125             }
126         }
127         /// <summary>
128         /// Gets the result of the scan asynchronously.
129         /// </summary>
130         /// <returns> A task contains the lisf for WiFiApInformation objects.</returns>
131         static public IEnumerable<WiFiAp> GetFoundAps()
132         {
133             return WiFiManagerImpl.Instance.GetFoundAps();
134         }
135         /// <summary>
136         /// Gets the result of specific ap scan asynchronously.
137         /// </summary>
138         /// <returns> A task contains the WiFiApInformation object.</returns>
139         static public IEnumerable<WiFiAp> GetFoundSpecificAps()
140         {
141             return WiFiManagerImpl.Instance.GetFoundSpecificAps();
142         }
143         /// <summary>
144         /// Gets the list of wifi configuration.
145         /// </summary>
146         /// <returns>A task contains the lisf for WiFiConfiguration objects.</returns>
147         static public IEnumerable<WiFiConfiguration> GetWiFiConfigurations()
148         {
149             return WiFiManagerImpl.Instance.GetWiFiConfigurations();
150         }
151         /// <summary>
152         /// Saves Wi-Fi configuration of access point.
153         /// </summary>
154         /// <param name="configuration">The configuration to be stored</param>
155         static public void SaveWiFiNetworkConfiguration(WiFiConfiguration configuration)
156         {
157             WiFiManagerImpl.Instance.SaveWiFiNetworkConfiguration(configuration);
158         }
159         /// <summary>
160         /// Gets the handle of the connected access point.
161         /// </summary>
162         /// <returns> The connected wifi access point(AP) information.</returns>
163         static public WiFiAp GetConnectedAp()
164         {
165             return WiFiManagerImpl.Instance.GetConnectedAp();
166         }
167         /// <summary>
168         /// Deletes the information of stored access point and disconnects it when it connected.<br>
169         /// If an AP is connected, then connection information will be stored. This information is used when a connection to that AP is established automatically.
170         /// </summary>
171         /// <param name="ap">The access point to be removed</param>
172         static public void RemoveAP(WiFiAp ap)
173         {
174             WiFiManagerImpl.Instance.RemoveAp(ap);
175         }
176         /// <summary>
177         /// Activates Wi-Fi asynchronously.
178         /// </summary>
179         /// <returns> A task indicates whether the Activate method is done or not.</returns>
180         static public Task ActivateAsync()
181         {
182             return WiFiManagerImpl.Instance.ActivateAsync();
183         }
184         /// <summary>
185         /// Activates Wi-Fi asynchronously and displays Wi-Fi picker (popup) when Wi-Fi is not automatically connected.
186         /// </summary>
187         /// <returns> A task indicates whether the ActivateWithPickerTeated method is done or not.</returns>
188         static public Task ActivateWithPickerTeatedAsync()
189         {
190             return WiFiManagerImpl.Instance.ActivateWithWiFiPickerTestedAsync();
191         }
192         /// <summary>
193         /// Deactivates Wi-Fi asynchronously.
194         /// </summary>
195         /// <returns> A task indicates whether the Deactivate method is done or not.</returns>
196         static public Task DeactivateAsync()
197         {
198             return WiFiManagerImpl.Instance.DeactivateAsync();
199         }
200         /// <summary>
201         /// Starts scan asynchronously.
202         /// </summary>
203         /// <returns> A task indicates whether the Scan method is done or not.</returns>
204         static public Task ScanAsync()
205         {
206             return WiFiManagerImpl.Instance.ScanAsync();
207         }
208         /// <summary>
209         /// Starts specific ap scan, asynchronously.
210         /// </summary>
211         /// <returns> A task contains WiFiApInformation object.</returns>
212         /// <param name="essid">The essid of hidden ap</param>
213         static public Task ScanSpecificApAsync(string essid)
214         {
215             return WiFiManagerImpl.Instance.ScanSpecificApAsync(essid);
216         }
217         /// <summary>
218         /// Connects the access point asynchronously.
219         /// </summary>
220         /// <param name="ap">The access point</param>
221         /// <returns> A task indicates whether the Connect method is done or not.</returns>
222         static public Task ConnectAsync(WiFiAp ap)
223         {
224             return WiFiManagerImpl.Instance.ConnectAsync(ap);
225         }
226         /// <summary>
227         /// Connects the access point with WPS PBC asynchronously.
228         /// </summary>
229         /// <returns> A task indicates whether the ConnectByWpsPbs method is done or not.</returns>
230         /// <param name="ap">The access point(AP)</param>
231         static public Task ConnectByWpsPbcAsync(WiFiAp ap)
232         {
233             return WiFiManagerImpl.Instance.ConnectByWpsPbcAsync(ap);
234         }
235         /// <summary>
236         /// Connects the access point with WPS PIN asynchronously.
237         /// </summary>
238         /// <returns> A task indicates whether the ConnectByWpsPin method is done or not.</returns>
239         /// <param name="ap">The access point(AP)</param>
240         /// <param name="pin">The WPS PIN is a non-NULL string with length greater than 0 and less than or equal to 8.</param>
241         static public Task ConnectByWpsPinAsync(WiFiAp ap, string pin)
242         {
243             Log.Debug(Globals.LogTag, "ConnectByWpsPinAsync");
244             return WiFiManagerImpl.Instance.ConnectByWpsPinAsync(ap, pin);
245         }
246         /// <summary>
247         /// Disconnects the access point asynchronously.
248         /// </summary>
249         /// <returns> A task indicates whether the Disconnect method is done or not.</returns>
250         static public Task DisconnectAsync(WiFiAp ap)
251         {
252             return WiFiManagerImpl.Instance.DisconnectAsync(ap);
253         }
254     }
255 }