/* * 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 the 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 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 Wi-Fi. /// 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 the Wi-Fi. /// 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 the Wi-Fi. /// 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 Wi-Fi 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 the 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 Wi-Fi 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 Wi-Fi safe handle. /// /// 3 /// The instance of the SafeWiFiManagerHandle. /// http://tizen.org/feature/network.wifi /// http://tizen.org/privilege/network.get /// Thrown when the Wi-Fi is not supported. /// Thrown when the permission is denied. /// Thrown when the system is out of memory. /// Thrown when the method failed due to an invalid parameter. /// Thrown when the method failed due to an invalid operation. [EditorBrowsable(EditorBrowsableState.Never)] public static SafeWiFiManagerHandle GetWiFiHandle() { return WiFiManagerImpl.Instance.GetSafeHandle(); } /// /// Gets the result of the scan. /// /// 3 /// A list of the WiFiAP objects. /// http://tizen.org/feature/network.wifi /// http://tizen.org/privilege/network.get /// Thrown when the Wi-Fi is not supported. /// Thrown when the permission is denied. /// Thrown when the method failed due to an invalid parameter. /// Thrown when the method failed due to an invalid operation. static public IEnumerable GetFoundAPs() { return WiFiManagerImpl.Instance.GetFoundAPs(); } /// /// Gets the result of a specific AP scan. /// /// 3 /// A list containing the WiFiAP objects. /// http://tizen.org/feature/network.wifi /// http://tizen.org/privilege/network.get /// Thrown when the Wi-Fi is not supported. /// Thrown when the permission is denied. /// Thrown when the method failed due to an invalid parameter. /// Thrown when the method failed due to an invalid operation. static public IEnumerable GetFoundSpecificAPs() { return WiFiManagerImpl.Instance.GetFoundSpecificAPs(); } /// /// Gets the list of Wi-Fi configurations. /// /// 3 /// A list containing the WiFiConfiguration objects. /// http://tizen.org/feature/network.wifi /// http://tizen.org/privilege/network.profile /// Thrown when the Wi-Fi is not supported. /// Thrown when the permission is denied. /// Thrown when system is out of memory. /// Thrown when the method failed due to an invalid parameter. /// Thrown when the method failed due to an invalid operation. static public IEnumerable GetWiFiConfigurations() { return WiFiManagerImpl.Instance.GetWiFiConfigurations(); } /// /// Saves the Wi-Fi configuration of the access point. /// /// 3 /// The configuration to be stored. /// http://tizen.org/feature/network.wifi /// http://tizen.org/privilege/network.profile /// Thrown when the Wi-Fi is not supported. /// Thrown when the permission is denied. /// Thrown when WiFiConfiguration is passed as null. /// Thrown when the method failed due to an invalid parameter. /// Thrown when the method failed due to an invalid operation. static public void SaveWiFiConfiguration(WiFiConfiguration configuration) { WiFiManagerImpl.Instance.SaveWiFiNetworkConfiguration(configuration); } /// /// Gets the object of the connected WiFiAP. /// /// 3 /// The connected Wi-Fi access point (AP) information. /// http://tizen.org/feature/network.wifi /// http://tizen.org/privilege/network.get /// Thrown when the Wi-Fi is not supported. /// Thrown when the permission is denied. /// Thrown when system is out of memory. /// Thrown when the method failed due to an invalid parameter. /// Thrown when the method failed due to an invalid operation. static public WiFiAP GetConnectedAP() { return WiFiManagerImpl.Instance.GetConnectedAP(); } /// /// Activates the 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 the Wi-Fi is not supported. /// Thrown when the permission is denied. /// Thrown when the method failed due to an invalid parameter. /// Thrown when the method failed due to an invalid operation. static public Task ActivateAsync() { return WiFiManagerImpl.Instance.ActivateAsync(); } /// /// Activates the Wi-Fi asynchronously and displays the Wi-Fi picker (popup) when the 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 the Wi-Fi is not supported. /// Thrown when the permission is denied. /// Thrown when the method failed due to an invalid parameter. /// Thrown when the method failed due to an invalid operation. static public Task ActivateWithPickerAsync() { return WiFiManagerImpl.Instance.ActivateWithWiFiPickerTestedAsync(); } /// /// Deactivates the 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 the Wi-Fi is not supported. /// Thrown when the permission is denied. /// Thrown when the method failed due to an invalid parameter. /// Thrown when the method failed due to an invalid operation. static public Task DeactivateAsync() { return WiFiManagerImpl.Instance.DeactivateAsync(); } /// /// Starts the 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 the Wi-Fi is not supported. /// Thrown when the permission is denied. /// Thrown when the method failed due to an invalid parameter. /// Thrown when the method failed due to an invalid operation. static public Task ScanAsync() { return WiFiManagerImpl.Instance.ScanAsync(); } /// /// Starts a specific access point scan asynchronously. /// /// 3 /// A task indicating whether the ScanSpecificAP method is done or not. /// The ESSID of the hidden AP. /// http://tizen.org/feature/network.wifi /// http://tizen.org/privilege/network.set /// http://tizen.org/privilege/network.get /// Thrown when the Wi-Fi is not supported. /// Thrown when the permission is denied. /// Thrown when the method failed due to an invalid parameter. /// Thrown when the method failed due to an invalid operation. static public Task ScanSpecificAPAsync(string essid) { return WiFiManagerImpl.Instance.ScanSpecificAPAsync(essid); } } }