[Bluetooth][Non-ACR] Fix GattConnection event not occured issue (#1735)
authorwootak <wootak.jung@samsung.com>
Mon, 22 Jun 2020 23:59:22 +0000 (08:59 +0900)
committerGitHub <noreply@github.com>
Mon, 22 Jun 2020 23:59:22 +0000 (08:59 +0900)
Signed-off-by: Wootak Jung <wootak.jung@samsung.com>
src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothGatt.cs
src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothLeAdapter.cs

index 1385dd1..bb7bb75 100644 (file)
@@ -261,11 +261,19 @@ namespace Tizen.Network.Bluetooth
         private static event EventHandler<GattConnectionStateChangedEventArgs> s_connectionStateChanged;
         private static Interop.Bluetooth.GattConnectionStateChangedCallBack s_connectionStateChangeCallback;
 
-        internal BluetoothGattClient(string remoteAddress)
+        internal BluetoothGattClient(string remoteAddress, bool fromLe)
         {
             _impl = new BluetoothGattClientImpl(remoteAddress);
             _remoteAddress = remoteAddress;
-            StaticConnectionStateChanged += OnConnectionStateChanged;
+            if (fromLe == false)
+            {
+                StaticConnectionStateChanged += OnConnectionStateChanged;
+            }
+            else
+            {
+                // fromLe will be removed after BluetoothLeDevice.GattConnect removed for backward compatibility.
+                // BluetoothLeDevice.GattConnectionStateChanged event will be occured in this case.
+            }
         }
 
         /// <summary>
@@ -279,7 +287,13 @@ namespace Tizen.Network.Bluetooth
         /// <since_tizen> 6 </since_tizen>
         public static BluetoothGattClient CreateClient(string remoteAddress)
         {
-            BluetoothGattClient client = new BluetoothGattClient(remoteAddress);
+            BluetoothGattClient client = new BluetoothGattClient(remoteAddress, false);
+            return client.Isvalid() ? client : null;
+        }
+
+        internal static BluetoothGattClient CreateClient(string remoteAddress, bool fromLe)
+        {
+            BluetoothGattClient client = new BluetoothGattClient(remoteAddress, fromLe);
             return client.Isvalid() ? client : null;
         }
 
index c603bf8..6b7a28a 100644 (file)
@@ -514,7 +514,7 @@ namespace Tizen.Network.Bluetooth {
                 }
                 else
                 {
-                    client = BluetoothGattClient.CreateClient(_remoteAddress);
+                    client = BluetoothGattClient.CreateClient(_remoteAddress, true);
                 }
             }
             else