From 4caef98a98ca090d43c51a24b892a0250bbfe226 Mon Sep 17 00:00:00 2001 From: Wootak Jung Date: Tue, 5 Dec 2023 07:56:03 +0900 Subject: [PATCH] [Bluetooth] Fix BluetoothProfileType enum mismatch issue (#5789) 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 | 54 ++++++++++++++++++++++ 2 files changed, 56 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..4cd2f34 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((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); diff --git a/src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothStructs.cs b/src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothStructs.cs index 60e63fd..f51f3b3 100644 --- a/src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothStructs.cs +++ b/src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothStructs.cs @@ -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; + } + } } } -- 2.7.4