From cbb7e050c0ed8d4077ded3f81db512f6a6ab012a Mon Sep 17 00:00:00 2001 From: Wootak Jung Date: Tue, 5 Dec 2023 08:51:57 +0900 Subject: [PATCH] [Bluetooth] Fix BluetoothProfileType enum mismatch issue (#5785) BluetoothProfileType enum does not match native bt_profile_e enum. Signed-off-by: Wootak Jung --- .../Tizen.Network.Bluetooth/BluetoothDevice.cs | 4 +-- .../Tizen.Network.Bluetooth/BluetoothStructs.cs | 33 ++++++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothDevice.cs b/src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothDevice.cs index 6f3586f..b7a83ae 100644 --- a/src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothDevice.cs +++ b/src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothDevice.cs @@ -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); diff --git a/src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothStructs.cs b/src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothStructs.cs index 60e63fd..b56a3ac 100644 --- a/src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothStructs.cs +++ b/src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothStructs.cs @@ -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, + }; + } } } -- 2.7.4