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="ArgumentException">Thrown when the method failed due to an invalid parameter.</exception>
215 /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
216 [EditorBrowsable(EditorBrowsableState.Never)]
217 public static SafeWiFiManagerHandle GetWiFiHandle()
219 return WiFiManagerImpl.Instance.GetSafeHandle();
223 /// Gets the result of the scan.
225 /// <since_tizen> 3 </since_tizen>
226 /// <returns>A list of the WiFiAP objects.</returns>
227 /// <feature>http://tizen.org/feature/network.wifi</feature>
228 /// <privilege>http://tizen.org/privilege/network.get</privilege>
229 /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
230 /// <exception cref="UnauthorizedAccessException">Thrown when the permission is denied.</exception>
231 /// <exception cref="ArgumentException">Thrown when the method failed due to an invalid parameter.</exception>
232 /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
233 static public IEnumerable<WiFiAP> GetFoundAPs()
235 return WiFiManagerImpl.Instance.GetFoundAPs();
239 /// Gets the result of ScanSpecificAPAsync(string essid) API.
241 /// <since_tizen> 3 </since_tizen>
242 /// <returns>A list containing the WiFiAP objects.</returns>
243 /// <feature>http://tizen.org/feature/network.wifi</feature>
244 /// <privilege>http://tizen.org/privilege/network.get</privilege>
245 /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
246 /// <exception cref="UnauthorizedAccessException">Thrown when the permission is denied.</exception>
247 /// <exception cref="ArgumentException">Thrown when the method failed due to an invalid parameter.</exception>
248 /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
249 static public IEnumerable<WiFiAP> GetFoundSpecificAPs()
251 return WiFiManagerImpl.Instance.GetFoundSpecificAPs();
255 /// Gets the list of Wi-Fi configurations.
257 /// <since_tizen> 3 </since_tizen>
258 /// <returns>A list containing the WiFiConfiguration objects.</returns>
259 /// <feature>http://tizen.org/feature/network.wifi</feature>
260 /// <privilege>http://tizen.org/privilege/network.profile</privilege>
261 /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
262 /// <exception cref="UnauthorizedAccessException">Thrown when the permission is denied.</exception>
263 /// <exception cref="OutOfMemoryException">Thrown when system is out of memory.</exception>
264 /// <exception cref="ArgumentException">Thrown when the method failed due to an invalid parameter.</exception>
265 /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
266 static public IEnumerable<WiFiConfiguration> GetWiFiConfigurations()
268 return WiFiManagerImpl.Instance.GetWiFiConfigurations();
272 /// Saves the Wi-Fi configuration of the access point.
274 /// <since_tizen> 3 </since_tizen>
275 /// <param name="configuration">The configuration to be stored.</param>
276 /// <feature>http://tizen.org/feature/network.wifi</feature>
277 /// <privilege>http://tizen.org/privilege/network.profile</privilege>
278 /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
279 /// <exception cref="UnauthorizedAccessException">Thrown when the permission is denied.</exception>
280 /// <exception cref="ArgumentNullException">Thrown when WiFiConfiguration is passed as null.</exception>
281 /// <exception cref="ArgumentException">Thrown when the method failed due to an invalid parameter.</exception>
282 /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
283 static public void SaveWiFiConfiguration(WiFiConfiguration configuration)
285 WiFiManagerImpl.Instance.SaveWiFiNetworkConfiguration(configuration);
289 /// Gets the object of the connected WiFiAP.
291 /// <since_tizen> 3 </since_tizen>
292 /// <returns>The connected Wi-Fi access point (AP) information.</returns>
293 /// <feature>http://tizen.org/feature/network.wifi</feature>
294 /// <privilege>http://tizen.org/privilege/network.get</privilege>
295 /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
296 /// <exception cref="UnauthorizedAccessException">Thrown when the permission is denied.</exception>
297 /// <exception cref="OutOfMemoryException">Thrown when system is out of memory.</exception>
298 /// <exception cref="ArgumentException">Thrown when the method failed due to an invalid parameter.</exception>
299 /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
300 static public WiFiAP GetConnectedAP()
302 return WiFiManagerImpl.Instance.GetConnectedAP();
306 /// Activates the Wi-Fi asynchronously.
308 /// <since_tizen> 3 </since_tizen>
309 /// <returns> A task indicating whether the activate method is done or not.</returns>
310 /// <feature>http://tizen.org/feature/network.wifi</feature>
311 /// <privilege>http://tizen.org/privilege/network.set</privilege>
312 /// <privilege>http://tizen.org/privilege/network.get</privilege>
313 /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
314 /// <exception cref="UnauthorizedAccessException">Thrown when the permission is denied.</exception>
315 /// <exception cref="ArgumentException">Thrown when the method failed due to an invalid parameter.</exception>
316 /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
317 static public Task ActivateAsync()
319 return WiFiManagerImpl.Instance.ActivateAsync();
323 /// Activates the Wi-Fi asynchronously and displays the Wi-Fi picker (popup) when the Wi-Fi is not automatically connected.
325 /// <since_tizen> 3 </since_tizen>
326 /// <returns>A task indicating whether the ActivateWithPicker method is done or not.</returns>
327 /// <feature>http://tizen.org/feature/network.wifi</feature>
328 /// <privilege>http://tizen.org/privilege/network.set</privilege>
329 /// <privilege>http://tizen.org/privilege/network.get</privilege>
330 /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
331 /// <exception cref="UnauthorizedAccessException">Thrown when the permission is denied.</exception>
332 /// <exception cref="ArgumentException">Thrown when the method failed due to an invalid parameter.</exception>
333 /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
334 static public Task ActivateWithPickerAsync()
336 return WiFiManagerImpl.Instance.ActivateWithWiFiPickerTestedAsync();
340 /// Deactivates the Wi-Fi asynchronously.
342 /// <since_tizen> 3 </since_tizen>
343 /// <returns>A task indicating whether the deactivate method is done or not.</returns>
344 /// <feature>http://tizen.org/feature/network.wifi</feature>
345 /// <privilege>http://tizen.org/privilege/network.set</privilege>
346 /// <privilege>http://tizen.org/privilege/network.get</privilege>
347 /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
348 /// <exception cref="UnauthorizedAccessException">Thrown when the permission is denied.</exception>
349 /// <exception cref="ArgumentException">Thrown when the method failed due to an invalid parameter.</exception>
350 /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
351 static public Task DeactivateAsync()
353 return WiFiManagerImpl.Instance.DeactivateAsync();
357 /// Starts the scan asynchronously.
359 /// <since_tizen> 3 </since_tizen>
360 /// <returns>A task indicating whether the scan method is done or not.</returns>
361 /// <feature>http://tizen.org/feature/network.wifi</feature>
362 /// <privilege>http://tizen.org/privilege/network.set</privilege>
363 /// <privilege>http://tizen.org/privilege/network.get</privilege>
364 /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
365 /// <exception cref="UnauthorizedAccessException">Thrown when the permission is denied.</exception>
366 /// <exception cref="ArgumentException">Thrown when the method failed due to an invalid parameter.</exception>
367 /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
368 static public Task ScanAsync()
370 return WiFiManagerImpl.Instance.ScanAsync();
374 /// Starts a specific access point scan asynchronously.
376 /// <since_tizen> 3 </since_tizen>
377 /// <returns>A task indicating whether the ScanSpecificAP method is done or not.</returns>
378 /// <param name="essid">The ESSID of the hidden AP.</param>
379 /// <feature>http://tizen.org/feature/network.wifi</feature>
380 /// <privilege>http://tizen.org/privilege/network.set</privilege>
381 /// <privilege>http://tizen.org/privilege/network.get</privilege>
382 /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
383 /// <exception cref="UnauthorizedAccessException">Thrown when the permission is denied.</exception>
384 /// <exception cref="ArgumentException">Thrown when the method failed due to an invalid parameter.</exception>
385 /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
386 static public Task ScanSpecificAPAsync(string essid)
388 return WiFiManagerImpl.Instance.ScanSpecificAPAsync(essid);