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 WiFiManager handle.
28 [EditorBrowsable(EditorBrowsableState.Never)]
29 public sealed class SafeWiFiManagerHandle : SafeHandle
31 internal SafeWiFiManagerHandle() : base(IntPtr.Zero, true)
36 /// Checks the validity of the handle.
38 /// <value>Represents the validity of the handle.</value>
39 public override bool IsInvalid
43 return this.handle == IntPtr.Zero;
47 protected override bool ReleaseHandle()
49 Interop.WiFi.Deinitialize(this.handle);
50 this.SetHandle(IntPtr.Zero);
56 /// A manager class which allows applications to connect to a Wireless Local Area Network (WLAN) and to transfer data over the network.<br>
57 /// 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.
59 /// <since_tizen> 3 </since_tizen>
60 static public class WiFiManager
63 /// The local MAC address.
65 /// <since_tizen> 3 </since_tizen>
66 /// <value>Represents the mac address of the WiFi.</value>
67 /// <privilege>http://tizen.org/privilege/network.get</privilege>
68 static public string MacAddress
72 return WiFiManagerImpl.Instance.MacAddress;
77 /// The name of the network interface.
79 /// <since_tizen> 3 </since_tizen>
80 /// <value>Interface name of WiFi.</value>
81 /// <privilege>http://tizen.org/privilege/network.get</privilege>
82 static public string InterfaceName
86 return WiFiManagerImpl.Instance.InterfaceName;
91 /// The network connection state.
93 /// <since_tizen> 3 </since_tizen>
94 /// <value>Represents the connection state of WiFi.</value>
95 /// <privilege>http://tizen.org/privilege/network.get</privilege>
96 static public WiFiConnectionState ConnectionState
100 return WiFiManagerImpl.Instance.ConnectionState;
105 /// A property to Check whether Wi-Fi is activated.
107 /// <since_tizen> 3 </since_tizen>
108 /// <value>Boolean value to check whether WiFi is activated or not.</value>
109 /// <privilege>http://tizen.org/privilege/network.get</privilege>
110 static public bool IsActive
114 return WiFiManagerImpl.Instance.IsActive;
119 /// DeviceStateChanged is raised when the device state is changed.
121 /// <since_tizen> 3 </since_tizen>
122 /// <privilege>http://tizen.org/privilege/network.get</privilege>
123 /// <feature>http://tizen.org/feature/network.wifi</feature>
124 static public event EventHandler<DeviceStateChangedEventArgs> DeviceStateChanged
128 WiFiManagerImpl.Instance.DeviceStateChanged += value;
132 WiFiManagerImpl.Instance.DeviceStateChanged -= value;
137 /// ConnectionStateChanged is raised when the connection state is changed.
139 /// <since_tizen> 3 </since_tizen>
140 /// <privilege>http://tizen.org/privilege/network.get</privilege>
141 /// <feature>http://tizen.org/feature/network.wifi</feature>
142 static public event EventHandler<ConnectionStateChangedEventArgs> ConnectionStateChanged
146 WiFiManagerImpl.Instance.ConnectionStateChanged += value;
150 WiFiManagerImpl.Instance.ConnectionStateChanged -= value;
155 /// RssiLevelChanged is raised when the RSSI of connected Wi-Fi is changed.
157 /// <since_tizen> 3 </since_tizen>
158 /// <privilege>http://tizen.org/privilege/network.get</privilege>
159 /// <feature>http://tizen.org/feature/network.wifi</feature>
160 static public event EventHandler<RssiLevelChangedEventArgs> RssiLevelChanged
164 WiFiManagerImpl.Instance.RssiLevelChanged += value;
168 WiFiManagerImpl.Instance.RssiLevelChanged -= value;
173 /// BackgroundScanFinished is raised when the background scan is finished.
174 /// The background scan starts automatically when wifi is activated. The callback will be invoked periodically.
176 /// <since_tizen> 3 </since_tizen>
177 /// <privilege>http://tizen.org/privilege/network.get</privilege>
178 /// <feature>http://tizen.org/feature/network.wifi</feature>
179 static public event EventHandler BackgroundScanFinished
183 WiFiManagerImpl.Instance.BackgroundScanFinished += value;
187 WiFiManagerImpl.Instance.BackgroundScanFinished -= value;
192 /// Gets the WiFi safe handle.
194 /// <since_tizen> 3 </since_tizen>
195 /// <returns>The instance of SafeWiFiManagerHandle</returns>
196 /// <feature>http://tizen.org/feature/network.wifi</feature>
197 /// <privilege>http://tizen.org/privilege/network.get</privilege>
198 /// <exception cref="NotSupportedException">Thrown when WiFi is not supported.</exception>
199 /// <exception cref="UnauthorizedAccessException">Thrown when permission is denied.</exception>
200 /// <exception cref="OutOfMemoryException">Thrown when the system is out of memory.</exception>
201 /// <exception cref="ArgumentException">Thrown when method is failed due to an invalid parameter.</exception>
202 /// <exception cref="InvalidOperationException">Thrown when the method failed due to invalid operation.</exception>
203 [EditorBrowsable(EditorBrowsableState.Never)]
204 public static SafeWiFiManagerHandle GetWiFiHandle()
206 return WiFiManagerImpl.Instance.GetSafeHandle();
210 /// Gets the result of the scan.
212 /// <since_tizen> 3 </since_tizen>
213 /// <returns> A list of WiFiAP objects.</returns>
214 /// <feature>http://tizen.org/feature/network.wifi</feature>
215 /// <privilege>http://tizen.org/privilege/network.get</privilege>
216 /// <exception cref="NotSupportedException">Thrown when WiFi is not supported.</exception>
217 /// <exception cref="UnauthorizedAccessException">Thrown when permission is denied.</exception>
218 /// <exception cref="ArgumentException">Thrown when method is failed due to an invalid parameter.</exception>
219 /// <exception cref="InvalidOperationException">Thrown when the method failed due to invalid operation.</exception>
220 static public IEnumerable<WiFiAP> GetFoundAPs()
222 return WiFiManagerImpl.Instance.GetFoundAPs();
226 /// Gets the result of specific AP scan.
228 /// <since_tizen> 3 </since_tizen>
229 /// <returns> A list contains the WiFiAP objects.</returns>
230 /// <feature>http://tizen.org/feature/network.wifi</feature>
231 /// <privilege>http://tizen.org/privilege/network.get</privilege>
232 /// <exception cref="NotSupportedException">Thrown when WiFi is not supported.</exception>
233 /// <exception cref="UnauthorizedAccessException">Thrown when permission is denied.</exception>
234 /// <exception cref="ArgumentException">Thrown when method is failed due to an invalid parameter.</exception>
235 /// <exception cref="InvalidOperationException">Thrown when the method failed due to invalid operation.</exception>
236 static public IEnumerable<WiFiAP> GetFoundSpecificAPs()
238 return WiFiManagerImpl.Instance.GetFoundSpecificAPs();
242 /// Gets the list of wifi configurations.
244 /// <since_tizen> 3 </since_tizen>
245 /// <returns>A list contains the WiFiConfiguration objects.</returns>
246 /// <feature>http://tizen.org/feature/network.wifi</feature>
247 /// <privilege>http://tizen.org/privilege/network.profile</privilege>
248 /// <exception cref="NotSupportedException">Thrown when WiFi is not supported.</exception>
249 /// <exception cref="UnauthorizedAccessException">Thrown when permission is denied.</exception>
250 /// <exception cref="OutOfMemoryException">Thrown when system is out of memory.</exception>
251 /// <exception cref="ArgumentException">Thrown when method is failed due to an invalid parameter.</exception>
252 /// <exception cref="InvalidOperationException">Thrown when the method failed due to invalid operation.</exception>
253 static public IEnumerable<WiFiConfiguration> GetWiFiConfigurations()
255 return WiFiManagerImpl.Instance.GetWiFiConfigurations();
259 /// Saves Wi-Fi configuration of access point.
261 /// <since_tizen> 3 </since_tizen>
262 /// <param name="configuration">The configuration to be stored</param>
263 /// <feature>http://tizen.org/feature/network.wifi</feature>
264 /// <privilege>http://tizen.org/privilege/network.profile</privilege>
265 /// <exception cref="NotSupportedException">Thrown when WiFi is not supported.</exception>
266 /// <exception cref="UnauthorizedAccessException">Thrown when permission is denied.</exception>
267 /// <exception cref="ArgumentNullException">Thrown when WiFiConfiguration is passed as null.</exception>
268 /// <exception cref="ArgumentException">Thrown when method is failed due to an invalid parameter.</exception>
269 /// <exception cref="InvalidOperationException">Thrown when the method failed due to invalid operation.</exception>
270 static public void SaveWiFiConfiguration(WiFiConfiguration configuration)
272 WiFiManagerImpl.Instance.SaveWiFiNetworkConfiguration(configuration);
276 /// Gets the object of the connected WiFiAP.
278 /// <since_tizen> 3 </since_tizen>
279 /// <returns> The connected wifi access point(AP) information.</returns>
280 /// <feature>http://tizen.org/feature/network.wifi</feature>
281 /// <privilege>http://tizen.org/privilege/network.get</privilege>
282 /// <exception cref="NotSupportedException">Thrown when WiFi is not supported.</exception>
283 /// <exception cref="UnauthorizedAccessException">Thrown when permission is denied.</exception>
284 /// <exception cref="OutOfMemoryException">Thrown when system is out of memory.</exception>
285 /// <exception cref="ArgumentException">Thrown when method is failed due to an invalid parameter.</exception>
286 /// <exception cref="InvalidOperationException">Thrown when the method failed due to invalid operation.</exception>
287 static public WiFiAP GetConnectedAP()
289 return WiFiManagerImpl.Instance.GetConnectedAP();
293 /// Activates Wi-Fi asynchronously.
295 /// <since_tizen> 3 </since_tizen>
296 /// <returns> A task indicating whether the Activate method is done or not.</returns>
297 /// <feature>http://tizen.org/feature/network.wifi</feature>
298 /// <privilege>http://tizen.org/privilege/network.set</privilege>
299 /// <privilege>http://tizen.org/privilege/network.get</privilege>
300 /// <exception cref="NotSupportedException">Thrown when WiFi is not supported.</exception>
301 /// <exception cref="UnauthorizedAccessException">Thrown when permission is denied.</exception>
302 /// <exception cref="ArgumentException">Thrown when method is failed due to an invalid parameter.</exception>
303 /// <exception cref="InvalidOperationException">Thrown when the method failed due to invalid operation.</exception>
304 static public Task ActivateAsync()
306 return WiFiManagerImpl.Instance.ActivateAsync();
310 /// Activates Wi-Fi asynchronously and displays Wi-Fi picker (popup) when Wi-Fi is not automatically connected.
312 /// <since_tizen> 3 </since_tizen>
313 /// <returns> A task indicating whether the ActivateWithPicker method is done or not.</returns>
314 /// <feature>http://tizen.org/feature/network.wifi</feature>
315 /// <privilege>http://tizen.org/privilege/network.set</privilege>
316 /// <privilege>http://tizen.org/privilege/network.get</privilege>
317 /// <exception cref="NotSupportedException">Thrown when WiFi is not supported.</exception>
318 /// <exception cref="UnauthorizedAccessException">Thrown when permission is denied.</exception>
319 /// <exception cref="ArgumentException">Thrown when method is failed due to an invalid parameter.</exception>
320 /// <exception cref="InvalidOperationException">Thrown when the method failed due to invalid operation.</exception>
321 static public Task ActivateWithPickerAsync()
323 return WiFiManagerImpl.Instance.ActivateWithWiFiPickerTestedAsync();
327 /// Deactivates Wi-Fi asynchronously.
329 /// <since_tizen> 3 </since_tizen>
330 /// <returns> A task indicating whether the Deactivate method is done or not.</returns>
331 /// <feature>http://tizen.org/feature/network.wifi</feature>
332 /// <privilege>http://tizen.org/privilege/network.set</privilege>
333 /// <privilege>http://tizen.org/privilege/network.get</privilege>
334 /// <exception cref="NotSupportedException">Thrown when WiFi is not supported.</exception>
335 /// <exception cref="UnauthorizedAccessException">Thrown when permission is denied.</exception>
336 /// <exception cref="ArgumentException">Thrown when method is failed due to an invalid parameter.</exception>
337 /// <exception cref="InvalidOperationException">Thrown when the method failed due to invalid operation.</exception>
338 static public Task DeactivateAsync()
340 return WiFiManagerImpl.Instance.DeactivateAsync();
344 /// Starts scan asynchronously.
346 /// <since_tizen> 3 </since_tizen>
347 /// <returns> A task indicating whether the Scan method is done or not.</returns>
348 /// <feature>http://tizen.org/feature/network.wifi</feature>
349 /// <privilege>http://tizen.org/privilege/network.set</privilege>
350 /// <privilege>http://tizen.org/privilege/network.get</privilege>
351 /// <exception cref="NotSupportedException">Thrown when WiFi is not supported.</exception>
352 /// <exception cref="UnauthorizedAccessException">Thrown when permission is denied.</exception>
353 /// <exception cref="ArgumentException">Thrown when method is failed due to an invalid parameter.</exception>
354 /// <exception cref="InvalidOperationException">Thrown when the method failed due to invalid operation.</exception>
355 static public Task ScanAsync()
357 return WiFiManagerImpl.Instance.ScanAsync();
361 /// Starts specific access point scan, asynchronously.
363 /// <since_tizen> 3 </since_tizen>
364 /// <returns> A task indicating whether the ScanSpecificAP method is done or not.</returns>
365 /// <param name="essid">The essid of hidden ap</param>
366 /// <feature>http://tizen.org/feature/network.wifi</feature>
367 /// <privilege>http://tizen.org/privilege/network.set</privilege>
368 /// <privilege>http://tizen.org/privilege/network.get</privilege>
369 /// <exception cref="NotSupportedException">Thrown when WiFi is not supported.</exception>
370 /// <exception cref="UnauthorizedAccessException">Thrown when permission is denied.</exception>
371 /// <exception cref="ArgumentException">Thrown when method is failed due to an invalid parameter.</exception>
372 /// <exception cref="InvalidOperationException">Thrown when the method failed due to invalid operation.</exception>
373 static public Task ScanSpecificAPAsync(string essid)
375 return WiFiManagerImpl.Instance.ScanSpecificAPAsync(essid);