2 * Copyright (c) 2016 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 /// DeviceStateChanged is raised when the device state is changed.
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
141 WiFiManagerImpl.Instance.DeviceStateChanged += value;
145 WiFiManagerImpl.Instance.DeviceStateChanged -= value;
150 /// ConnectionStateChanged is raised when the connection state is changed.
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
159 WiFiManagerImpl.Instance.ConnectionStateChanged += value;
163 WiFiManagerImpl.Instance.ConnectionStateChanged -= value;
168 /// RssiLevelChanged is raised when the RSSI of the connected Wi-Fi is changed.
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
177 WiFiManagerImpl.Instance.RssiLevelChanged += value;
181 WiFiManagerImpl.Instance.RssiLevelChanged -= value;
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.
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
196 WiFiManagerImpl.Instance.BackgroundScanFinished += value;
200 WiFiManagerImpl.Instance.BackgroundScanFinished -= value;
205 /// Gets the Wi-Fi safe handle.
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()
218 return WiFiManagerImpl.Instance.GetSafeHandle();
222 /// Gets the result of the scan.
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()
233 return WiFiManagerImpl.Instance.GetFoundAPs();
237 /// Gets the result of ScanSpecificAPAsync(string essid) API.
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()
248 return WiFiManagerImpl.Instance.GetFoundSpecificAPs();
252 /// Gets the result of the BssidScanAsync() API.
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()
263 return WiFiManagerImpl.Instance.GetFoundBssids();
267 /// Gets the list of Wi-Fi configurations.
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()
279 return WiFiManagerImpl.Instance.GetWiFiConfigurations();
283 /// Saves the Wi-Fi configuration of the access point.
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)
296 WiFiManagerImpl.Instance.SaveWiFiNetworkConfiguration(configuration);
300 /// Gets the object of the connected WiFiAP.
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()
312 return WiFiManagerImpl.Instance.GetConnectedAP();
316 /// Activates the Wi-Fi asynchronously.
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()
328 return WiFiManagerImpl.Instance.ActivateAsync();
332 /// Activates the Wi-Fi asynchronously and displays the Wi-Fi picker (popup) when the Wi-Fi is not automatically connected.
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()
344 return WiFiManagerImpl.Instance.ActivateWithWiFiPickerTestedAsync();
348 /// Deactivates the Wi-Fi asynchronously.
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()
360 return WiFiManagerImpl.Instance.DeactivateAsync();
364 /// Starts the scan asynchronously.
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()
376 return WiFiManagerImpl.Instance.ScanAsync();
380 /// Starts a specific access point scan asynchronously.
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)
394 return WiFiManagerImpl.Instance.ScanSpecificAPAsync(essid);
398 /// Starts BSSID scan asynchronously.
401 /// This method must be called from MainThread.
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()
413 return WiFiManagerImpl.Instance.BssidScanAsync();