/* * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ using System; using System.Collections.Generic; using System.Runtime.InteropServices; using System.Threading.Tasks; using System.ComponentModel; namespace Tizen.Network.WiFi { /// /// A class for managing WiFiManager handle. /// [EditorBrowsable(EditorBrowsableState.Never)] public sealed class SafeWiFiManagerHandle : SafeHandle { internal SafeWiFiManagerHandle() : base(IntPtr.Zero, true) { } /// /// Checks the validity of the handle. /// /// Represents the validity of the handle. public override bool IsInvalid { get { return this.handle == IntPtr.Zero; } } protected override bool ReleaseHandle() { Interop.WiFi.Deinitialize(this.handle); this.SetHandle(IntPtr.Zero); return true; } } /// /// A manager class which allows applications to connect to a Wireless Local Area Network (WLAN) and to transfer data over the network.
/// 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. ///
/// 3 static public class WiFiManager { /// /// The local MAC address. /// /// 3 /// Represents the mac address of the WiFi. /// http://tizen.org/privilege/network.get static public string MacAddress { get { return WiFiManagerImpl.Instance.MacAddress; } } /// /// The name of the network interface. /// /// 3 /// Interface name of WiFi. /// http://tizen.org/privilege/network.get static public string InterfaceName { get { return WiFiManagerImpl.Instance.InterfaceName; } } /// /// The network connection state. /// /// 3 /// Represents the connection state of WiFi. /// http://tizen.org/privilege/network.get static public WiFiConnectionState ConnectionState { get { return WiFiManagerImpl.Instance.ConnectionState; } } /// /// A property to Check whether Wi-Fi is activated. /// /// 3 /// Boolean value to check whether WiFi is activated or not. /// http://tizen.org/privilege/network.get static public bool IsActive { get { return WiFiManagerImpl.Instance.IsActive; } } /// /// DeviceStateChanged is raised when the device state is changed. /// /// 3 /// http://tizen.org/privilege/network.get /// http://tizen.org/feature/network.wifi static public event EventHandler DeviceStateChanged { add { WiFiManagerImpl.Instance.DeviceStateChanged += value; } remove { WiFiManagerImpl.Instance.DeviceStateChanged -= value; } } /// /// ConnectionStateChanged is raised when the connection state is changed. /// /// 3 /// http://tizen.org/privilege/network.get /// http://tizen.org/feature/network.wifi static public event EventHandler ConnectionStateChanged { add { WiFiManagerImpl.Instance.ConnectionStateChanged += value; } remove { WiFiManagerImpl.Instance.ConnectionStateChanged -= value; } } /// /// RssiLevelChanged is raised when the RSSI of connected Wi-Fi is changed. /// /// 3 /// http://tizen.org/privilege/network.get /// http://tizen.org/feature/network.wifi static public event EventHandler RssiLevelChanged { add { WiFiManagerImpl.Instance.RssiLevelChanged += value; } remove { WiFiManagerImpl.Instance.RssiLevelChanged -= value; } } /// /// BackgroundScanFinished is raised when the background scan is finished. /// The background scan starts automatically when wifi is activated. The callback will be invoked periodically. /// /// 3 /// http://tizen.org/privilege/network.get /// http://tizen.org/feature/network.wifi static public event EventHandler BackgroundScanFinished { add { WiFiManagerImpl.Instance.BackgroundScanFinished += value; } remove { WiFiManagerImpl.Instance.BackgroundScanFinished -= value; } } /// /// Gets the WiFi safe handle. /// /// 3 /// The instance of SafeWiFiManagerHandle /// http://tizen.org/feature/network.wifi /// http://tizen.org/privilege/network.get /// Thrown when WiFi is not supported. /// Thrown when permission is denied. /// Thrown when the system is out of memory. /// Thrown when method is failed due to an invalid parameter. /// Thrown when the method failed due to invalid operation. [EditorBrowsable(EditorBrowsableState.Never)] public static SafeWiFiManagerHandle GetWiFiHandle() { return WiFiManagerImpl.Instance.GetSafeHandle(); } /// /// Gets the result of the scan. /// /// 3 /// A list of WiFiAP objects. /// http://tizen.org/feature/network.wifi /// http://tizen.org/privilege/network.get /// Thrown when WiFi is not supported. /// Thrown when permission is denied. /// Thrown when method is failed due to an invalid parameter. /// Thrown when the method failed due to invalid operation. static public IEnumerable GetFoundAPs() { return WiFiManagerImpl.Instance.GetFoundAPs(); } /// /// Gets the result of specific AP scan. /// /// 3 /// A list contains the WiFiAP objects. /// http://tizen.org/feature/network.wifi /// http://tizen.org/privilege/network.get /// Thrown when WiFi is not supported. /// Thrown when permission is denied. /// Thrown when method is failed due to an invalid parameter. /// Thrown when the method failed due to invalid operation. static public IEnumerable GetFoundSpecificAPs() { return WiFiManagerImpl.Instance.GetFoundSpecificAPs(); } /// /// Gets the list of wifi configurations. /// /// 3 /// A list contains the WiFiConfiguration objects. /// http://tizen.org/feature/network.wifi /// http://tizen.org/privilege/network.profile /// Thrown when WiFi is not supported. /// Thrown when permission is denied. /// Thrown when system is out of memory. /// Thrown when method is failed due to an invalid parameter. /// Thrown when the method failed due to invalid operation. static public IEnumerable GetWiFiConfigurations() { return WiFiManagerImpl.Instance.GetWiFiConfigurations(); } /// /// Saves Wi-Fi configuration of access point. /// /// 3 /// The configuration to be stored /// http://tizen.org/feature/network.wifi /// http://tizen.org/privilege/network.profile /// Thrown when WiFi is not supported. /// Thrown when permission is denied. /// Thrown when WiFiConfiguration is passed as null. /// Thrown when method is failed due to an invalid parameter. /// Thrown when the method failed due to invalid operation. static public void SaveWiFiConfiguration(WiFiConfiguration configuration) { WiFiManagerImpl.Instance.SaveWiFiNetworkConfiguration(configuration); } /// /// Gets the object of the connected WiFiAP. /// /// 3 /// The connected wifi access point(AP) information. /// http://tizen.org/feature/network.wifi /// http://tizen.org/privilege/network.get /// Thrown when WiFi is not supported. /// Thrown when permission is denied. /// Thrown when system is out of memory. /// Thrown when method is failed due to an invalid parameter. /// Thrown when the method failed due to invalid operation. static public WiFiAP GetConnectedAP() { return WiFiManagerImpl.Instance.GetConnectedAP(); } /// /// Activates Wi-Fi asynchronously. /// /// 3 /// A task indicating whether the Activate method is done or not. /// http://tizen.org/feature/network.wifi /// http://tizen.org/privilege/network.set /// http://tizen.org/privilege/network.get /// Thrown when WiFi is not supported. /// Thrown when permission is denied. /// Thrown when method is failed due to an invalid parameter. /// Thrown when the method failed due to invalid operation. static public Task ActivateAsync() { return WiFiManagerImpl.Instance.ActivateAsync(); } /// /// Activates Wi-Fi asynchronously and displays Wi-Fi picker (popup) when Wi-Fi is not automatically connected. /// /// 3 /// A task indicating whether the ActivateWithPicker method is done or not. /// http://tizen.org/feature/network.wifi /// http://tizen.org/privilege/network.set /// http://tizen.org/privilege/network.get /// Thrown when WiFi is not supported. /// Thrown when permission is denied. /// Thrown when method is failed due to an invalid parameter. /// Thrown when the method failed due to invalid operation. static public Task ActivateWithPickerAsync() { return WiFiManagerImpl.Instance.ActivateWithWiFiPickerTestedAsync(); } /// /// Deactivates Wi-Fi asynchronously. /// /// 3 /// A task indicating whether the Deactivate method is done or not. /// http://tizen.org/feature/network.wifi /// http://tizen.org/privilege/network.set /// http://tizen.org/privilege/network.get /// Thrown when WiFi is not supported. /// Thrown when permission is denied. /// Thrown when method is failed due to an invalid parameter. /// Thrown when the method failed due to invalid operation. static public Task DeactivateAsync() { return WiFiManagerImpl.Instance.DeactivateAsync(); } /// /// Starts scan asynchronously. /// /// 3 /// A task indicating whether the Scan method is done or not. /// http://tizen.org/feature/network.wifi /// http://tizen.org/privilege/network.set /// http://tizen.org/privilege/network.get /// Thrown when WiFi is not supported. /// Thrown when permission is denied. /// Thrown when method is failed due to an invalid parameter. /// Thrown when the method failed due to invalid operation. static public Task ScanAsync() { return WiFiManagerImpl.Instance.ScanAsync(); } /// /// Starts specific access point scan, asynchronously. /// /// 3 /// A task indicating whether the ScanSpecificAP method is done or not. /// The essid of hidden ap /// http://tizen.org/feature/network.wifi /// http://tizen.org/privilege/network.set /// http://tizen.org/privilege/network.get /// Thrown when WiFi is not supported. /// Thrown when permission is denied. /// Thrown when method is failed due to an invalid parameter. /// Thrown when the method failed due to invalid operation. static public Task ScanSpecificAPAsync(string essid) { return WiFiManagerImpl.Instance.ScanSpecificAPAsync(essid); } } }