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);
66 Log.Info(Globals.LogTag, "New Handle for Thread " + tid);
72 /// A manager class which allows applications to connect to a Wireless Local Area Network (WLAN) and transfer data over the network.
73 /// 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.
75 /// <since_tizen> 3 </since_tizen>
76 static public class WiFiManager
79 /// The local MAC address.
81 /// <since_tizen> 3 </since_tizen>
82 /// <value>Represents the MAC address of the Wi-Fi.</value>
83 /// <privilege>http://tizen.org/privilege/network.get</privilege>
84 static public string MacAddress
88 return WiFiManagerImpl.Instance.MacAddress;
93 /// The name of the network interface.
95 /// <since_tizen> 3 </since_tizen>
96 /// <value>Interface name of the Wi-Fi.</value>
97 /// <privilege>http://tizen.org/privilege/network.get</privilege>
98 static public string InterfaceName
102 return WiFiManagerImpl.Instance.InterfaceName;
107 /// The network connection state.
109 /// <since_tizen> 3 </since_tizen>
110 /// <value>Represents the connection state of the Wi-Fi.</value>
111 /// <privilege>http://tizen.org/privilege/network.get</privilege>
112 static public WiFiConnectionState ConnectionState
116 return WiFiManagerImpl.Instance.ConnectionState;
121 /// A property to check whether Wi-Fi is activated.
123 /// <since_tizen> 3 </since_tizen>
124 /// <value>Boolean value to check whether Wi-Fi is activated or not.</value>
125 /// <privilege>http://tizen.org/privilege/network.get</privilege>
126 static public bool IsActive
130 return WiFiManagerImpl.Instance.IsActive;
135 /// DeviceStateChanged is raised when the device state is changed.
137 /// <since_tizen> 3 </since_tizen>
138 /// <privilege>http://tizen.org/privilege/network.get</privilege>
139 /// <feature>http://tizen.org/feature/network.wifi</feature>
140 static public event EventHandler<DeviceStateChangedEventArgs> DeviceStateChanged
144 WiFiManagerImpl.Instance.DeviceStateChanged += value;
148 WiFiManagerImpl.Instance.DeviceStateChanged -= value;
153 /// ConnectionStateChanged is raised when the connection state is changed.
155 /// <since_tizen> 3 </since_tizen>
156 /// <privilege>http://tizen.org/privilege/network.get</privilege>
157 /// <feature>http://tizen.org/feature/network.wifi</feature>
158 static public event EventHandler<ConnectionStateChangedEventArgs> ConnectionStateChanged
162 WiFiManagerImpl.Instance.ConnectionStateChanged += value;
166 WiFiManagerImpl.Instance.ConnectionStateChanged -= value;
171 /// RssiLevelChanged is raised when the RSSI of the connected Wi-Fi is changed.
173 /// <since_tizen> 3 </since_tizen>
174 /// <privilege>http://tizen.org/privilege/network.get</privilege>
175 /// <feature>http://tizen.org/feature/network.wifi</feature>
176 static public event EventHandler<RssiLevelChangedEventArgs> RssiLevelChanged
180 WiFiManagerImpl.Instance.RssiLevelChanged += value;
184 WiFiManagerImpl.Instance.RssiLevelChanged -= value;
189 /// BackgroundScanFinished is raised when the background scan is finished.
190 /// The background scan starts automatically when Wi-Fi is activated. The callback will be invoked periodically.
192 /// <since_tizen> 3 </since_tizen>
193 /// <privilege>http://tizen.org/privilege/network.get</privilege>
194 /// <feature>http://tizen.org/feature/network.wifi</feature>
195 static public event EventHandler BackgroundScanFinished
199 WiFiManagerImpl.Instance.BackgroundScanFinished += value;
203 WiFiManagerImpl.Instance.BackgroundScanFinished -= value;
208 /// Gets the Wi-Fi safe handle.
210 /// <since_tizen> 3 </since_tizen>
211 /// <returns>The instance of the SafeWiFiManagerHandle.</returns>
212 /// <feature>http://tizen.org/feature/network.wifi</feature>
213 /// <privilege>http://tizen.org/privilege/network.get</privilege>
214 /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
215 /// <exception cref="UnauthorizedAccessException">Thrown when the permission is denied.</exception>
216 /// <exception cref="OutOfMemoryException">Thrown when the system is out of memory.</exception>
217 /// <exception cref="ArgumentException">Thrown when the method failed due to an invalid parameter.</exception>
218 /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
219 [EditorBrowsable(EditorBrowsableState.Never)]
220 public static SafeWiFiManagerHandle GetWiFiHandle()
222 return WiFiManagerImpl.Instance.GetSafeHandle();
226 /// Gets the result of the scan.
228 /// <since_tizen> 3 </since_tizen>
229 /// <returns>A list of 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 the Wi-Fi is not supported.</exception>
233 /// <exception cref="UnauthorizedAccessException">Thrown when the permission is denied.</exception>
234 /// <exception cref="ArgumentException">Thrown when the method failed due to an invalid parameter.</exception>
235 /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
236 static public IEnumerable<WiFiAP> GetFoundAPs()
238 return WiFiManagerImpl.Instance.GetFoundAPs();
242 /// Gets the result of ScanSpecificAPAsync(string essid) API.
244 /// <since_tizen> 3 </since_tizen>
245 /// <returns>A list containing the WiFiAP objects.</returns>
246 /// <feature>http://tizen.org/feature/network.wifi</feature>
247 /// <privilege>http://tizen.org/privilege/network.get</privilege>
248 /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
249 /// <exception cref="UnauthorizedAccessException">Thrown when the permission is denied.</exception>
250 /// <exception cref="ArgumentException">Thrown when the method failed due to an invalid parameter.</exception>
251 /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
252 static public IEnumerable<WiFiAP> GetFoundSpecificAPs()
254 return WiFiManagerImpl.Instance.GetFoundSpecificAPs();
258 /// Gets the list of Wi-Fi configurations.
260 /// <since_tizen> 3 </since_tizen>
261 /// <returns>A list containing the WiFiConfiguration objects.</returns>
262 /// <feature>http://tizen.org/feature/network.wifi</feature>
263 /// <privilege>http://tizen.org/privilege/network.profile</privilege>
264 /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
265 /// <exception cref="UnauthorizedAccessException">Thrown when the permission is denied.</exception>
266 /// <exception cref="OutOfMemoryException">Thrown when system is out of memory.</exception>
267 /// <exception cref="ArgumentException">Thrown when the method failed due to an invalid parameter.</exception>
268 /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
269 static public IEnumerable<WiFiConfiguration> GetWiFiConfigurations()
271 return WiFiManagerImpl.Instance.GetWiFiConfigurations();
275 /// Saves the Wi-Fi configuration of the access point.
277 /// <since_tizen> 3 </since_tizen>
278 /// <param name="configuration">The configuration to be stored.</param>
279 /// <feature>http://tizen.org/feature/network.wifi</feature>
280 /// <privilege>http://tizen.org/privilege/network.profile</privilege>
281 /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
282 /// <exception cref="UnauthorizedAccessException">Thrown when the permission is denied.</exception>
283 /// <exception cref="ArgumentNullException">Thrown when WiFiConfiguration is passed as null.</exception>
284 /// <exception cref="ArgumentException">Thrown when the method failed due to an invalid parameter.</exception>
285 /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
286 static public void SaveWiFiConfiguration(WiFiConfiguration configuration)
288 WiFiManagerImpl.Instance.SaveWiFiNetworkConfiguration(configuration);
292 /// Gets the object of the connected WiFiAP.
294 /// <since_tizen> 3 </since_tizen>
295 /// <returns>The connected Wi-Fi access point (AP) information.</returns>
296 /// <feature>http://tizen.org/feature/network.wifi</feature>
297 /// <privilege>http://tizen.org/privilege/network.get</privilege>
298 /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
299 /// <exception cref="UnauthorizedAccessException">Thrown when the permission is denied.</exception>
300 /// <exception cref="OutOfMemoryException">Thrown when system is out of memory.</exception>
301 /// <exception cref="ArgumentException">Thrown when the method failed due to an invalid parameter.</exception>
302 /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
303 static public WiFiAP GetConnectedAP()
305 return WiFiManagerImpl.Instance.GetConnectedAP();
309 /// Activates the Wi-Fi asynchronously.
311 /// <since_tizen> 3 </since_tizen>
312 /// <returns> A task indicating whether the activate method is done or not.</returns>
313 /// <feature>http://tizen.org/feature/network.wifi</feature>
314 /// <privilege>http://tizen.org/privilege/network.set</privilege>
315 /// <privilege>http://tizen.org/privilege/network.get</privilege>
316 /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
317 /// <exception cref="UnauthorizedAccessException">Thrown when the permission is denied.</exception>
318 /// <exception cref="ArgumentException">Thrown when the method failed due to an invalid parameter.</exception>
319 /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
320 static public Task ActivateAsync()
322 return WiFiManagerImpl.Instance.ActivateAsync();
326 /// Activates the Wi-Fi asynchronously and displays the Wi-Fi picker (popup) when the Wi-Fi is not automatically connected.
328 /// <since_tizen> 3 </since_tizen>
329 /// <returns>A task indicating whether the ActivateWithPicker method is done or not.</returns>
330 /// <feature>http://tizen.org/feature/network.wifi</feature>
331 /// <privilege>http://tizen.org/privilege/network.set</privilege>
332 /// <privilege>http://tizen.org/privilege/network.get</privilege>
333 /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
334 /// <exception cref="UnauthorizedAccessException">Thrown when the permission is denied.</exception>
335 /// <exception cref="ArgumentException">Thrown when the method failed due to an invalid parameter.</exception>
336 /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
337 static public Task ActivateWithPickerAsync()
339 return WiFiManagerImpl.Instance.ActivateWithWiFiPickerTestedAsync();
343 /// Deactivates the Wi-Fi asynchronously.
345 /// <since_tizen> 3 </since_tizen>
346 /// <returns>A task indicating whether the deactivate method is done or not.</returns>
347 /// <feature>http://tizen.org/feature/network.wifi</feature>
348 /// <privilege>http://tizen.org/privilege/network.set</privilege>
349 /// <privilege>http://tizen.org/privilege/network.get</privilege>
350 /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
351 /// <exception cref="UnauthorizedAccessException">Thrown when the permission is denied.</exception>
352 /// <exception cref="ArgumentException">Thrown when the method failed due to an invalid parameter.</exception>
353 /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
354 static public Task DeactivateAsync()
356 return WiFiManagerImpl.Instance.DeactivateAsync();
360 /// Starts the scan asynchronously.
362 /// <since_tizen> 3 </since_tizen>
363 /// <returns>A task indicating whether the scan method is done or not.</returns>
364 /// <feature>http://tizen.org/feature/network.wifi</feature>
365 /// <privilege>http://tizen.org/privilege/network.set</privilege>
366 /// <privilege>http://tizen.org/privilege/network.get</privilege>
367 /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
368 /// <exception cref="UnauthorizedAccessException">Thrown when the permission is denied.</exception>
369 /// <exception cref="ArgumentException">Thrown when the method failed due to an invalid parameter.</exception>
370 /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
371 static public Task ScanAsync()
373 return WiFiManagerImpl.Instance.ScanAsync();
377 /// Starts a specific access point scan asynchronously.
379 /// <since_tizen> 3 </since_tizen>
380 /// <returns>A task indicating whether the ScanSpecificAP method is done or not.</returns>
381 /// <param name="essid">The ESSID of the hidden AP.</param>
382 /// <feature>http://tizen.org/feature/network.wifi</feature>
383 /// <privilege>http://tizen.org/privilege/network.set</privilege>
384 /// <privilege>http://tizen.org/privilege/network.get</privilege>
385 /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
386 /// <exception cref="UnauthorizedAccessException">Thrown when the permission is denied.</exception>
387 /// <exception cref="ArgumentException">Thrown when the method failed due to an invalid parameter.</exception>
388 /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
389 static public Task ScanSpecificAPAsync(string essid)
391 return WiFiManagerImpl.Instance.ScanSpecificAPAsync(essid);