[WiFi][TCSACR-155] Remove ArgumentException descriptions (#323)
[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.Runtime.InteropServices;
20 using System.Threading.Tasks;
21 using System.ComponentModel;
22
23 namespace Tizen.Network.WiFi
24 {
25     /// <summary>
26     /// A class for managing the WiFiManager handle.
27     /// </summary>
28     /// <since_tizen> 3 </since_tizen>
29     [EditorBrowsable(EditorBrowsableState.Never)]
30     public sealed class SafeWiFiManagerHandle : SafeHandle
31     {
32         private int _tid;
33
34         internal SafeWiFiManagerHandle() : base(IntPtr.Zero, true)
35         {
36         }
37
38         /// <summary>
39         /// Checks the validity of the handle.
40         /// </summary>
41         /// <value>Represents the validity of the handle.</value>
42         /// <since_tizen> 3 </since_tizen>
43         public override bool IsInvalid
44         {
45             get
46             {
47                 return this.handle == IntPtr.Zero;
48             }
49         }
50
51         /// <summary>
52         /// Release the handle
53         /// </summary>
54         protected override bool ReleaseHandle()
55         {
56             Interop.WiFi.Deinitialize(_tid, this.handle);
57             this.SetHandle(IntPtr.Zero);
58             return true;
59         }
60
61         internal void SetTID(int id)
62         {
63             _tid = id;
64             Log.Info(Globals.LogTag, "New Handle for Thread " + _tid);
65         }
66     }
67
68     /// <summary>
69     /// A manager class which allows applications to connect to a Wireless Local Area Network (WLAN) and transfer data over the network.
70     /// 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.
71     /// </summary>
72     /// <since_tizen> 3 </since_tizen>
73     static public class WiFiManager
74     {
75         /// <summary>
76         /// The local MAC address.
77         /// </summary>
78         /// <since_tizen> 3 </since_tizen>
79         /// <value>Represents the MAC address of the Wi-Fi.</value>
80         /// <privilege>http://tizen.org/privilege/network.get</privilege>
81         static public string MacAddress
82         {
83             get
84             {
85                 return WiFiManagerImpl.Instance.MacAddress;
86             }
87         }
88
89         /// <summary>
90         /// The name of the network interface.
91         /// </summary>
92         /// <since_tizen> 3 </since_tizen>
93         /// <value>Interface name of the Wi-Fi.</value>
94         /// <privilege>http://tizen.org/privilege/network.get</privilege>
95         static public string InterfaceName
96         {
97             get
98             {
99                 return WiFiManagerImpl.Instance.InterfaceName;
100             }
101         }
102
103         /// <summary>
104         /// The network connection state.
105         /// </summary>
106         /// <since_tizen> 3 </since_tizen>
107         /// <value>Represents the connection state of the Wi-Fi.</value>
108         /// <privilege>http://tizen.org/privilege/network.get</privilege>
109         static public WiFiConnectionState ConnectionState
110         {
111             get
112             {
113                 return WiFiManagerImpl.Instance.ConnectionState;
114             }
115         }
116
117         /// <summary>
118         /// A property to check whether Wi-Fi is activated.
119         /// </summary>
120         /// <since_tizen> 3 </since_tizen>
121         /// <value>Boolean value to check whether Wi-Fi is activated or not.</value>
122         /// <privilege>http://tizen.org/privilege/network.get</privilege>
123         static public bool IsActive
124         {
125             get
126             {
127                 return WiFiManagerImpl.Instance.IsActive;
128             }
129         }
130
131         /// <summary>
132         /// DeviceStateChanged is raised when the device state is changed.
133         /// </summary>
134         /// <since_tizen> 3 </since_tizen>
135         /// <privilege>http://tizen.org/privilege/network.get</privilege>
136         /// <feature>http://tizen.org/feature/network.wifi</feature>
137         static public event EventHandler<DeviceStateChangedEventArgs> DeviceStateChanged
138         {
139             add
140             {
141                 WiFiManagerImpl.Instance.DeviceStateChanged += value;
142             }
143             remove
144             {
145                 WiFiManagerImpl.Instance.DeviceStateChanged -= value;
146             }
147         }
148
149         /// <summary>
150         /// ConnectionStateChanged is raised when the connection state is changed.
151         /// </summary>
152         /// <since_tizen> 3 </since_tizen>
153         /// <privilege>http://tizen.org/privilege/network.get</privilege>
154         /// <feature>http://tizen.org/feature/network.wifi</feature>
155         static public event EventHandler<ConnectionStateChangedEventArgs> ConnectionStateChanged
156         {
157             add
158             {
159                 WiFiManagerImpl.Instance.ConnectionStateChanged += value;
160             }
161             remove
162             {
163                 WiFiManagerImpl.Instance.ConnectionStateChanged -= value;
164             }
165         }
166
167         /// <summary>
168         /// RssiLevelChanged is raised when the RSSI of the connected Wi-Fi is changed.
169         /// </summary>
170         /// <since_tizen> 3 </since_tizen>
171         /// <privilege>http://tizen.org/privilege/network.get</privilege>
172         /// <feature>http://tizen.org/feature/network.wifi</feature>
173         static public event EventHandler<RssiLevelChangedEventArgs> RssiLevelChanged
174         {
175             add
176             {
177                 WiFiManagerImpl.Instance.RssiLevelChanged += value;
178             }
179             remove
180             {
181                 WiFiManagerImpl.Instance.RssiLevelChanged -= value;
182             }
183         }
184
185         /// <summary>
186         /// BackgroundScanFinished is raised when the background scan is finished.
187         /// The background scan starts automatically when Wi-Fi is activated. The callback will be invoked periodically.
188         /// </summary>
189         /// <since_tizen> 3 </since_tizen>
190         /// <privilege>http://tizen.org/privilege/network.get</privilege>
191         /// <feature>http://tizen.org/feature/network.wifi</feature>
192         static public event EventHandler BackgroundScanFinished
193         {
194             add
195             {
196                 WiFiManagerImpl.Instance.BackgroundScanFinished += value;
197             }
198             remove
199             {
200                 WiFiManagerImpl.Instance.BackgroundScanFinished -= value;
201             }
202         }
203
204         /// <summary>
205         /// Gets the Wi-Fi safe handle.
206         /// </summary>
207         /// <since_tizen> 3 </since_tizen>
208         /// <returns>The instance of the SafeWiFiManagerHandle.</returns>
209         /// <feature>http://tizen.org/feature/network.wifi</feature>
210         /// <privilege>http://tizen.org/privilege/network.get</privilege>
211         /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
212         /// <exception cref="UnauthorizedAccessException">Thrown when the permission is denied.</exception>
213         /// <exception cref="OutOfMemoryException">Thrown when the system is out of memory.</exception>
214         /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
215         [EditorBrowsable(EditorBrowsableState.Never)]
216         public static SafeWiFiManagerHandle GetWiFiHandle()
217         {
218             return WiFiManagerImpl.Instance.GetSafeHandle();
219         }
220
221         /// <summary>
222         /// Gets the result of the scan.
223         /// </summary>
224         /// <since_tizen> 3 </since_tizen>
225         /// <returns>A list of the WiFiAP objects.</returns>
226         /// <feature>http://tizen.org/feature/network.wifi</feature>
227         /// <privilege>http://tizen.org/privilege/network.get</privilege>
228         /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
229         /// <exception cref="UnauthorizedAccessException">Thrown when the permission is denied.</exception>
230         /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
231         static public IEnumerable<WiFiAP> GetFoundAPs()
232         {
233             return WiFiManagerImpl.Instance.GetFoundAPs();
234         }
235
236         /// <summary>
237         /// Gets the result of ScanSpecificAPAsync(string essid) API.
238         /// </summary>
239         /// <since_tizen> 3 </since_tizen>
240         /// <returns>A list containing the WiFiAP objects.</returns>
241         /// <feature>http://tizen.org/feature/network.wifi</feature>
242         /// <privilege>http://tizen.org/privilege/network.get</privilege>
243         /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
244         /// <exception cref="UnauthorizedAccessException">Thrown when the permission is denied.</exception>
245         /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
246         static public IEnumerable<WiFiAP> GetFoundSpecificAPs()
247         {
248             return WiFiManagerImpl.Instance.GetFoundSpecificAPs();
249         }
250
251         /// <summary>
252         /// Gets the result of the BssidScanAsync() API.
253         /// </summary>
254         /// <since_tizen> 5 </since_tizen>
255         /// <returns>A list of the WiFiAP objects.</returns>
256         /// <feature>http://tizen.org/feature/network.wifi</feature>
257         /// <privilege>http://tizen.org/privilege/network.get</privilege>
258         /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
259         /// <exception cref="UnauthorizedAccessException">Thrown when the permission is denied.</exception>
260         /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
261         static public IEnumerable<WiFiAP> GetFoundBssids()
262         {
263             return WiFiManagerImpl.Instance.GetFoundBssids();
264         }
265
266         /// <summary>
267         /// Gets the list of Wi-Fi configurations.
268         /// </summary>
269         /// <since_tizen> 3 </since_tizen>
270         /// <returns>A list containing the WiFiConfiguration objects.</returns>
271         /// <feature>http://tizen.org/feature/network.wifi</feature>
272         /// <privilege>http://tizen.org/privilege/network.profile</privilege>
273         /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
274         /// <exception cref="UnauthorizedAccessException">Thrown when the permission is denied.</exception>
275         /// <exception cref="OutOfMemoryException">Thrown when system is out of memory.</exception>
276         /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
277         static public IEnumerable<WiFiConfiguration> GetWiFiConfigurations()
278         {
279             return WiFiManagerImpl.Instance.GetWiFiConfigurations();
280         }
281
282         /// <summary>
283         /// Saves the Wi-Fi configuration of the access point.
284         /// </summary>
285         /// <since_tizen> 3 </since_tizen>
286         /// <param name="configuration">The configuration to be stored.</param>
287         /// <feature>http://tizen.org/feature/network.wifi</feature>
288         /// <privilege>http://tizen.org/privilege/network.profile</privilege>
289         /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
290         /// <exception cref="UnauthorizedAccessException">Thrown when the permission is denied.</exception>
291         /// <exception cref="ArgumentNullException">Thrown when WiFiConfiguration is passed as null.</exception>
292         /// <exception cref="ArgumentException">Thrown when the method failed due to an invalid parameter.</exception>
293         /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
294         static public void SaveWiFiConfiguration(WiFiConfiguration configuration)
295         {
296             WiFiManagerImpl.Instance.SaveWiFiNetworkConfiguration(configuration);
297         }
298
299         /// <summary>
300         /// Gets the object of the connected WiFiAP.
301         /// </summary>
302         /// <since_tizen> 3 </since_tizen>
303         /// <returns>The connected Wi-Fi access point (AP) information.</returns>
304         /// <feature>http://tizen.org/feature/network.wifi</feature>
305         /// <privilege>http://tizen.org/privilege/network.get</privilege>
306         /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
307         /// <exception cref="UnauthorizedAccessException">Thrown when the permission is denied.</exception>
308         /// <exception cref="OutOfMemoryException">Thrown when system is out of memory.</exception>
309         /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
310         static public WiFiAP GetConnectedAP()
311         {
312             return WiFiManagerImpl.Instance.GetConnectedAP();
313         }
314
315         /// <summary>
316         /// Activates the Wi-Fi asynchronously.
317         /// </summary>
318         /// <since_tizen> 3 </since_tizen>
319         /// <returns> A task indicating whether the activate method is done or not.</returns>
320         /// <feature>http://tizen.org/feature/network.wifi</feature>
321         /// <privilege>http://tizen.org/privilege/network.set</privilege>
322         /// <privilege>http://tizen.org/privilege/network.get</privilege>
323         /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
324         /// <exception cref="UnauthorizedAccessException">Thrown when the permission is denied.</exception>
325         /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
326         static public Task ActivateAsync()
327         {
328             return WiFiManagerImpl.Instance.ActivateAsync();
329         }
330
331         /// <summary>
332         /// Activates the Wi-Fi asynchronously and displays the Wi-Fi picker (popup) when the Wi-Fi is not automatically connected.
333         /// </summary>
334         /// <since_tizen> 3 </since_tizen>
335         /// <returns>A task indicating whether the ActivateWithPicker method is done or not.</returns>
336         /// <feature>http://tizen.org/feature/network.wifi</feature>
337         /// <privilege>http://tizen.org/privilege/network.set</privilege>
338         /// <privilege>http://tizen.org/privilege/network.get</privilege>
339         /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
340         /// <exception cref="UnauthorizedAccessException">Thrown when the permission is denied.</exception>
341         /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
342         static public Task ActivateWithPickerAsync()
343         {
344             return WiFiManagerImpl.Instance.ActivateWithWiFiPickerTestedAsync();
345         }
346
347         /// <summary>
348         /// Deactivates the Wi-Fi asynchronously.
349         /// </summary>
350         /// <since_tizen> 3 </since_tizen>
351         /// <returns>A task indicating whether the deactivate method is done or not.</returns>
352         /// <feature>http://tizen.org/feature/network.wifi</feature>
353         /// <privilege>http://tizen.org/privilege/network.set</privilege>
354         /// <privilege>http://tizen.org/privilege/network.get</privilege>
355         /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
356         /// <exception cref="UnauthorizedAccessException">Thrown when the permission is denied.</exception>
357         /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
358         static public Task DeactivateAsync()
359         {
360             return WiFiManagerImpl.Instance.DeactivateAsync();
361         }
362
363         /// <summary>
364         /// Starts the scan asynchronously.
365         /// </summary>
366         /// <since_tizen> 3 </since_tizen>
367         /// <returns>A task indicating whether the scan method is done or not.</returns>
368         /// <feature>http://tizen.org/feature/network.wifi</feature>
369         /// <privilege>http://tizen.org/privilege/network.set</privilege>
370         /// <privilege>http://tizen.org/privilege/network.get</privilege>
371         /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
372         /// <exception cref="UnauthorizedAccessException">Thrown when the permission is denied.</exception>
373         /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
374         static public Task ScanAsync()
375         {
376             return WiFiManagerImpl.Instance.ScanAsync();
377         }
378
379         /// <summary>
380         /// Starts a specific access point scan asynchronously.
381         /// </summary>
382         /// <since_tizen> 3 </since_tizen>
383         /// <returns>A task indicating whether the ScanSpecificAP method is done or not.</returns>
384         /// <param name="essid">The ESSID of the hidden AP.</param>
385         /// <feature>http://tizen.org/feature/network.wifi</feature>
386         /// <privilege>http://tizen.org/privilege/network.set</privilege>
387         /// <privilege>http://tizen.org/privilege/network.get</privilege>
388         /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
389         /// <exception cref="UnauthorizedAccessException">Thrown when the permission is denied.</exception>
390         /// <exception cref="ArgumentException">Thrown when the method failed due to an invalid parameter.</exception>
391         /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
392         static public Task ScanSpecificAPAsync(string essid)
393         {
394             return WiFiManagerImpl.Instance.ScanSpecificAPAsync(essid);
395         }
396
397         /// <summary>
398         /// Starts BSSID scan asynchronously.
399         /// </summary>
400         /// <remarks>
401         /// This method must be called from MainThread.
402         /// </remarks>
403         /// <since_tizen> 5 </since_tizen>
404         /// <returns>A task indicating whether the BssidScanAsync method is done or not.</returns>
405         /// <feature>http://tizen.org/feature/network.wifi</feature>
406         /// <privilege>http://tizen.org/privilege/network.set</privilege>
407         /// <privilege>http://tizen.org/privilege/network.get</privilege>
408         /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
409         /// <exception cref="UnauthorizedAccessException">Thrown when the permission is denied.</exception>
410         /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
411         static public Task BssidScanAsync()
412         {
413             return WiFiManagerImpl.Instance.BssidScanAsync();
414         }
415     }
416 }