/* * 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; namespace Tizen.Network.WiFiDirect { /// /// A class which is used to manage settings of Wi-Fi Direct.
/// This class is used to discover peer devices and manage settings of Wi-Fi Direct. ///
/// http://tizen.org/privilege/wifidirect public static class WiFiDirectManager { /// /// A property to check whether the device is group owner or not. /// /// /// Wi-Fi Direct must be activated. /// If it is deactivated, false will be returned. /// public static bool IsGroupOwner { get { if (Globals.IsActivated) { return WiFiDirectManagerImpl.Instance.IsGroupOwner; } else { return false; } } } /// /// A property to check whether the current group is the autonomous group or not. /// /// /// Wi-Fi Direct must be activated. /// If it is deactivated, false will be returned. /// public static bool IsAutonomousGroup { get { if (Globals.IsActivated) { return WiFiDirectManagerImpl.Instance.IsAutonomousGroup; } else { return false; } } } /// /// SSID of local device. /// /// /// If there is any error, null will be returned. /// /// Thrown while setting this property when the wifidirect is not supported public static string Ssid { get { if (Globals.IsInitialize) { return WiFiDirectManagerImpl.Instance.Ssid; } else { return null; } } } /// /// Name of network interface. /// /// /// Wi-Fi Direct must be activated. /// If it is deactivated, null will be returned. /// public static string NetworkInterface { get { if (Globals.IsActivated) { return WiFiDirectManagerImpl.Instance.NetworkInterface; } else { return null; } } } /// /// IP address of a local device. /// /// /// Wi-Fi Direct must be activated. /// If it is deactivated, null will be returned. /// public static string IpAddress { get { if (Globals.IsActivated) { return WiFiDirectManagerImpl.Instance.IpAddress; } else { return null; } } } /// /// Subnet mask. /// /// /// Wi-Fi Direct must be activated. /// If it is deactivated, null will be returned. /// public static string SubnetMask { get { if (Globals.IsActivated) { return WiFiDirectManagerImpl.Instance.SubnetMask; } else { return null; } } } /// /// Gateway address. /// /// /// Wi-Fi Direct must be activated. /// If it is deactivated, null will be returned. /// public static string GatewayAddress { get { if (Globals.IsActivated) { return WiFiDirectManagerImpl.Instance.GatewayAddress; } else { return null; } } } /// /// Mac address of a local device. /// /// /// If there is any error, null will be returned. /// /// Thrown while setting this property when the wifidirect is not supported public static string MacAddress { get { if (Globals.IsInitialize) { return WiFiDirectManagerImpl.Instance.MacAddress; } else { return null; } } } /// /// State of Wi-Fi direct service. /// public static WiFiDirectState State { get { return WiFiDirectManagerImpl.Instance.State; } } /// /// A property to check whether the device is discoverable or not by P2P discovery. /// public static bool IsDiscoverable { get { if (Globals.IsInitialize) { return WiFiDirectManagerImpl.Instance.IsDiscoverable; } else { return false; } } } /// /// A property to check whether the local device is listening only. /// /// /// Wi-Fi Direct must be activated. /// If it is deactivated, false will be returned. /// public static bool IsListenOnly { get { if (Globals.IsActivated) { return WiFiDirectManagerImpl.Instance.IsListenOnly; } else { return false; } } } /// /// Primary device type of local device. /// /// /// If there is any error, 0 will be returned. /// public static WiFiDirectPrimaryDeviceType PrimaryType { get { if (Globals.IsInitialize) { return WiFiDirectManagerImpl.Instance.PrimaryType; } else { return default(WiFiDirectPrimaryDeviceType); } } } /// /// Secondary device type of local device. /// /// /// If there is any error, 0 will be returned. /// public static WiFiDirectSecondaryDeviceType SecondaryType { get { if (Globals.IsInitialize) { return WiFiDirectManagerImpl.Instance.SecondaryType; } else { return default(WiFiDirectSecondaryDeviceType); } } } /// /// Supported WPS (Wi-Fi Protected Setup) types at local device. /// /// /// If there is any error, -1 will be returned. /// /// Thrown while setting this property when the wifidirect is not supported public static int WpsMode { get { if (Globals.IsInitialize) { return WiFiDirectManagerImpl.Instance.WpsMode; } else { return -1; } } } /// /// WPS (Wi-Fi Protected Setup) type. /// public static WiFiDirectWpsType Wps { get { if (Globals.IsInitialize) { return WiFiDirectManagerImpl.Instance.WpsType; } else { return default(WiFiDirectWpsType); } } } /// /// Channel number on which the P2P Device is operating as the P2P Group. /// /// /// If there is any error, -1 will be returned. /// public static int OperatingChannel { get { if (Globals.IsInitialize) { return WiFiDirectManagerImpl.Instance.OperatingChannel; } else { return -1; } } } /// /// A property to check whether persistent group is enabled. /// /// Thrown while setting this property when the wifidirect is not supported public static bool PersistentGroupEnabled { get { if (Globals.IsInitialize) { return WiFiDirectManagerImpl.Instance.PersistentGroupEnabled; } else { return false; } } set { if (Globals.IsInitialize) { WiFiDirectManagerImpl.Instance.PersistentGroupEnabled = value; } } } /// /// Autoconnection mode status. /// /// Thrown while setting this property when the wifidirect is not supported public static bool AutoConnect { get { if (Globals.IsInitialize) { return WiFiDirectManagerImpl.Instance.AutoConnect; } else { return false; } } set { if (Globals.IsInitialize) { WiFiDirectManagerImpl.Instance.AutoConnect = value; } } } /// /// WPS PIN number. /// /// /// Wi-Fi Direct must be activated. /// If it is deactivated, null will be returned during get and Not permitted exception message will be returned during set. /// /// Thrown while setting this property when the wifidirect is not supported public static string WpsPin { get { if (Globals.IsActivated) { return WiFiDirectManagerImpl.Instance.WpsPin; } else { return null; } } set { if (Globals.IsActivated) { WiFiDirectManagerImpl.Instance.WpsPin = value; } else { Log.Error(Globals.LogTag, "Wifi-direct is not activated"); WiFiDirectErrorFactory.ThrowWiFiDirectException((int)WiFiDirectError.NotPermitted); } } } /// /// Name of local device. /// /// Thrown while setting this property when the wifidirect is not supported public static string Name { get { if (Globals.IsInitialize) { return WiFiDirectManagerImpl.Instance.Name; } else { return null; } } set { if (Globals.IsInitialize) { WiFiDirectManagerImpl.Instance.Name = value; } } } /// /// Requested WPS (Wi-Fi Protected Setup) type. /// /// Thrown while setting this property when the wifidirect is not supported public static WiFiDirectWpsType RequestedWps { get { if (Globals.IsInitialize) { return WiFiDirectManagerImpl.Instance.RequestedWps; } else { return default(WiFiDirectWpsType); } } set { if (Globals.IsInitialize) { WiFiDirectManagerImpl.Instance.RequestedWps = value; } } } /// /// Intent of the group owner. /// /// Thrown while setting this property when the wifidirect is not supported public static int GroupOwnerIntent { get { if (Globals.IsInitialize) { return WiFiDirectManagerImpl.Instance.GroupOwnerIntent; } else { return -1; } } set { if (Globals.IsInitialize) { WiFiDirectManagerImpl.Instance.GroupOwnerIntent = value; } } } /// /// Max number of clients. /// /// Thrown while setting this property when the wifidirect is not supported public static int MaxClients { get { if (Globals.IsInitialize) { return WiFiDirectManagerImpl.Instance.MaxClients; } else { return -1; } } set { if (Globals.IsInitialize) { WiFiDirectManagerImpl.Instance.MaxClients = value; } } } /// /// Wi-Fi Protected Access (WPA) password. /// It is used during Wi-Fi Direct Group creation. /// /// /// Wi-Fi Direct must be activated. /// If it is deactivated, null will be returned during get and Not permitted exception message will be returned during set. /// /// Thrown while setting this property when the wifidirect is not supported public static string Passphrase { get { if (Globals.IsActivated) { return WiFiDirectManagerImpl.Instance.Passphrase; } else { return null; } } set { if (Globals.IsActivated) { WiFiDirectManagerImpl.Instance.Passphrase = value; } else { Log.Error(Globals.LogTag, "Wi-Fi direct is not activated"); WiFiDirectErrorFactory.ThrowWiFiDirectException((int)WiFiDirectError.NotPermitted); } } } /// /// Connection session timer value in second. /// /// /// Wi-Fi Direct must be activated. /// If it is deactivated, -1 will be returned during get and Not permitted exception message will be returned during set. /// /// Thrown while setting this property when the wifidirect is not supported public static int SessionTimer { get { if (Globals.IsActivated) { return WiFiDirectManagerImpl.Instance.SessionTimer; } else { return -1; } } set { if (Globals.IsActivated) { WiFiDirectManagerImpl.Instance.SessionTimer = value; } else { Log.Error(Globals.LogTag, "Wi-Fi direct is not activated"); WiFiDirectErrorFactory.ThrowWiFiDirectException((int)WiFiDirectError.NotPermitted); } } } /// /// (event) StateChanged is raised when Wi-Fi Direct state is changed. /// public static event EventHandler StateChanged { add { WiFiDirectManagerImpl.Instance.StateChanged += value; } remove { WiFiDirectManagerImpl.Instance.StateChanged -= value; } } /// /// (event) DiscoveryStateChanged is raised when Wi-Fi Direct discovery state is changed. /// public static event EventHandler DiscoveryStateChanged { add { if (Globals.IsInitialize) { WiFiDirectManagerImpl.Instance.DiscoveryStateChanged += value; } } remove { if (Globals.IsInitialize) { WiFiDirectManagerImpl.Instance.DiscoveryStateChanged -= value; } } } /// /// (event) DeviceStateChanged is raised when device state is changed. /// public static event EventHandler DeviceStateChanged { add { if (Globals.IsInitialize) { WiFiDirectManagerImpl.Instance.DeviceStateChanged += value; } } remove { if (Globals.IsInitialize) { WiFiDirectManagerImpl.Instance.DeviceStateChanged -= value; } } } /// /// (event) PeerFound is raised when peer is found. /// public static event EventHandler PeerFound { add { if (Globals.IsInitialize) { WiFiDirectManagerImpl.Instance.PeerFound += value; } } remove { if (Globals.IsInitialize) { WiFiDirectManagerImpl.Instance.PeerFound -= value; } } } /// /// (event) ConnectionStatusChanged is raised when status of connection is changed. /// public static event EventHandler ConnectionStatusChanged { add { if (Globals.IsInitialize) { WiFiDirectManagerImpl.Instance.ConnectionStatusChanged += value; } } remove { if (Globals.IsInitialize) { WiFiDirectManagerImpl.Instance.ConnectionStatusChanged -= value; } } } /// /// Activates the Wi-Fi Direct service. /// /// /// If this succeeds, DeviceStateChanged event will be invoked. /// /// Thrown when the wifidirect is not supported public static void Activate() { if (Globals.IsInitialize) { WiFiDirectManagerImpl.Instance.Activate(); } else { Log.Error(Globals.LogTag, "Wi-Fi direct is not initialized"); WiFiDirectErrorFactory.ThrowWiFiDirectException((int)WiFiDirectError.NotInitialized); } } /// /// Deactivates the Wi-Fi Direct service. /// /// /// Wi-Fi Direct must be activated. /// If this succeeds, DeviceStateChanged event will be invoked. /// /// Thrown when the wifidirect is not supported public static void Deactivate() { if (Globals.IsActivated) { WiFiDirectManagerImpl.Instance.Deactivate(); } else { Log.Error(Globals.LogTag, "Wi-Fi direct is not activated"); WiFiDirectErrorFactory.ThrowWiFiDirectException((int)WiFiDirectError.NotPermitted); } } /// /// Starts discovery to find all P2P capable devices. /// /// /// Wi-Fi Direct must be activated. /// If this succeeds, DiscoveryStateChanged and PeerFound event will be invoked. /// /// Thrown when the wifidirect is not supported /// Listen status.If False, then cycle between Scan and Listen.If True, then skip the initial 802.11 Scan and enter Listen state. /// Duration of discovery period, in seconds. /// Discovery channel.It is optional, default enum value FullScan is assigned. public static void StartDiscovery(bool listenOnly, int duration, WiFiDirectDiscoveryChannel channel = WiFiDirectDiscoveryChannel.FullScan) { if (Globals.IsActivated) { WiFiDirectManagerImpl.Instance.StartDiscovery(listenOnly, duration, channel); } else { Log.Error(Globals.LogTag, "Wi-Fi direct is not activated"); WiFiDirectErrorFactory.ThrowWiFiDirectException((int)WiFiDirectError.NotPermitted); } } /// /// Cancels discovery process. /// /// /// Discovery must be started by StartDiscovery. /// If this succeeds, DiscoveryStateChanged and PeerFound event will be invoked. /// /// Thrown when the wifidirect is not supported public static void CancelDiscovery() { if (WiFiDirectManager.State == WiFiDirectState.Discovering) { WiFiDirectManagerImpl.Instance.CancelDiscovery(); } else { Log.Error(Globals.LogTag, "Wi-Fi direct discovery is not started"); WiFiDirectErrorFactory.ThrowWiFiDirectException((int)WiFiDirectError.NotPermitted); } } /// /// Gets the information of discovered peers. /// /// /// Wi-Fi Direct must be activated. /// /// Thrown when the wifidirect is not supported /// List of discovered peer objects. public static IEnumerable GetDiscoveredPeers() { if (Globals.IsActivated) { return WiFiDirectManagerImpl.Instance.GetDiscoveredPeers(); } else { return null; } } /// /// Gets the information of connected peers. /// /// /// Wi-Fi Direct must be activated. /// /// Thrown when the wifidirect is not supported /// List of connected peer objects. public static IEnumerable GetConnectedPeers() { if (Globals.IsActivated) { return WiFiDirectManagerImpl.Instance.GetConnectedPeers(); } else { return null; } } /// /// Disconnects all connected links to peers. /// /// /// Wi-Fi Direct must be activated. /// If this succeeds, ConnectionStatusChanged event will be invoked. /// /// Thrown when the wifidirect is not supported public static void DisconnectAll() { if (Globals.IsActivated) { WiFiDirectManagerImpl.Instance.DisconnectAll(); } else { Log.Error(Globals.LogTag, "Wifi-direct is not activated"); WiFiDirectErrorFactory.ThrowWiFiDirectException((int)WiFiDirectError.NotPermitted); } } /// /// Creates a Wi-Fi Direct group and sets up device as the group owner. /// /// /// Wi-Fi Direct must be activated. /// If this succeeds, ConnectionStatusChanged event will be invoked with GroupCreated. /// /// Thrown when the wifidirect is not supported public static void CreateGroup() { if (Globals.IsActivated) { WiFiDirectManagerImpl.Instance.CreateGroup(); } else { Log.Error(Globals.LogTag, "Wifi-direct is not activated"); WiFiDirectErrorFactory.ThrowWiFiDirectException((int)WiFiDirectError.NotPermitted); } } /// /// Destroys the Wi-Fi Direct group owned by a local device.If creating a group is in progress, this API cancels that process. /// /// /// Wi-Fi Direct must be activated. /// If this succeeds, ConnectionStatusChanged event will be invoked with GroupDestroyed. /// /// Thrown when the wifidirect is not supported public static void DestroyGroup() { if (Globals.IsActivated) { WiFiDirectManagerImpl.Instance.DestroyGroup(); } else { Log.Error(Globals.LogTag, "Wifi-direct is not activated"); WiFiDirectErrorFactory.ThrowWiFiDirectException((int)WiFiDirectError.NotPermitted); } } /// /// Set the WPS config PBC as preferred method for connection. /// /// Thrown when the wifidirect is not supported public static void ActivatePushButton() { if (Globals.IsActivated) { WiFiDirectManagerImpl.Instance.ActivatePushButton(); } else { Log.Error(Globals.LogTag, "Wifi-direct is not activated"); WiFiDirectErrorFactory.ThrowWiFiDirectException((int)WiFiDirectError.NotPermitted); } } /// /// Gets the supported WPS types. /// /// Thrown when the wifidirect is not supported /// The list of supported wps types. public static IEnumerable GetSupportedWpsTypes() { if (Globals.IsInitialize) { return WiFiDirectManagerImpl.Instance.GetSupportedWpsTypes(); } else { return null; } } /// /// Gets the persistent groups. /// /// Thrown when the wifidirect is not supported /// List of the persistent group objects. public static IEnumerable GetPersistentGroups() { if (Globals.IsInitialize) { return WiFiDirectManagerImpl.Instance.GetPersistentGroups(); } else { return null; } } /// /// Removes a persistent group. /// /// Thrown when the wifidirect is not supported /// Persistent group owner. public static void RemovePersistentGroup(WiFiDirectPersistentGroup group) { if (Globals.IsInitialize) { WiFiDirectManagerImpl.Instance.RemovePersistentGroup(group); } else { Log.Error(Globals.LogTag, "Wifi-direct is not activated"); WiFiDirectErrorFactory.ThrowWiFiDirectException((int)WiFiDirectError.NotInitialized); } } /// /// Initializes or Deintializes the WiFi-Direct Display(MIRACAST) service. /// /// /// Wi-Fi Direct must be activated. /// /// /// Thrown during one of the following cases : /// 1. When the wifidirect is not supported /// 2. When the wifidirect display feature is not supported /// /// Enables/Disables service. public static void InitMiracast(bool enable) { if (Globals.IsActivated) { WiFiDirectManagerImpl.Instance.InitMiracast(enable); } else { Log.Error(Globals.LogTag, "Wifi-direct is not activated"); WiFiDirectErrorFactory.ThrowWiFiDirectException((int)WiFiDirectError.NotPermitted); } } /// /// Enables Wi-Fi Display functionality. /// /// /// Wi-Fi Direct must be activated. /// /// /// Thrown during one of the following cases : /// 1. When the wifidirect is not supported /// 2. When the wifidirect display feature is not supported /// public static void InitDisplay() { if (Globals.IsActivated) { WiFiDirectManagerImpl.Instance.InitDisplay(); } else { Log.Error(Globals.LogTag, "Wifi-direct is not activated"); WiFiDirectErrorFactory.ThrowWiFiDirectException((int)WiFiDirectError.NotPermitted); } } /// /// Disable Wi-Fi Display(WFD) functionality and disable the support of WFD Information Element(IE). /// /// /// Wi-Fi Direct must be activated and WFD must be enabled. /// /// /// Thrown during one of the following cases : /// 1. When the wifidirect is not supported /// 2. When the wifidirect display feature is not supported /// public static void DeinitDisplay() { if (Globals.IsActivated && Globals.s_isDisplay) { WiFiDirectManagerImpl.Instance.DeinitDisplay(); } else { Log.Error(Globals.LogTag, "Wifi-direct is not activated and/or Wi-Fi display is not enabled"); WiFiDirectErrorFactory.ThrowWiFiDirectException((int)WiFiDirectError.NotPermitted); } } /// /// Sets the Wi-Fi Display parameters for the WFD IE of local device. /// /// /// Wi-Fi Direct must be activated and WFD must be enabled. /// /// /// Thrown during one of the following cases : /// 1. When the wifidirect is not supported /// 2. When the wifidirect display feature is not supported /// /// WFD Device Type: define the Role of WFD device like source or sink. /// Specifies Session Management Control Port number. It should be 2 bytes(0~65535). /// CP support bit: (1 = enable the hdcp support, 0 = disable the hdcp support). public static void SetDisplay(WiFiDirectDisplayType type, int port, int hdcp) { if (Globals.IsActivated && Globals.s_isDisplay) { WiFiDirectManagerImpl.Instance.SetDisplay(type, port, hdcp); } else { Log.Error(Globals.LogTag, "Wifi-direct is not activated and/or Wi-Fi display is not enabled"); WiFiDirectErrorFactory.ThrowWiFiDirectException((int)WiFiDirectError.NotPermitted); } } /// /// Sets the Wi-Fi Display session availability. /// /// /// Wi-Fi Direct must be activated and WFD must be enabled. /// /// /// Thrown during one of the following cases : /// 1. When the wifidirect is not supported /// 2. When the wifidirect display feature is not supported /// /// Wi-Fi Display session availability. public static void SetDisplayAvailability(bool availability) { if (Globals.IsActivated && Globals.s_isDisplay) { WiFiDirectManagerImpl.Instance.SetDisplayAvailability(availability); } else { Log.Error(Globals.LogTag, "Wifi-direct is not activated and/or Wi-Fi display is not enabled"); WiFiDirectErrorFactory.ThrowWiFiDirectException((int)WiFiDirectError.NotPermitted); } } /// /// Sets the automatic group removal feature when all peers are disconnected. /// /// /// Wi-Fi Direct must be activated. /// ConnectionStatusChanged event will be invoked with GroupDestroyed when this feature is enabled and there's no connected group client and if device is group owner. /// /// Thrown when the wifidirect is not supported /// Enables/Disables group removal feature. public static void SetAutoGroupRemove(bool enable) { if (Globals.IsActivated) { WiFiDirectManagerImpl.Instance.SetAutoGroupRemove(enable); } else { Log.Error(Globals.LogTag, "Wifi-direct is not activated"); WiFiDirectErrorFactory.ThrowWiFiDirectException((int)WiFiDirectError.NotPermitted); } } /// /// Registers the service. /// /// /// Wi-Fi Direct must be activated. /// If there is any error while registering service, 0 will be returned. /// /// /// Thrown during one of the following cases : /// 1. When the wifidirect is not supported /// 2. When the wifidirect service discovery is not supported /// /// The service Id of service getting registered. /// Type of Wi-Fi Direct Service. /// Service specific information. /// Service information. public static uint RegisterService(WiFiDirectServiceType type, string info, string serviceInfo) { if (Globals.IsActivated) { return WiFiDirectManagerImpl.Instance.RegisterService(type, info, serviceInfo); } else { return 0; } } /// /// Deregisters for a service used for WiFi Direct Service Discovery. /// /// /// Wi-Fi Direct must be activated. /// /// /// Thrown during one of the following cases : /// 1. When the wifidirect is not supported /// 2. When the wifidirect service discovery is not supported /// /// Service ID for which service has to be deregistered. public static void DeregisterService(uint serviceId) { if (Globals.IsActivated) { WiFiDirectManagerImpl.Instance.DeregisterService(serviceId); } else { Log.Error(Globals.LogTag, "Wifi-direct is not activated"); WiFiDirectErrorFactory.ThrowWiFiDirectException((int)WiFiDirectError.NotPermitted); } } } }