[Bluetooth] Fixed issues related to BLE 81/216381/3
authorPiotr Kosko/Engineer/Native/Web API (PLT) /SRPOL/Samsung Electronics <p.kosko@samsung.com>
Thu, 24 Oct 2019 06:59:52 +0000 (08:59 +0200)
committerPiotr Kosko/Engineer/Native/Web API (PLT) /SRPOL/Samsung Electronics <p.kosko@samsung.com>
Thu, 24 Oct 2019 07:57:11 +0000 (09:57 +0200)
[Bug/Fix]
  1. Prevent possible crash in case of invalid data passed from native
  2. Prevent type mismatch exception in JS in case of LE devices advertising
     serviceData.

[Verification] tct passrate 100%
  Checked in chrome console and le device with serviceData.

Change-Id: Iecc9929a77a1acfd1b33eb325ea287011b9a6096

src/bluetooth/bluetooth_api.js
src/bluetooth/bluetooth_le_device.cc

index 7a6540a..984fb77 100755 (executable)
@@ -610,6 +610,7 @@ var BluetoothLEDevice = function(data) {
         uuids = data.uuids || null;
         solicitationuuids = data.solicitationuuids || null;
         if (data.serviceData) {
+            serviceData = [];
             data.serviceData.forEach(function(d) {
                 serviceData.push(new tizen.BluetoothLEServiceData(d));
             });
index 62caee5..f680cc1 100644 (file)
@@ -434,6 +434,7 @@ void BluetoothLEDevice::GattConnectionState(int result, bool connected, const ch
 
   // check state change success
   PlatformResult operation_success = ValidateConnectionChange(result);
+
   if (operation_success) {
     if (connected) {  // connect success
       le_device->is_connected_.insert(remote_address);
@@ -470,12 +471,16 @@ void BluetoothLEDevice::CleanClientInfo(const char* remote_address) {
 
 void BluetoothLEDevice::TriggerConnectCallback(const char* remote_address, PlatformResult result) {
   ScopeLogger();
-  auto it = connecting_.find(remote_address);
-  if (connecting_.end() != it) {
-    instance_.AsyncResponse(it->second, result);
-    connecting_.erase(it);
+  if (remote_address) {
+    auto it = connecting_.find(remote_address);
+    if (connecting_.end() != it) {
+      instance_.AsyncResponse(it->second, result);
+      connecting_.erase(it);
+    } else {
+      LoggerW("Given address is not in waiting connections list");
+    }
   } else {
-    LoggerW("Given address is not in waiting connections list");
+    LoggerE("Connection failed, returned remote_address is null. Callback will be not triggered");
   }
 }