[Bluetooth] Fix BluetoothProfileType enum mismatch issue (#5788)
authorWootak Jung <wootak.jung@samsung.com>
Mon, 4 Dec 2023 22:55:52 +0000 (07:55 +0900)
committerGitHub <noreply@github.com>
Mon, 4 Dec 2023 22:55:52 +0000 (07:55 +0900)
BluetoothProfileType enum does not match native bt_profile_e enum.

Signed-off-by: Wootak Jung <wootak.jung@samsung.com>
src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothDevice.cs
src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothStructs.cs

index 6f3586f..b7a83ae 100644 (file)
@@ -636,7 +636,7 @@ namespace Tizen.Network.Bluetooth
                 {
                     if (!profile.Equals(null))
                     {
-                        profileList.Add((BluetoothProfileType)profile);
+                        profileList.Add(BluetoothUtils.ConvertBtProfileToProfileType(profile));
                     }
                     return true;
                 };
@@ -670,7 +670,7 @@ namespace Tizen.Network.Bluetooth
             if (BluetoothAdapter.IsBluetoothEnabled)
             {
                 bool isConnected;
-                int ret = Interop.Bluetooth.IsProfileConnected(RemoteDeviceAddress, (int)profileType, out isConnected);
+                int ret = Interop.Bluetooth.IsProfileConnected(RemoteDeviceAddress, BluetoothUtils.ConvertProfileTypeToBtProfile(profileType), out isConnected);
                 if (ret != (int)BluetoothError.None)
                 {
                     Log.Error(Globals.LogTag, "Failed to get profile connected state, Error - " + (BluetoothError)ret);
index 60e63fd..b56a3ac 100644 (file)
@@ -465,6 +465,39 @@ namespace Tizen.Network.Bluetooth
 
             return connectionInfo;
         }
+
+        internal static int ConvertProfileTypeToBtProfile(BluetoothProfileType profileType)
+        {
+            return profileType switch
+            {
+                BluetoothProfileType.Rfcomm => 0x01,
+                BluetoothProfileType.AdvancedAudioDistribution => 0x02,
+                BluetoothProfileType.Headset => 0x04,
+                BluetoothProfileType.HumanInterfaceDevice => 0x08,
+                BluetoothProfileType.NetworkAccessPoint => 0x10,
+                BluetoothProfileType.AudioGateway => 0x20,
+                BluetoothProfileType.GenericAttribute => 0x40,
+                BluetoothProfileType.NapServer => 0x80,
+                BluetoothProfileType.AdvancedAudioDistributionSink => 0x100,
+                _ => -1,
+            };
+        }
+
+        internal static BluetoothProfileType ConvertBtProfileToProfileType(int btProfile)
+        {
+            return btProfile switch
+            {
+                0x01 => BluetoothProfileType.Rfcomm,
+                0x02 => BluetoothProfileType.AdvancedAudioDistribution,
+                0x04 => BluetoothProfileType.Headset,
+                0x08 => BluetoothProfileType.HumanInterfaceDevice,
+                0x10 => BluetoothProfileType.NetworkAccessPoint,
+                0x20 => BluetoothProfileType.AudioGateway,
+                0x40 => BluetoothProfileType.GenericAttribute,
+                0x80 => BluetoothProfileType.NapServer,
+                0x100 => BluetoothProfileType.AdvancedAudioDistributionSink,
+            };
+        }
     }
 }