2 * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 using System.Collections.Generic;
19 using System.Runtime.InteropServices;
20 using System.Threading.Tasks;
21 using System.ComponentModel;
23 namespace Tizen.Network.WiFi
26 /// A class for managing the WiFiManager handle.
28 /// <since_tizen> 3 </since_tizen>
29 [EditorBrowsable(EditorBrowsableState.Never)]
30 public sealed class SafeWiFiManagerHandle : SafeHandle
34 internal SafeWiFiManagerHandle() : base(IntPtr.Zero, true)
39 /// Checks the validity of the handle.
41 /// <value>Represents the validity of the handle.</value>
42 /// <since_tizen> 3 </since_tizen>
43 public override bool IsInvalid
47 return this.handle == IntPtr.Zero;
52 /// Release the handle
54 protected override bool ReleaseHandle()
56 Interop.WiFi.Deinitialize(_tid, this.handle);
57 this.SetHandle(IntPtr.Zero);
61 internal void SetTID(int id)
64 Log.Info(Globals.LogTag, "New Handle for Thread " + _tid);
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.
72 /// <since_tizen> 3 </since_tizen>
73 static public class WiFiManager
76 /// The local MAC address.
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
85 return WiFiManagerImpl.Instance.MacAddress;
90 /// The name of the network interface.
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
99 return WiFiManagerImpl.Instance.InterfaceName;
104 /// The network connection state.
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
113 return WiFiManagerImpl.Instance.ConnectionState;
118 /// A property to check whether Wi-Fi is activated.
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
127 return WiFiManagerImpl.Instance.IsActive;
132 /// The Wi-Fi scan state.
134 /// <since_tizen> 6 </since_tizen>
135 /// <value>Represents the scan state of the Wi-Fi.</value>
136 static public WiFiScanState ScanState
140 return WiFiManagerImpl.Instance.ScanState;
145 /// DeviceStateChanged is raised when the device state is changed.
147 /// <since_tizen> 3 </since_tizen>
148 /// <privilege>http://tizen.org/privilege/network.get</privilege>
149 /// <feature>http://tizen.org/feature/network.wifi</feature>
150 static public event EventHandler<DeviceStateChangedEventArgs> DeviceStateChanged
154 WiFiManagerImpl.Instance.DeviceStateChanged += value;
158 WiFiManagerImpl.Instance.DeviceStateChanged -= value;
163 /// ConnectionStateChanged is raised when the connection state is changed.
165 /// <since_tizen> 3 </since_tizen>
166 /// <privilege>http://tizen.org/privilege/network.get</privilege>
167 /// <feature>http://tizen.org/feature/network.wifi</feature>
168 static public event EventHandler<ConnectionStateChangedEventArgs> ConnectionStateChanged
172 WiFiManagerImpl.Instance.ConnectionStateChanged += value;
176 WiFiManagerImpl.Instance.ConnectionStateChanged -= value;
181 /// RssiLevelChanged is raised when the RSSI of the connected Wi-Fi is changed.
183 /// <since_tizen> 3 </since_tizen>
184 /// <privilege>http://tizen.org/privilege/network.get</privilege>
185 /// <feature>http://tizen.org/feature/network.wifi</feature>
186 static public event EventHandler<RssiLevelChangedEventArgs> RssiLevelChanged
190 WiFiManagerImpl.Instance.RssiLevelChanged += value;
194 WiFiManagerImpl.Instance.RssiLevelChanged -= value;
199 /// BackgroundScanFinished is raised when the background scan is finished.
200 /// The background scan starts automatically when Wi-Fi is activated. The callback will be invoked periodically.
202 /// <since_tizen> 3 </since_tizen>
203 /// <privilege>http://tizen.org/privilege/network.get</privilege>
204 /// <feature>http://tizen.org/feature/network.wifi</feature>
205 static public event EventHandler BackgroundScanFinished
209 WiFiManagerImpl.Instance.BackgroundScanFinished += value;
213 WiFiManagerImpl.Instance.BackgroundScanFinished -= value;
218 /// ScanStateChanged is raised when the scan state is changed.
220 /// <since_tizen> 6 </since_tizen>
221 /// <feature>http://tizen.org/feature/network.wifi</feature>
222 static public event EventHandler<ScanStateChangedEventArgs> ScanStateChanged
226 WiFiManagerImpl.Instance.ScanStateChanged += value;
230 WiFiManagerImpl.Instance.ScanStateChanged -= value;
235 /// Gets the Wi-Fi safe handle.
237 /// <since_tizen> 3 </since_tizen>
238 /// <returns>The instance of the SafeWiFiManagerHandle.</returns>
239 /// <feature>http://tizen.org/feature/network.wifi</feature>
240 /// <privilege>http://tizen.org/privilege/network.get</privilege>
241 /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
242 /// <exception cref="UnauthorizedAccessException">Thrown when the permission is denied.</exception>
243 /// <exception cref="OutOfMemoryException">Thrown when the system is out of memory.</exception>
244 /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
245 [EditorBrowsable(EditorBrowsableState.Never)]
246 public static SafeWiFiManagerHandle GetWiFiHandle()
248 return WiFiManagerImpl.Instance.GetSafeHandle();
252 /// Gets the result of the scan.
254 /// <since_tizen> 3 </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> GetFoundAPs()
263 return WiFiManagerImpl.Instance.GetFoundAPs();
267 /// Gets the result of ScanSpecificAPAsync(string essid) API.
269 /// <since_tizen> 3 </since_tizen>
270 /// <returns>A list containing the WiFiAP objects.</returns>
271 /// <feature>http://tizen.org/feature/network.wifi</feature>
272 /// <privilege>http://tizen.org/privilege/network.get</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="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
276 static public IEnumerable<WiFiAP> GetFoundSpecificAPs()
278 return WiFiManagerImpl.Instance.GetFoundSpecificAPs();
282 /// Gets the result of the BssidScanAsync() API.
284 /// <since_tizen> 5 </since_tizen>
285 /// <returns>A list of the WiFiAP objects.</returns>
286 /// <feature>http://tizen.org/feature/network.wifi</feature>
287 /// <privilege>http://tizen.org/privilege/network.get</privilege>
288 /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
289 /// <exception cref="UnauthorizedAccessException">Thrown when the permission is denied.</exception>
290 /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
291 static public IEnumerable<WiFiAP> GetFoundBssids()
293 return WiFiManagerImpl.Instance.GetFoundBssids();
297 /// Gets the list of Wi-Fi configurations.
299 /// <since_tizen> 3 </since_tizen>
300 /// <returns>A list containing the WiFiConfiguration objects.</returns>
301 /// <feature>http://tizen.org/feature/network.wifi</feature>
302 /// <privilege>http://tizen.org/privilege/network.profile</privilege>
303 /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
304 /// <exception cref="UnauthorizedAccessException">Thrown when the permission is denied.</exception>
305 /// <exception cref="OutOfMemoryException">Thrown when system is out of memory.</exception>
306 /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
307 static public IEnumerable<WiFiConfiguration> GetWiFiConfigurations()
309 return WiFiManagerImpl.Instance.GetWiFiConfigurations();
313 /// Saves the Wi-Fi configuration of the access point.
315 /// <since_tizen> 3 </since_tizen>
316 /// <param name="configuration">The configuration to be stored.</param>
317 /// <feature>http://tizen.org/feature/network.wifi</feature>
318 /// <privilege>http://tizen.org/privilege/network.profile</privilege>
319 /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
320 /// <exception cref="UnauthorizedAccessException">Thrown when the permission is denied.</exception>
321 /// <exception cref="ArgumentNullException">Thrown when WiFiConfiguration is passed as null.</exception>
322 /// <exception cref="ArgumentException">Thrown when the method failed due to an invalid parameter.</exception>
323 /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
324 static public void SaveWiFiConfiguration(WiFiConfiguration configuration)
326 WiFiManagerImpl.Instance.SaveWiFiNetworkConfiguration(configuration);
330 /// Gets the object of the connected WiFiAP.
332 /// <since_tizen> 3 </since_tizen>
333 /// <returns>The connected Wi-Fi access point (AP) information.</returns>
334 /// <feature>http://tizen.org/feature/network.wifi</feature>
335 /// <privilege>http://tizen.org/privilege/network.get</privilege>
336 /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
337 /// <exception cref="UnauthorizedAccessException">Thrown when the permission is denied.</exception>
338 /// <exception cref="OutOfMemoryException">Thrown when system is out of memory.</exception>
339 /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
340 static public WiFiAP GetConnectedAP()
342 return WiFiManagerImpl.Instance.GetConnectedAP();
346 /// Activates the Wi-Fi asynchronously.
348 /// <since_tizen> 3 </since_tizen>
349 /// <returns> A task indicating whether the activate method is done or not.</returns>
350 /// <feature>http://tizen.org/feature/network.wifi</feature>
351 /// <privilege>http://tizen.org/privilege/network.set</privilege>
352 /// <privilege>http://tizen.org/privilege/network.get</privilege>
353 /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
354 /// <exception cref="NowInProgressException">Thrown when the Wi-Fi activation is now in progress.</exception>
355 /// <exception cref="UnauthorizedAccessException">Thrown when the permission is denied.</exception>
356 /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
357 static public Task ActivateAsync()
359 return WiFiManagerImpl.Instance.ActivateAsync();
363 /// Activates the Wi-Fi asynchronously and displays the Wi-Fi picker (popup) when the Wi-Fi is not automatically connected.
365 /// <since_tizen> 3 </since_tizen>
366 /// <returns>A task indicating whether the ActivateWithPicker method is done or not.</returns>
367 /// <feature>http://tizen.org/feature/network.wifi</feature>
368 /// <privilege>http://tizen.org/privilege/network.set</privilege>
369 /// <privilege>http://tizen.org/privilege/network.get</privilege>
370 /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
371 /// <exception cref="NowInProgressException">Thrown when the Wi-Fi activation is now in progress.</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 ActivateWithPickerAsync()
376 return WiFiManagerImpl.Instance.ActivateWithWiFiPickerTestedAsync();
380 /// Deactivates the Wi-Fi asynchronously.
382 /// <since_tizen> 3 </since_tizen>
383 /// <returns>A task indicating whether the deactivate method is done or not.</returns>
384 /// <feature>http://tizen.org/feature/network.wifi</feature>
385 /// <privilege>http://tizen.org/privilege/network.set</privilege>
386 /// <privilege>http://tizen.org/privilege/network.get</privilege>
387 /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
388 /// <exception cref="NowInProgressException">Thrown when the Wi-Fi deactivation is now in progress.</exception>
389 /// <exception cref="UnauthorizedAccessException">Thrown when the permission is denied.</exception>
390 /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
391 static public Task DeactivateAsync()
393 return WiFiManagerImpl.Instance.DeactivateAsync();
397 /// Starts the scan asynchronously.
399 /// <since_tizen> 3 </since_tizen>
400 /// <returns>A task indicating whether the scan method is done or not.</returns>
401 /// <feature>http://tizen.org/feature/network.wifi</feature>
402 /// <privilege>http://tizen.org/privilege/network.set</privilege>
403 /// <privilege>http://tizen.org/privilege/network.get</privilege>
404 /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
405 /// <exception cref="UnauthorizedAccessException">Thrown when the permission is denied.</exception>
406 /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
407 static public Task ScanAsync()
409 return WiFiManagerImpl.Instance.ScanAsync();
413 /// Starts a specific access point scan asynchronously.
415 /// <since_tizen> 3 </since_tizen>
416 /// <returns>A task indicating whether the ScanSpecificAP method is done or not.</returns>
417 /// <param name="essid">The ESSID of the hidden AP.</param>
418 /// <feature>http://tizen.org/feature/network.wifi</feature>
419 /// <privilege>http://tizen.org/privilege/network.set</privilege>
420 /// <privilege>http://tizen.org/privilege/network.get</privilege>
421 /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
422 /// <exception cref="UnauthorizedAccessException">Thrown when the permission is denied.</exception>
423 /// <exception cref="ArgumentException">Thrown when the method failed due to an invalid parameter.</exception>
424 /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
425 static public Task ScanSpecificAPAsync(string essid)
427 return WiFiManagerImpl.Instance.ScanSpecificAPAsync(essid);
431 /// Starts BSSID scan asynchronously.
434 /// This method must be called from MainThread.
436 /// <since_tizen> 5 </since_tizen>
437 /// <returns>A task indicating whether the BssidScanAsync method is done or not.</returns>
438 /// <feature>http://tizen.org/feature/network.wifi</feature>
439 /// <privilege>http://tizen.org/privilege/network.set</privilege>
440 /// <privilege>http://tizen.org/privilege/network.get</privilege>
441 /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
442 /// <exception cref="UnauthorizedAccessException">Thrown when the permission is denied.</exception>
443 /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
444 static public Task BssidScanAsync()
446 return WiFiManagerImpl.Instance.BssidScanAsync();
450 /// Set Auto Scan Mode.
452 /// <since_tizen> 10 </since_tizen>
453 /// <feature>http://tizen.org/feature/network.wifi</feature>
454 /// <privilege>http://tizen.org/privilege/network.set</privilege>
455 /// <privilege>http://tizen.org/privilege/network.get</privilege>
456 /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
457 /// <exception cref="UnauthorizedAccessException">Thrown when the permission is denied.</exception>
458 /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
459 [EditorBrowsable(EditorBrowsableState.Never)]
460 static public void SetAutoScanMode(WiFiAutoScanMode scanMode)
462 WiFiManagerImpl.Instance.SetAutoScanMode((int)scanMode);
466 /// Hidden Ap connect.
469 /// This method must be called from MainThread.
471 /// <since_tizen> 10 </since_tizen>
472 /// <returns>A task indicating whether the HiddenAPConnectAsync method is done or not.</returns>
473 /// <feature>http://tizen.org/feature/network.wifi</feature>
474 /// <privilege>http://tizen.org/privilege/network.set</privilege>
475 /// <privilege>http://tizen.org/privilege/network.get</privilege>
476 /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
477 /// <exception cref="UnauthorizedAccessException">Thrown when the permission is denied.</exception>
478 /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
479 [EditorBrowsable(EditorBrowsableState.Never)]
480 static public Task HiddenAPConnectAsync(string essid, int secType, string password)
482 return WiFiManagerImpl.Instance.HiddenAPConnectAsync(essid, secType, password);
486 /// Create Specific scan handle.
488 /// <since_tizen> 9 </since_tizen>
489 /// <feature>http://tizen.org/feature/network.wifi</feature>
490 /// <privilege>http://tizen.org/privilege/network.profile</privilege>
491 /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
492 /// <exception cref="UnauthorizedAccessException">Thrown when the permission is denied.</exception>
493 /// <exception cref="OutOfMemoryException">Thrown when system is out of memory.</exception>
494 /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
495 [EditorBrowsable(EditorBrowsableState.Never)]
496 static public void CreateSpecificHandle()
498 WiFiManagerImpl.Instance.CreateSpecificScanHandle();
502 /// Destroys Specific scan handle.
504 /// <since_tizen> 9 </since_tizen>
505 /// <feature>http://tizen.org/feature/network.wifi</feature>
506 /// <privilege>http://tizen.org/privilege/network.profile</privilege>
507 /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
508 /// <exception cref="UnauthorizedAccessException">Thrown when the permission is denied.</exception>
509 /// <exception cref="OutOfMemoryException">Thrown when system is out of memory.</exception>
510 /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
511 [EditorBrowsable(EditorBrowsableState.Never)]
512 static public void DestroySpecificHandle()
514 WiFiManagerImpl.Instance.DestroySpecificScanHandle();
518 /// Starts Multi Scan.
521 /// This method must be called from MainThread.
523 /// <since_tizen> 9 </since_tizen>
524 /// <param name="frequency">Frequency for which MultiScan is to be run.</param>
525 /// <returns>A task indicating whether the StartMultiScan method is done or not.</returns>
526 /// <feature>http://tizen.org/feature/network.wifi</feature>
527 /// <privilege>http://tizen.org/privilege/network.set</privilege>
528 /// <privilege>http://tizen.org/privilege/network.get</privilege>
529 /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
530 /// <exception cref="UnauthorizedAccessException">Thrown when the permission is denied.</exception>
531 /// <exception cref="OutOfMemoryException">Thrown when system is out of memory.</exception>
532 /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
533 [EditorBrowsable(EditorBrowsableState.Never)]
534 static public Task StartMultiScan(int frequency)
536 WiFiManagerImpl.Instance.SetSpecificScanFreq(frequency);
537 return WiFiManagerImpl.Instance.StartMultiScan();