[Bluetooth][TCSACR-237] Add BluetoothLeDevice APIs (#779)
authorWootak <wootak.jung@samsung.com>
Fri, 12 Apr 2019 01:34:29 +0000 (10:34 +0900)
committerGitHub <noreply@github.com>
Fri, 12 Apr 2019 01:34:29 +0000 (10:34 +0900)
* Add BluetoothLeDevice APIs getting the remote device information
* Deprecated BluetoothLeDevice APIs getting the remote device information
ACR(Add): http://suprem.sec.samsung.net/jira/browse/TCSACR-237
ACR(Deprecated): http://suprem.sec.samsung.net/jira/browse/TCSACR-238

src/Tizen.Network.Bluetooth/Interop/Interop.Bluetooth.cs
src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothLeAdapter.cs
src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothLeAdapterImpl.cs

index 09fe238..66bac98 100755 (executable)
@@ -244,7 +244,7 @@ internal static partial class Interop
                             BluetoothLePacketType packetType, out int txPowerLevel);
 
         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_le_get_scan_result_service_solicitation_uuids")]
-        public static extern int GetScaResultSvcSolicitationUuids(ref BluetoothLeScanDataStruct scanData,
+        public static extern int GetScanResultSvcSolicitationUuids(ref BluetoothLeScanDataStruct scanData,
                             BluetoothLePacketType packetType, out IntPtr uuids, out int count);
 
         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_le_get_scan_result_service_data_list")]
index d2c8775..52a40a3 100644 (file)
@@ -247,6 +247,7 @@ namespace Tizen.Network.Bluetooth {
         /// The type of the packet.
         /// </summary>
         /// <since_tizen> 3 </since_tizen>
+        [Obsolete("Deprecated since API level 6. Please use new methods with this type on BluetoothLeDevice.")]
         public BluetoothLePacketType PacketType
         {
             get
@@ -269,20 +270,32 @@ namespace Tizen.Network.Bluetooth {
         /// <exception cref="NotSupportedException">Thrown when the Bluetooth LE is not supported.</exception>
         /// <exception cref="InvalidOperationException">Thrown when the Bluetooth LE is not enabled.</exception>
         /// <since_tizen> 3 </since_tizen>
+        [Obsolete("Deprecated since API level 6. Please use GetServiceUuid() method on BluetoothLeDevice.")]
         public IEnumerable<string> ServiceUuid
         {
             get
             {
-                if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
-                {
-                    Log.Info(Globals.LogTag, "Retrieving Service uuid- ");
-                    return BluetoothLeImplAdapter.Instance.GetLeScanResultServiceUuids(_scanData, _packetType);
-                }
-                return null;
+                return GetServiceUuid(_packetType);
             }
         }
 
         /// <summary>
+        /// Gets the service UUIDs list from the LE scan result information.
+        /// </summary>
+        /// <value> Gets the list of the string service UUIDs.</value>
+        /// <remarks>The Bluetooth must be enabled.</remarks>
+        /// <param name="packetType"> The enumeration for BLE packet type.</param>
+        /// <returns>The service uuid value</returns>
+        /// <feature>http://tizen.org/feature/network.bluetooth.le</feature>
+        /// <exception cref="NotSupportedException">Thrown when the Bluetooth LE is not supported.</exception>
+        /// <exception cref="InvalidOperationException">Thrown when the Bluetooth LE is not enabled.</exception>
+        /// <since_tizen> 6 </since_tizen>
+        public IEnumerable<string> GetServiceUuid(BluetoothLePacketType packetType)
+        {
+            return BluetoothLeImplAdapter.Instance.GetLeScanResultServiceUuids(_scanData, packetType);
+        }
+
+        /// <summary>
         /// Gets the device name from the LE scan result information.
         /// </summary>
         /// <value> Gets the device name.</value>
@@ -292,18 +305,31 @@ namespace Tizen.Network.Bluetooth {
         /// <exception cref="NotSupportedException">Thrown when the Bluetooth LE is not supported.</exception>
         /// <exception cref="InvalidOperationException">Thrown when the Bluetooth LE is not enabled.</exception>
         /// <since_tizen> 3 </since_tizen>
+        [Obsolete("Deprecated since API level 6. Please use GetDeviceName() method on BluetoothLeDevice.")]
         public string DeviceName
         {
             get
             {
-                Log.Info(Globals.LogTag, "Retrieving device name- ");
-                if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
-                {
-                    return BluetoothLeImplAdapter.Instance.GetLeScanResultDeviceName(_scanData, _packetType);
-                }
-                return null;
+                return GetDeviceName(_packetType);
             }
         }
+
+        /// <summary>
+        /// Gets the device name from the LE scan result information.
+        /// </summary>
+        /// <value> Gets the device name.</value>
+        /// <remarks>The Bluetooth must be enabled.</remarks>
+        /// <param name="packetType"> The enumeration for BLE packet type.</param>
+        /// <returns>The device name value</returns>
+        /// <feature>http://tizen.org/feature/network.bluetooth.le</feature>
+        /// <exception cref="NotSupportedException">Thrown when the Bluetooth LE is not supported.</exception>
+        /// <exception cref="InvalidOperationException">Thrown when the Bluetooth LE is not enabled.</exception>
+        /// <since_tizen> 6 </since_tizen>
+        public string GetDeviceName(BluetoothLePacketType packetType)
+        {
+            return BluetoothLeImplAdapter.Instance.GetLeScanResultDeviceName(_scanData, packetType);
+        }
+
         /// <summary>
         /// Gets the transmission power level from the LE scan result information.
         /// </summary>
@@ -314,19 +340,32 @@ namespace Tizen.Network.Bluetooth {
         /// <exception cref="NotSupportedException">Thrown when the Bluetooth LE is not supported.</exception>
         /// <exception cref="InvalidOperationException">Thrown when the Bluetooth LE is not enabled.</exception>
         /// <since_tizen> 3 </since_tizen>
+        [Obsolete("Deprecated since API level 6. Please use GetTxPowerLevel() method on BluetoothLeDevice.")]
         public int TxPowerLevel
         {
             get
             {
-                if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
-                {
-                    return BluetoothLeImplAdapter.Instance.GetScanResultTxPowerLevel(_scanData, _packetType);
-                }
-                return -1;
+                return GetTxPowerLevel(_packetType);
             }
         }
 
         /// <summary>
+        /// Gets the transmission power level from the LE scan result information.
+        /// </summary>
+        /// <value> Gets the transmission power level in dB.</value>
+        /// <remarks>The Bluetooth must be enabled.</remarks>
+        /// <param name="packetType"> The enumeration for BLE packet type.</param>
+        /// <returns>The tx power level value</returns>
+        /// <feature>http://tizen.org/feature/network.bluetooth.le</feature>
+        /// <exception cref="NotSupportedException">Thrown when the Bluetooth LE is not supported.</exception>
+        /// <exception cref="InvalidOperationException">Thrown when the Bluetooth LE is not enabled.</exception>
+        /// <since_tizen> 6 </since_tizen>
+        public int GetTxPowerLevel(BluetoothLePacketType packetType)
+        {
+            return BluetoothLeImplAdapter.Instance.GetScanResultTxPowerLevel(_scanData, packetType);
+        }
+
+        /// <summary>
         /// Gets the service solicitation UUID list from the scan result information.
         /// </summary>
         /// <value> Gets the list of the service solicitation UUIDs.</value>
@@ -336,17 +375,31 @@ namespace Tizen.Network.Bluetooth {
         /// <exception cref="NotSupportedException">Thrown when the Bluetooth LE is not supported.</exception>
         /// <exception cref="InvalidOperationException">Thrown when the Bluetooth LE is not enabled.</exception>
         /// <since_tizen> 3 </since_tizen>
+        [Obsolete("Deprecated since API level 6. Please use GetServiceSolicitationUuid() method on BluetoothLeDevice.")]
         public IEnumerable<string> ServiceSolictationUuid
         {
             get
             {
-                if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
-                {
-                    return BluetoothLeImplAdapter.Instance.GetScanResultSvcSolicitationUuids(_scanData, _packetType);
-                }
-                return null;
+                return GetServiceSolicitationUuid(_packetType);
             }
         }
+
+        /// <summary>
+        /// Gets the service solicitation UUID list from the scan result information.
+        /// </summary>
+        /// <value> Gets the list of the service solicitation UUIDs.</value>
+        /// <remarks>The Bluetooth must be enabled.</remarks>
+        /// <param name="packetType"> The enumeration for BLE packet type.</param>
+        /// <returns>The service solicitation uuid value</returns>
+        /// <feature>http://tizen.org/feature/network.bluetooth.le</feature>
+        /// <exception cref="NotSupportedException">Thrown when the Bluetooth LE is not supported.</exception>
+        /// <exception cref="InvalidOperationException">Thrown when the Bluetooth LE is not enabled.</exception>
+        /// <since_tizen> 6 </since_tizen>
+        public IEnumerable<string> GetServiceSolicitationUuid(BluetoothLePacketType packetType)
+        {
+            return BluetoothLeImplAdapter.Instance.GetScanResultSvcSolicitationUuids(_scanData, packetType);
+        }
+
         /// <summary>
         /// Gets the manufacturer data from the scan result information.
         /// </summary>
@@ -357,17 +410,31 @@ namespace Tizen.Network.Bluetooth {
         /// <exception cref="NotSupportedException">Thrown when the Bluetooth LE is not supported.</exception>
         /// <exception cref="InvalidOperationException">Thrown when the Bluetooth LE is not enabled.</exception>
         /// <since_tizen> 3 </since_tizen>
+        [Obsolete("Deprecated since API level 6. Please use GetAppearance() method on BluetoothLeDevice.")]
         public int Appearance
         {
             get
             {
-                if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
-                {
-                    return BluetoothLeImplAdapter.Instance.GetScanResultAppearance(_scanData, _packetType);
-                }
-                return -1;
+                return GetAppearance(_packetType);
             }
         }
+
+        /// <summary>
+        /// Gets the manufacturer data from the scan result information.
+        /// </summary>
+        /// <value> Gets the appearance value.</value>
+        /// <remarks>The Bluetooth must be enabled.</remarks>
+        /// <param name="packetType"> The enumeration for BLE packet type.</param>
+        /// <returns>The appearance value</returns>
+        /// <feature>http://tizen.org/feature/network.bluetooth.le</feature>
+        /// <exception cref="NotSupportedException">Thrown when the Bluetooth LE is not supported.</exception>
+        /// <exception cref="InvalidOperationException">Thrown when the Bluetooth LE is not enabled.</exception>
+        /// <since_tizen> 6 </since_tizen>
+        public int GetAppearance(BluetoothLePacketType packetType)
+        {
+            return BluetoothLeImplAdapter.Instance.GetScanResultAppearance(_scanData, packetType);
+        }
+
         /// <summary>
         /// Gets the manufacturer data from the scan result information.
         /// </summary>
@@ -378,19 +445,32 @@ namespace Tizen.Network.Bluetooth {
         /// <exception cref="NotSupportedException">Thrown when the Bluetooth LE is not supported.</exception>
         /// <exception cref="InvalidOperationException">Thrown when the Bluetooth LE is not enabled.</exception>/// 
         /// <since_tizen> 3 </since_tizen>
+        [Obsolete("Deprecated since API level 6. Please use GetManufacturerData() method on BluetoothLeDevice.")]
         public ManufacturerData ManufacturerData
         {
             get
             {
-                if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
-                {
-                    return BluetoothLeImplAdapter.Instance.GetScanResultManufacturerData(_scanData, _packetType);
-                }
-                return null;
+                return GetManufacturerData(_packetType);
             }
         }
 
         /// <summary>
+        /// Gets the manufacturer data from the scan result information.
+        /// </summary>
+        /// <value> Gets the manufacturer data containing the manucturer data and ID information.</value>
+        /// <remarks>The Bluetooth must be enabled.</remarks>
+        /// <param name="packetType"> The enumeration for BLE packet type.</param>
+        /// <returns>The manufacturer data object</returns>
+        /// <feature>http://tizen.org/feature/network.bluetooth.le</feature>
+        /// <exception cref="NotSupportedException">Thrown when the Bluetooth LE is not supported.</exception>
+        /// <exception cref="InvalidOperationException">Thrown when the Bluetooth LE is not enabled.</exception>/// 
+        /// <since_tizen> 6 </since_tizen>
+        public ManufacturerData GetManufacturerData(BluetoothLePacketType packetType)
+        {
+            return BluetoothLeImplAdapter.Instance.GetScanResultManufacturerData(_scanData, packetType);
+        }
+
+        /// <summary>
         /// Gets the service data list from the scan result information.
         /// </summary>
         /// <remarks>
@@ -400,17 +480,26 @@ namespace Tizen.Network.Bluetooth {
         /// <exception cref="NotSupportedException">Thrown when the Bluetooth LE is not supported.</exception>
         /// <exception cref="InvalidOperationException">Thrown when the Bluetooth LE is not enabled.</exception>
         /// <since_tizen> 3 </since_tizen>
+        [Obsolete("Deprecated since API level 6. Please use GetServiceDataList() method on BluetoothLeDevice.")]
         public IEnumerable<BluetoothLeServiceData> GetServiceDataList()
         {
-            int serviceCount = 0;
-            if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
-            {
-                return BluetoothLeImplAdapter.Instance.GetScanResultServiceDataList(_scanData,
-                                            _packetType, out serviceCount);
-            }
-            return null;
+            return GetServiceDataList(_packetType);
         }
 
+        /// <summary>
+        /// Gets the service data list from the scan result information.
+        /// </summary>
+        /// <remarks>The Bluetooth must be enabled.</remarks>
+        /// <param name="packetType"> The packet type.</param>
+        /// <returns> Returns the service data list.</returns>
+        /// <feature>http://tizen.org/feature/network.bluetooth.le</feature>
+        /// <exception cref="NotSupportedException">Thrown when the Bluetooth LE is not supported.</exception>
+        /// <exception cref="InvalidOperationException">Thrown when the Bluetooth LE is not enabled.</exception>
+        /// <since_tizen> 6 </since_tizen>
+        public IEnumerable<BluetoothLeServiceData> GetServiceDataList(BluetoothLePacketType packetType)
+        {
+            return BluetoothLeImplAdapter.Instance.GetScanResultServiceDataList(_scanData, packetType);
+        }
 
         /// <summary>
         /// Creates a GATT connection with the remote device.
@@ -651,6 +740,7 @@ namespace Tizen.Network.Bluetooth {
                 }
             }
         }
+
         /// <summary>
         /// Sets whether the device name has to be included in the advertise or the scan response data.
         /// The maximum advertised or responded data size is 31 bytes including the data type and the system wide data.
index 1fb02de..edf6053 100644 (file)
@@ -203,121 +203,154 @@ namespace Tizen.Network.Bluetooth
 
         internal IList<string> GetLeScanResultServiceUuids(BluetoothLeScanData scanData, BluetoothLePacketType packetType)
         {
+            if (!BluetoothAdapter.IsBluetoothEnabled || !Globals.IsInitialize)
+            {
+                BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
+            }
+
+            IList<string> list = new List<string>();
             IntPtr uuidListArray = IntPtr.Zero;
             int count = -1;
-
             BluetoothLeScanDataStruct scanDataStruct = BluetoothUtils.ConvertLeScanDataToStruct(scanData);
 
-            int ret = Interop.Bluetooth.GetScanResultServiceUuid(ref scanDataStruct, packetType,
-                                                ref uuidListArray, ref count);
+            int ret = Interop.Bluetooth.GetScanResultServiceUuid(ref scanDataStruct, packetType, ref uuidListArray, ref count);
             if (ret != (int)BluetoothError.None)
             {
                 Log.Info(Globals.LogTag, "Failed to service uuids list- " + (BluetoothError)ret);
-                return null;
+                Marshal.FreeHGlobal(scanDataStruct.AdvData);
+                Marshal.FreeHGlobal(scanDataStruct.ScanData);
+                BluetoothErrorFactory.ThrowBluetoothException(ret);
             }
 
-            Log.Info(Globals.LogTag, "count of uuids :  " + count);
+            Log.Info(Globals.LogTag, "Count of UUIDs:  " + count);
 
             IntPtr[] uuidList = new IntPtr[count];
             Marshal.Copy(uuidListArray, uuidList, 0, count);
-            IList<string> list = new List<string>();
-            foreach(IntPtr uuids in uuidList)
+            foreach (IntPtr uuids in uuidList)
             {
                 list.Add(Marshal.PtrToStringAnsi(uuids));
                 Interop.Libc.Free(uuids);
             }
 
             Interop.Libc.Free(uuidListArray);
+            Marshal.FreeHGlobal(scanDataStruct.AdvData);
+            Marshal.FreeHGlobal(scanDataStruct.ScanData);
             return list;
         }
 
         internal string GetLeScanResultDeviceName(BluetoothLeScanData scanData, BluetoothLePacketType packetType)
         {
-            string deviceName;
+            if (!BluetoothAdapter.IsBluetoothEnabled || !Globals.IsInitialize)
+            {
+                BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
+            }
 
-            BluetoothLeScanDataStruct scanDataStruct = BluetoothUtils.ConvertLeScanDataToStruct (scanData);
+            string deviceName;
+            BluetoothLeScanDataStruct scanDataStruct = BluetoothUtils.ConvertLeScanDataToStruct(scanData);
 
             int ret = Interop.Bluetooth.GetLeScanResultDeviceName(ref scanDataStruct, packetType, out deviceName);
-            if (ret != (int)BluetoothError.None) {
+            if (ret != (int)BluetoothError.None)
+            {
                 Log.Error(Globals.LogTag, "Failed to get Device name- " + (BluetoothError)ret);
-                return null;
+                Marshal.FreeHGlobal(scanDataStruct.AdvData);
+                Marshal.FreeHGlobal(scanDataStruct.ScanData);
+                BluetoothErrorFactory.ThrowBluetoothException(ret);
             }
-            Log.Info (Globals.LogTag, "Device name " + deviceName);
+
+            Log.Info(Globals.LogTag, "DeviceName: " + deviceName);
+            Marshal.FreeHGlobal(scanDataStruct.AdvData);
+            Marshal.FreeHGlobal(scanDataStruct.ScanData);
             return deviceName;
         }
 
         internal int GetScanResultTxPowerLevel(BluetoothLeScanData scanData, BluetoothLePacketType packetType)
         {
+            if (!BluetoothAdapter.IsBluetoothEnabled || !Globals.IsInitialize)
+            {
+                BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
+            }
+
             int powerLevel = -1;
-            BluetoothLeScanDataStruct scanDataStruct = BluetoothUtils.ConvertLeScanDataToStruct (scanData);
+            BluetoothLeScanDataStruct scanDataStruct = BluetoothUtils.ConvertLeScanDataToStruct(scanData);
 
             int ret = Interop.Bluetooth.GetScanResultTxPowerLevel(ref scanDataStruct, packetType, out powerLevel);
-            if (ret != (int)BluetoothError.None) {
+            if (ret != (int)BluetoothError.None)
+            {
                 Log.Error(Globals.LogTag, "Failed to get tx power level- " + (BluetoothError)ret);
+                Marshal.FreeHGlobal(scanDataStruct.AdvData);
+                Marshal.FreeHGlobal(scanDataStruct.ScanData);
+                BluetoothErrorFactory.ThrowBluetoothException(ret);
             }
-            Log.Info (Globals.LogTag, "TxPowerLevel is --- " + powerLevel);
+
+            Log.Info (Globals.LogTag, "TxPowerLevel: " + powerLevel);
+            Marshal.FreeHGlobal(scanDataStruct.AdvData);
+            Marshal.FreeHGlobal(scanDataStruct.ScanData);
             return powerLevel;
         }
 
         internal IList<string> GetScanResultSvcSolicitationUuids(BluetoothLeScanData scanData, BluetoothLePacketType packetType)
         {
+            if (!BluetoothAdapter.IsBluetoothEnabled || !Globals.IsInitialize)
+            {
+                BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
+            }
+
+            IList<string> list = new List<string>();
             IntPtr uuidListArray;
             int count;
-
             BluetoothLeScanDataStruct scanDataStruct = BluetoothUtils.ConvertLeScanDataToStruct(scanData);
 
-            int ret = Interop.Bluetooth.GetScaResultSvcSolicitationUuids(ref scanDataStruct, packetType, out uuidListArray, out count);
-            if (ret != (int)BluetoothError.None) {
+            int ret = Interop.Bluetooth.GetScanResultSvcSolicitationUuids(ref scanDataStruct, packetType, out uuidListArray, out count);
+            if (ret != (int)BluetoothError.None)
+            {
                 Log.Error(Globals.LogTag, "Failed to get service solicitation uuids " + (BluetoothError)ret);
-                return null;
+                Marshal.FreeHGlobal(scanDataStruct.AdvData);
+                Marshal.FreeHGlobal(scanDataStruct.ScanData);
+                BluetoothErrorFactory.ThrowBluetoothException(ret);
             }
 
             IntPtr[] uuidList = new IntPtr[count];
             Marshal.Copy(uuidListArray, uuidList, 0, count);
-            IList<string> list = new List<string>();
-            foreach(IntPtr uuids in uuidList)
+            foreach (IntPtr uuids in uuidList)
             {
                 list.Add(Marshal.PtrToStringAnsi(uuids));
                 Interop.Libc.Free(uuids);
             }
 
             Interop.Libc.Free(uuidListArray);
+            Marshal.FreeHGlobal(scanDataStruct.AdvData);
+            Marshal.FreeHGlobal(scanDataStruct.ScanData);
             return list;
         }
 
-        internal IList<BluetoothLeServiceData> GetScanResultServiceDataList(BluetoothLeScanData scanData,
-                            BluetoothLePacketType packetType, out int serviceCount)
+        internal IList<BluetoothLeServiceData> GetScanResultServiceDataList(BluetoothLeScanData scanData, BluetoothLePacketType packetType)
         {
-            int ret = 0;
+            if (!BluetoothAdapter.IsBluetoothEnabled || !Globals.IsInitialize)
+            {
+                BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
+            }
+
             IntPtr serviceListArray;
             _serviceListCount = 0;
+            BluetoothLeScanDataStruct scanDataStruct = BluetoothUtils.ConvertLeScanDataToStruct(scanData);
 
-            BluetoothLeScanDataStruct scanDataStruct = BluetoothUtils.ConvertLeScanDataToStruct (scanData);
-
-            ret = Interop.Bluetooth.GetScanResultServiceDataList(ref scanDataStruct, packetType, out serviceListArray, out _serviceListCount);
+            int ret = Interop.Bluetooth.GetScanResultServiceDataList(ref scanDataStruct, packetType, out serviceListArray, out _serviceListCount);
             Log.Info(Globals.LogTag, "ServiceListCount :  " + _serviceListCount + " PacketType : " + packetType + " Error: " + (BluetoothError)ret);
             if (ret != (int)BluetoothError.None)
             {
                 Log.Info(Globals.LogTag, "Failed to get Service Data List, Error - " + (BluetoothError)ret);
-                serviceCount = 0;
-                Marshal.FreeHGlobal(serviceListArray);
                 Marshal.FreeHGlobal(scanDataStruct.AdvData);
                 Marshal.FreeHGlobal(scanDataStruct.ScanData);
-                return null;
+                BluetoothErrorFactory.ThrowBluetoothException(ret);
             }
 
-            BluetoothLeServiceDataStruct[] svcList = new BluetoothLeServiceDataStruct[_serviceListCount];
             int sizePointerToABC = Marshal.SizeOf(new BluetoothLeServiceDataStruct());
             for (int i = 0; i < _serviceListCount; i++)
             {
-                svcList[i] = (BluetoothLeServiceDataStruct)Marshal.PtrToStructure(new IntPtr(serviceListArray.ToInt32() + (i * sizePointerToABC)), typeof(BluetoothLeServiceDataStruct));
-                Log.Info(Globals.LogTag, " Uuid : " + svcList[i].ServiceUuid + "length :  " + svcList[i].ServiceDataLength);
-
-                _list.Add(BluetoothUtils.ConvertStructToLeServiceData(svcList[i]));
+                var svc = (BluetoothLeServiceDataStruct)Marshal.PtrToStructure(new IntPtr(serviceListArray.ToInt32() + (i * sizePointerToABC)), typeof(BluetoothLeServiceDataStruct));
+                _list.Add(BluetoothUtils.ConvertStructToLeServiceData(svc));
             }
 
-            serviceCount = _serviceListCount;
-
             Interop.Libc.Free(serviceListArray);
             Marshal.FreeHGlobal(scanDataStruct.AdvData);
             Marshal.FreeHGlobal(scanDataStruct.ScanData);
@@ -346,32 +379,48 @@ namespace Tizen.Network.Bluetooth
 
         internal int GetScanResultAppearance(BluetoothLeScanData scanData, BluetoothLePacketType packetType)
         {
-            int appearance;
+            if (!BluetoothAdapter.IsBluetoothEnabled || !Globals.IsInitialize)
+            {
+                BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
+            }
 
-            BluetoothLeScanDataStruct scanDataStruct = BluetoothUtils.ConvertLeScanDataToStruct (scanData);
+            int appearance = -1;
+            BluetoothLeScanDataStruct scanDataStruct = BluetoothUtils.ConvertLeScanDataToStruct(scanData);
 
             int ret = Interop.Bluetooth.GetScanResultAppearance(ref scanDataStruct, packetType, out appearance);
-            if (ret != (int)BluetoothError.None) {
+            if (ret != (int)BluetoothError.None)
+            {
                 Log.Error(Globals.LogTag, "Failed to get Appearance value- " + (BluetoothError)ret);
+                Marshal.FreeHGlobal(scanDataStruct.AdvData);
+                Marshal.FreeHGlobal(scanDataStruct.ScanData);
+                BluetoothErrorFactory.ThrowBluetoothException(ret);
             }
+
+            Marshal.FreeHGlobal(scanDataStruct.AdvData);
+            Marshal.FreeHGlobal(scanDataStruct.ScanData);
             return appearance;
         }
 
         internal ManufacturerData GetScanResultManufacturerData(BluetoothLeScanData scanData, BluetoothLePacketType packetType)
         {
+            if (!BluetoothAdapter.IsBluetoothEnabled || !Globals.IsInitialize)
+            {
+                BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
+            }
+
+            ManufacturerData data = new ManufacturerData();
             int dataId = 0;
             int dataLength = 0;
             IntPtr manufData;
+            BluetoothLeScanDataStruct scanDataStruct = BluetoothUtils.ConvertLeScanDataToStruct(scanData);
 
-            BluetoothLeScanDataStruct scanDataStruct = BluetoothUtils.ConvertLeScanDataToStruct (scanData);
-            ManufacturerData data = new ManufacturerData();
-
-            int ret = Interop.Bluetooth.GetScanResultManufacturerData(ref scanDataStruct, packetType, out dataId,
-                out manufData, out dataLength);
+            int ret = Interop.Bluetooth.GetScanResultManufacturerData(ref scanDataStruct, packetType, out dataId, out manufData, out dataLength);
             if (ret != (int)BluetoothError.None)
             {
                 Log.Error(Globals.LogTag, "Failed to get Manufacturer data - " + (BluetoothError)ret);
-                return null;
+                Marshal.FreeHGlobal(scanDataStruct.AdvData);
+                Marshal.FreeHGlobal(scanDataStruct.ScanData);
+                BluetoothErrorFactory.ThrowBluetoothException(ret);
             }
 
             data.Id = dataId;
@@ -382,6 +431,9 @@ namespace Tizen.Network.Bluetooth
                 Marshal.Copy(manufData, data.Data, 0, data.DataLength);
             }
 
+            Interop.Libc.Free(manufData);
+            Marshal.FreeHGlobal(scanDataStruct.AdvData);
+            Marshal.FreeHGlobal(scanDataStruct.ScanData);
             return data;
         }