Add C# internal APIs (#6064)
authoranujk-singh <115205617+anujk-singh@users.noreply.github.com>
Mon, 29 Apr 2024 07:15:38 +0000 (12:45 +0530)
committerGitHub <noreply@github.com>
Mon, 29 Apr 2024 07:15:38 +0000 (16:15 +0900)
* Add C# internal APIs

API List:
bt_adapter_set_authentication_req_cb
bt_adapter_unset_authentication_req_cb
bt_adapter_passkey_confirmation_reply

Signed-off-by: Anuj Kumar Singh <anujk.singh@samsung.com>
* Add C# internal APIs

API List:
bt_adapter_set_authentication_req_cb
bt_adapter_unset_authentication_req_cb
bt_adapter_passkey_confirmation_reply

Signed-off-by: Anuj Kumar Singh <anujk.singh@samsung.com>
* add invisible tag to function the public class AuthenticationRequestedEventArgs

Signed-off-by: anujk-singh <anujk.singh@samsung.com>
---------

Signed-off-by: Anuj Kumar Singh <anujk.singh@samsung.com>
Signed-off-by: anujk-singh <anujk.singh@samsung.com>
src/Tizen.Network.Bluetooth/Interop/Interop.Bluetooth.cs
src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothAdapter.cs
src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothAdapterImpl.cs
src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothEnumerations.cs
src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothEventArgs.cs

index 52a5a97..78c549b 100644 (file)
@@ -24,6 +24,8 @@ internal static partial class Interop
     {
         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
         internal delegate void StateChangedCallback(int result, int state, IntPtr userData);
+        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+        internal delegate void AuthenticationRequestedCallback(int result, AuthenticationInfoType authType, string deviceName, string remoteAddr, string passKey, IntPtr userData);
 
         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
         internal delegate void NameChangedCallback(string deviceName, IntPtr userData);
@@ -168,6 +170,12 @@ internal static partial class Interop
         internal static extern int SetDiscoveryStateChangedCallback(DiscoveryStateChangedCallback discoveryChangedCb, IntPtr userData);
         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_unset_device_discovery_state_changed_cb")]
         internal static extern int UnsetDiscoveryStateChangedCallback();
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_passkey_confirmation_reply")]
+        internal static extern int PasskeyConfirmationReply(bool confirmationReply);
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_set_authentication_req_cb")]
+        internal static extern int SetAuthenticationRequestedCallback(AuthenticationRequestedCallback stateChangedCb, IntPtr userData);
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_unset_authentication_req_cb")]
+        internal static extern int UnsetAuthenticationRequestedCallback();
 
         //Bluetooth Device
         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_device_create_bond")]
index dd1f4bb..5ec27d9 100644 (file)
@@ -213,6 +213,39 @@ namespace Tizen.Network.Bluetooth
         }
 
         /// <summary>
+        /// The AuthenticationChanged event is raised when the Bluetooth adapter authentication is changed.
+        /// </summary>
+        /// <exception cref="NotSupportedException">Thrown when the Bluetooth is not supported.</exception>
+        /// <exception cref="InvalidOperationException">Thrown when the Bluetooth is not enabled.</exception>
+        /// <since_tizen> 9 </since_tizen>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        static public event EventHandler<AuthenticationRequestedEventArgs> AuthenticationChanged
+        {
+            add
+            {
+                try
+                {
+                    BluetoothAdapterImpl.Instance.AuthenticationChanged += value;
+                }
+                catch (TypeInitializationException e)
+                {
+                    throw e.InnerException;
+                }
+            }
+            remove
+            {
+                try
+                {
+                    BluetoothAdapterImpl.Instance.AuthenticationChanged -= value;
+                }
+                catch (TypeInitializationException e)
+                {
+                    throw e.InnerException;
+                }
+            }
+        }
+
+        /// <summary>
         /// The NameChanged event is raised when the Bluetooth adapter name is changed.
         /// </summary>
         /// <exception cref="NotSupportedException">Thrown when the Bluetooth is not supported.</exception>
index d74b045..198bb14 100644 (file)
@@ -37,6 +37,7 @@ namespace Tizen.Network.Bluetooth
         private event EventHandler<VisibilityModeChangedEventArgs> _visibilityModeChanged;
         private event EventHandler<VisibilityDurationChangedEventArgs> _visibilityDurationChanged;
         private event EventHandler<DiscoveryStateChangedEventArgs> _discoveryStateChanged;
+        private event EventHandler<AuthenticationRequestedEventArgs> _authenticationRequested;
 
         private Interop.Bluetooth.StateChangedCallback _stateChangedCallback;
         private Interop.Bluetooth.NameChangedCallback _nameChangedCallback;
@@ -44,6 +45,7 @@ namespace Tizen.Network.Bluetooth
         private Interop.Bluetooth.VisibilityDurationChangedCallback _visibilitydurationChangedCallback;
         private Interop.Bluetooth.DiscoveryStateChangedCallback _discoveryStateChangedCallback;
         private Interop.Bluetooth.BondedDeviceCallback _bondedDeviceCallback;
+        private Interop.Bluetooth.AuthenticationRequestedCallback _authenticationRequestedCallback;
 
         private static readonly BluetoothAdapterImpl _instance = new BluetoothAdapterImpl();
         private bool disposed = false;
@@ -68,6 +70,26 @@ namespace Tizen.Network.Bluetooth
             }
         }
 
+        internal event EventHandler<AuthenticationRequestedEventArgs> AuthenticationChanged
+        {
+            add
+            {
+                if (_authenticationRequested == null)
+                {
+                    RegisterAuthenticationRequestedEvent();
+                }
+                _authenticationRequested += value;
+            }
+            remove
+            {
+                _authenticationRequested -= value;
+                if (_stateChanged == null)
+                {
+                    UnregisterAuthenticationRequestedEvent();
+                }
+            }
+        }
+
         internal event EventHandler<NameChangedEventArgs> NameChanged
         {
             add
@@ -175,6 +197,33 @@ namespace Tizen.Network.Bluetooth
             }
         }
 
+        private void RegisterAuthenticationRequestedEvent()
+        {
+            _authenticationRequestedCallback = (int result, AuthenticationInfoType authType, string deviceName, string remoteAddr, string passKey, IntPtr userData) =>
+            {
+                if (_authenticationRequested != null)
+                {
+                    AuthenticationInfoType at = authType;
+                    BluetoothError res = (BluetoothError)result;
+                    _authenticationRequested(null, new AuthenticationRequestedEventArgs(res, at, deviceName, remoteAddr, passKey));
+                }
+            };
+            int ret = Interop.Bluetooth.SetAuthenticationRequestedCallback(_authenticationRequestedCallback, IntPtr.Zero);
+            if (ret != (int)BluetoothError.None)
+            {
+                Log.Error(Globals.LogTag, "Failed to set authentication request callback, Error - " + (BluetoothError)ret);
+            }
+        }
+
+        private void UnregisterAuthenticationRequestedEvent()
+        {
+            int ret = Interop.Bluetooth.UnsetAuthenticationRequestedCallback();
+            if (ret != (int)BluetoothError.None)
+            {
+                Log.Error(Globals.LogTag, "Failed to unset authentication request callback, Error - " + (BluetoothError)ret);
+            }
+        }
+
         private void RegisterNameChangedEvent()
         {
             _nameChangedCallback = (string deviceName, IntPtr userData) =>
@@ -577,6 +626,16 @@ namespace Tizen.Network.Bluetooth
             }
         }
 
+        internal void PasskeyConfirmationReply(bool confirmationReply)
+        {
+            int ret = Interop.Bluetooth.PasskeyConfirmationReply(confirmationReply);
+            if (ret != (int)BluetoothError.None)
+            {
+                Log.Error(Globals.LogTag, "Failed to passkey confirmation reply, Error - " + (BluetoothError)ret);
+                BluetoothErrorFactory.ThrowBluetoothException(ret);
+            }
+        }
+
         internal BluetoothServerSocket CreateServerSocket(string serviceUuid)
         {
             int socketFd;
index 3f070d4..8efab31 100644 (file)
@@ -1384,4 +1384,25 @@ namespace Tizen.Network.Bluetooth
         /// </summary>
         Output
     }
+
+    /// <summary>
+    /// Enumeration for the authentication info type.
+    /// </summary>
+    /// <since_tizen> 9 </since_tizen>
+    [EditorBrowsable(EditorBrowsableState.Never)]
+    public enum AuthenticationInfoType
+    {
+        /// <summary>
+        /// PIN display event to user for entering PIN in keyboard
+        /// </summary>
+        AuthKeyboardPasskeyDisplay = 0,
+        /// <summary>
+        /// Legacy PIN or PASSKEY request event
+        /// </summary>
+        AuthPinRequest,
+        /// <summary>
+        /// PASSKEY confirmation event to match PASSKEY in remote device
+        /// </summary>
+        AuthPasskeyConfirmRequest,
+    }
 }
index ec87eaa..fe4f095 100644 (file)
@@ -61,6 +61,89 @@ namespace Tizen.Network.Bluetooth
     }
 
     /// <summary>
+    /// An extended EventArgs class contains the changed Bluetooth authentication.
+    /// </summary>
+    /// <since_tizen> 9 </since_tizen>
+    [EditorBrowsable(EditorBrowsableState.Never)]
+    public class AuthenticationRequestedEventArgs : EventArgs
+    {
+        private AuthenticationInfoType _authType;
+        private BluetoothError _result;
+        private string _deviceName;
+        private string _remoteAddr;
+        private string _passKey;
+
+        internal AuthenticationRequestedEventArgs(BluetoothError result, AuthenticationInfoType type, string deviceName, string remoteAddr, string passKey)
+        {
+            _authType = type;
+            _result = result;
+            _deviceName = deviceName;
+            _remoteAddr = remoteAddr;
+            _passKey = passKey;
+        }
+
+        /// <summary>
+        /// The authentication of Bluetooth.
+        /// </summary>
+        /// <since_tizen> 9 </since_tizen>
+        public AuthenticationInfoType Authentication
+        {
+            get
+            {
+                return _authType;
+            }
+        }
+
+        /// <summary>
+        /// The BluetoothError result.
+        /// </summary>
+        /// <since_tizen> 9 </since_tizen>
+        public BluetoothError Result
+        {
+            get
+            {
+                return _result;
+            }
+        }
+
+        /// <summary>
+        /// The name of the device.
+        /// </summary>
+        /// <since_tizen> 9 </since_tizen>
+        public string DeviceName
+        {
+            get
+            {
+                return _deviceName;
+            }
+        }
+
+        /// <summary>
+        /// The Remote address of the device.
+        /// </summary>
+        /// <since_tizen> 9 </since_tizen>
+        public string RemoteAddr
+        {
+            get
+            {
+                return _remoteAddr;
+            }
+        }
+
+        /// <summary>
+        /// The pass key of the device.
+        /// </summary>
+        /// <since_tizen> 9 </since_tizen>
+        public string PassKey
+        {
+            get
+            {
+                return _passKey;
+            }
+        }
+    }
+
+    /// <summary>
     /// An extended EventArgs class contains the changed Bluetooth name.
     /// </summary>
     /// <since_tizen> 3 </since_tizen>