[Bluetooth] Fix BluetoothProfileType enum mismatch issue (#5789)
authorWootak Jung <wootak.jung@samsung.com>
Mon, 4 Dec 2023 22:56:03 +0000 (07:56 +0900)
committerGitHub <noreply@github.com>
Mon, 4 Dec 2023 22:56:03 +0000 (07:56 +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..4cd2f34 100644 (file)
@@ -636,7 +636,7 @@ namespace Tizen.Network.Bluetooth
                 {
                     if (!profile.Equals(null))
                     {
-                        profileList.Add((BluetoothProfileType)profile);
+                        profileList.Add((BluetoothProfileType)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..f51f3b3 100644 (file)
@@ -465,6 +465,60 @@ namespace Tizen.Network.Bluetooth
 
             return connectionInfo;
         }
+
+        internal static int ConvertProfileTypeToBtProfile(BluetoothProfileType profileType)
+        {
+            switch (profileType)
+            {
+                case BluetoothProfileType.Rfcomm:
+                    return 0x01;
+                case BluetoothProfileType.AdvancedAudioDistribution:
+                    return 0x02;
+                case BluetoothProfileType.Headset:
+                    return 0x04;
+                case BluetoothProfileType.HumanInterfaceDevice:
+                    return 0x08;
+                case BluetoothProfileType.NetworkAccessPoint:
+                    return 0x10;
+                case BluetoothProfileType.AudioGateway:
+                    return 0x20;
+                case BluetoothProfileType.GenericAttribute:
+                    return 0x40;
+                case BluetoothProfileType.NapServer:
+                    return 0x80;
+                case BluetoothProfileType.AdvancedAudioDistributionSink:
+                    return 0x100;
+                default:
+                    return -1;
+            }
+        }
+
+        internal static int ConvertBtProfileToProfileType(int btProfile)
+        {
+            switch (btProfile)
+            {
+                case 0x01:
+                    return (int)BluetoothProfileType.Rfcomm;
+                case 0x02:
+                    return (int)BluetoothProfileType.AdvancedAudioDistribution;
+                case 0x04:
+                    return (int)BluetoothProfileType.Headset;
+                case 0x08:
+                    return (int)BluetoothProfileType.HumanInterfaceDevice;
+                case 0x10:
+                    return (int)BluetoothProfileType.NetworkAccessPoint;
+                case 0x20:
+                    return (int)BluetoothProfileType.AudioGateway;
+                case 0x40:
+                    return (int)BluetoothProfileType.GenericAttribute;
+                case 0x80:
+                    return (int)BluetoothProfileType.NapServer;
+                case 0x100:
+                    return (int)BluetoothProfileType.AdvancedAudioDistributionSink;
+                default:
+                    return -1;
+            }
+        }
     }
 }