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 [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;
48 /// Release the handle
50 protected override bool ReleaseHandle()
52 Interop.WiFi.Deinitialize(this.handle);
53 this.SetHandle(IntPtr.Zero);
59 /// A manager class which allows applications to connect to a Wireless Local Area Network (WLAN) and transfer data over the network.
60 /// 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.
62 /// <since_tizen> 3 </since_tizen>
63 static public class WiFiManager
66 /// The local MAC address.
68 /// <since_tizen> 3 </since_tizen>
69 /// <value>Represents the MAC address of the Wi-Fi.</value>
70 /// <privilege>http://tizen.org/privilege/network.get</privilege>
71 static public string MacAddress
75 return WiFiManagerImpl.Instance.MacAddress;
80 /// The name of the network interface.
82 /// <since_tizen> 3 </since_tizen>
83 /// <value>Interface name of the Wi-Fi.</value>
84 /// <privilege>http://tizen.org/privilege/network.get</privilege>
85 static public string InterfaceName
89 return WiFiManagerImpl.Instance.InterfaceName;
94 /// The network connection state.
96 /// <since_tizen> 3 </since_tizen>
97 /// <value>Represents the connection state of the Wi-Fi.</value>
98 /// <privilege>http://tizen.org/privilege/network.get</privilege>
99 static public WiFiConnectionState ConnectionState
103 return WiFiManagerImpl.Instance.ConnectionState;
108 /// A property to check whether Wi-Fi is activated.
110 /// <since_tizen> 3 </since_tizen>
111 /// <value>Boolean value to check whether Wi-Fi is activated or not.</value>
112 /// <privilege>http://tizen.org/privilege/network.get</privilege>
113 static public bool IsActive
117 return WiFiManagerImpl.Instance.IsActive;
122 /// DeviceStateChanged is raised when the device state is changed.
124 /// <since_tizen> 3 </since_tizen>
125 /// <privilege>http://tizen.org/privilege/network.get</privilege>
126 /// <feature>http://tizen.org/feature/network.wifi</feature>
127 static public event EventHandler<DeviceStateChangedEventArgs> DeviceStateChanged
131 WiFiManagerImpl.Instance.DeviceStateChanged += value;
135 WiFiManagerImpl.Instance.DeviceStateChanged -= value;
140 /// ConnectionStateChanged is raised when the connection state is changed.
142 /// <since_tizen> 3 </since_tizen>
143 /// <privilege>http://tizen.org/privilege/network.get</privilege>
144 /// <feature>http://tizen.org/feature/network.wifi</feature>
145 static public event EventHandler<ConnectionStateChangedEventArgs> ConnectionStateChanged
149 WiFiManagerImpl.Instance.ConnectionStateChanged += value;
153 WiFiManagerImpl.Instance.ConnectionStateChanged -= value;
158 /// RssiLevelChanged is raised when the RSSI of the connected Wi-Fi is changed.
160 /// <since_tizen> 3 </since_tizen>
161 /// <privilege>http://tizen.org/privilege/network.get</privilege>
162 /// <feature>http://tizen.org/feature/network.wifi</feature>
163 static public event EventHandler<RssiLevelChangedEventArgs> RssiLevelChanged
167 WiFiManagerImpl.Instance.RssiLevelChanged += value;
171 WiFiManagerImpl.Instance.RssiLevelChanged -= value;
176 /// BackgroundScanFinished is raised when the background scan is finished.
177 /// The background scan starts automatically when Wi-Fi is activated. The callback will be invoked periodically.
179 /// <since_tizen> 3 </since_tizen>
180 /// <privilege>http://tizen.org/privilege/network.get</privilege>
181 /// <feature>http://tizen.org/feature/network.wifi</feature>
182 static public event EventHandler BackgroundScanFinished
186 WiFiManagerImpl.Instance.BackgroundScanFinished += value;
190 WiFiManagerImpl.Instance.BackgroundScanFinished -= value;
195 /// Gets the Wi-Fi safe handle.
197 /// <since_tizen> 3 </since_tizen>
198 /// <returns>The instance of the SafeWiFiManagerHandle.</returns>
199 /// <feature>http://tizen.org/feature/network.wifi</feature>
200 /// <privilege>http://tizen.org/privilege/network.get</privilege>
201 /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
202 /// <exception cref="UnauthorizedAccessException">Thrown when the permission is denied.</exception>
203 /// <exception cref="OutOfMemoryException">Thrown when the system is out of memory.</exception>
204 /// <exception cref="ArgumentException">Thrown when the method failed due to an invalid parameter.</exception>
205 /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
206 [EditorBrowsable(EditorBrowsableState.Never)]
207 public static SafeWiFiManagerHandle GetWiFiHandle()
209 return WiFiManagerImpl.Instance.GetSafeHandle();
213 /// Gets the result of the scan.
215 /// <since_tizen> 3 </since_tizen>
216 /// <returns>A list of the WiFiAP objects.</returns>
217 /// <feature>http://tizen.org/feature/network.wifi</feature>
218 /// <privilege>http://tizen.org/privilege/network.get</privilege>
219 /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
220 /// <exception cref="UnauthorizedAccessException">Thrown when the permission is denied.</exception>
221 /// <exception cref="ArgumentException">Thrown when the method failed due to an invalid parameter.</exception>
222 /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
223 static public IEnumerable<WiFiAP> GetFoundAPs()
225 return WiFiManagerImpl.Instance.GetFoundAPs();
229 /// Gets the result of ScanSpecificAPAsync(string essid) API.
231 /// <since_tizen> 3 </since_tizen>
232 /// <returns>A list containing the WiFiAP objects.</returns>
233 /// <feature>http://tizen.org/feature/network.wifi</feature>
234 /// <privilege>http://tizen.org/privilege/network.get</privilege>
235 /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
236 /// <exception cref="UnauthorizedAccessException">Thrown when the permission is denied.</exception>
237 /// <exception cref="ArgumentException">Thrown when the method failed due to an invalid parameter.</exception>
238 /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
239 static public IEnumerable<WiFiAP> GetFoundSpecificAPs()
241 return WiFiManagerImpl.Instance.GetFoundSpecificAPs();
245 /// Gets the list of Wi-Fi configurations.
247 /// <since_tizen> 3 </since_tizen>
248 /// <returns>A list containing the WiFiConfiguration objects.</returns>
249 /// <feature>http://tizen.org/feature/network.wifi</feature>
250 /// <privilege>http://tizen.org/privilege/network.profile</privilege>
251 /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
252 /// <exception cref="UnauthorizedAccessException">Thrown when the permission is denied.</exception>
253 /// <exception cref="OutOfMemoryException">Thrown when system is out of memory.</exception>
254 /// <exception cref="ArgumentException">Thrown when the method failed due to an invalid parameter.</exception>
255 /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
256 static public IEnumerable<WiFiConfiguration> GetWiFiConfigurations()
258 return WiFiManagerImpl.Instance.GetWiFiConfigurations();
262 /// Saves the Wi-Fi configuration of the access point.
264 /// <since_tizen> 3 </since_tizen>
265 /// <param name="configuration">The configuration to be stored.</param>
266 /// <feature>http://tizen.org/feature/network.wifi</feature>
267 /// <privilege>http://tizen.org/privilege/network.profile</privilege>
268 /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
269 /// <exception cref="UnauthorizedAccessException">Thrown when the permission is denied.</exception>
270 /// <exception cref="ArgumentNullException">Thrown when WiFiConfiguration is passed as null.</exception>
271 /// <exception cref="ArgumentException">Thrown when the method failed due to an invalid parameter.</exception>
272 /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
273 static public void SaveWiFiConfiguration(WiFiConfiguration configuration)
275 WiFiManagerImpl.Instance.SaveWiFiNetworkConfiguration(configuration);
279 /// Gets the object of the connected WiFiAP.
281 /// <since_tizen> 3 </since_tizen>
282 /// <returns>The connected Wi-Fi access point (AP) information.</returns>
283 /// <feature>http://tizen.org/feature/network.wifi</feature>
284 /// <privilege>http://tizen.org/privilege/network.get</privilege>
285 /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
286 /// <exception cref="UnauthorizedAccessException">Thrown when the permission is denied.</exception>
287 /// <exception cref="OutOfMemoryException">Thrown when system is out of memory.</exception>
288 /// <exception cref="ArgumentException">Thrown when the method failed due to an invalid parameter.</exception>
289 /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
290 static public WiFiAP GetConnectedAP()
292 return WiFiManagerImpl.Instance.GetConnectedAP();
296 /// Activates the Wi-Fi asynchronously.
298 /// <since_tizen> 3 </since_tizen>
299 /// <returns> A task indicating whether the activate method is done or not.</returns>
300 /// <feature>http://tizen.org/feature/network.wifi</feature>
301 /// <privilege>http://tizen.org/privilege/network.set</privilege>
302 /// <privilege>http://tizen.org/privilege/network.get</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="ArgumentException">Thrown when the method failed due to an invalid parameter.</exception>
306 /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
307 static public Task ActivateAsync()
309 return WiFiManagerImpl.Instance.ActivateAsync();
313 /// Activates the Wi-Fi asynchronously and displays the Wi-Fi picker (popup) when the Wi-Fi is not automatically connected.
315 /// <since_tizen> 3 </since_tizen>
316 /// <returns>A task indicating whether the ActivateWithPicker method is done or not.</returns>
317 /// <feature>http://tizen.org/feature/network.wifi</feature>
318 /// <privilege>http://tizen.org/privilege/network.set</privilege>
319 /// <privilege>http://tizen.org/privilege/network.get</privilege>
320 /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
321 /// <exception cref="UnauthorizedAccessException">Thrown when the permission is denied.</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 Task ActivateWithPickerAsync()
326 return WiFiManagerImpl.Instance.ActivateWithWiFiPickerTestedAsync();
330 /// Deactivates the Wi-Fi asynchronously.
332 /// <since_tizen> 3 </since_tizen>
333 /// <returns>A task indicating whether the deactivate method is done or not.</returns>
334 /// <feature>http://tizen.org/feature/network.wifi</feature>
335 /// <privilege>http://tizen.org/privilege/network.set</privilege>
336 /// <privilege>http://tizen.org/privilege/network.get</privilege>
337 /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
338 /// <exception cref="UnauthorizedAccessException">Thrown when the permission is denied.</exception>
339 /// <exception cref="ArgumentException">Thrown when the method failed due to an invalid parameter.</exception>
340 /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
341 static public Task DeactivateAsync()
343 return WiFiManagerImpl.Instance.DeactivateAsync();
347 /// Starts the scan asynchronously.
349 /// <since_tizen> 3 </since_tizen>
350 /// <returns>A task indicating whether the scan method is done or not.</returns>
351 /// <feature>http://tizen.org/feature/network.wifi</feature>
352 /// <privilege>http://tizen.org/privilege/network.set</privilege>
353 /// <privilege>http://tizen.org/privilege/network.get</privilege>
354 /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
355 /// <exception cref="UnauthorizedAccessException">Thrown when the permission is denied.</exception>
356 /// <exception cref="ArgumentException">Thrown when the method failed due to an invalid parameter.</exception>
357 /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
358 static public Task ScanAsync()
360 return WiFiManagerImpl.Instance.ScanAsync();
364 /// Starts a specific access point scan asynchronously.
366 /// <since_tizen> 3 </since_tizen>
367 /// <returns>A task indicating whether the ScanSpecificAP method is done or not.</returns>
368 /// <param name="essid">The ESSID of the hidden AP.</param>
369 /// <feature>http://tizen.org/feature/network.wifi</feature>
370 /// <privilege>http://tizen.org/privilege/network.set</privilege>
371 /// <privilege>http://tizen.org/privilege/network.get</privilege>
372 /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
373 /// <exception cref="UnauthorizedAccessException">Thrown when the permission is denied.</exception>
374 /// <exception cref="ArgumentException">Thrown when the method failed due to an invalid parameter.</exception>
375 /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
376 static public Task ScanSpecificAPAsync(string essid)
378 return WiFiManagerImpl.Instance.ScanSpecificAPAsync(essid);