[Bluetooth][Non-ACR] Fix BluetoothDevice data converting issue (#2885)
authorWootak Jung <wootak.jung@samsung.com>
Tue, 13 Apr 2021 02:25:44 +0000 (11:25 +0900)
committerGitHub <noreply@github.com>
Tue, 13 Apr 2021 02:25:44 +0000 (11:25 +0900)
Signed-off-by: Wootak Jung <wootak.jung@samsung.com>
src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothStructs.cs

index c8cebfd..c2966a9 100644 (file)
@@ -112,8 +112,7 @@ namespace Tizen.Network.Bluetooth
         [MarshalAsAttribute(UnmanagedType.LPStr)]
         internal string Address;
 
-        [MarshalAsAttribute(UnmanagedType.LPStr)]
-        internal string Name;
+        internal IntPtr Name;
 
         internal BluetoothClassStruct Class;
 
@@ -255,19 +254,24 @@ namespace Tizen.Network.Bluetooth
         {
             BluetoothDevice resultDevice = new BluetoothDevice();
             Collection<string> uuidList = null;
+            const int DeviceNameLengthMax = 248;
+            const int UuidLengthMax = 50;
 
             if (structDevice.ServiceCount > 0) {
                 IntPtr[] extensionList = new IntPtr[structDevice.ServiceCount];
                 Marshal.Copy (structDevice.ServiceUuidList, extensionList, 0, structDevice.ServiceCount);
                 uuidList = new Collection<string> ();
                 foreach (IntPtr extension in extensionList) {
-                    string uuid = Marshal.PtrToStringAnsi (extension);
-                    uuidList.Add (uuid);
+                    if (extension != IntPtr.Zero)
+                    {
+                        string uuid = Marshal.PtrToStringAnsi(extension, UuidLengthMax);
+                        uuidList.Add(uuid);
+                    }
                 }
             }
 
             resultDevice.RemoteDeviceAddress = structDevice.Address;
-            resultDevice.RemoteDeviceName = structDevice.Name;
+            resultDevice.RemoteDeviceName = Marshal.PtrToStringAnsi(structDevice.Name, DeviceNameLengthMax);
 
             resultDevice.RemoteDeviceClass = new BluetoothClass();
             resultDevice.Class.MajorType = structDevice.Class.MajorDeviceClassType;