[Bluetooth] destroyBonding API : remove device from known_devices array
authorCorentin Lecouvey <corentin.lecouvey@open.eurogiciel.org>
Fri, 17 Oct 2014 13:05:55 +0000 (15:05 +0200)
committerCorentin Lecouvey <corentin.lecouvey@open.eurogiciel.org>
Fri, 17 Oct 2014 14:16:57 +0000 (16:16 +0200)
When remote device is unpaired, known_devices array has to be removed as well
and not just isBonded device property.

Add also an error case to directly returns an error if device to unpair is not in
known_devices array.

bluetooth/bluetooth_api.js

index 3ac6a97..bd65e16 100644 (file)
@@ -678,12 +678,20 @@ BluetoothAdapter.prototype.destroyBonding = function(address, successCallback, e
     throw new tizen.WebAPIError(tizen.WebAPIException.TYPE_MISMATCH_ERR);
   }
 
+  if (adapter.checkServiceAvailability(errorCallback))
+    return;
+
   if (!validateAddress(address)) {
     throw new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR);
   }
 
-  if (adapter.checkServiceAvailability(errorCallback))
+  var index = adapter.indexOfDevice(adapter.known_devices, address);
+  if (index == -1) {
+    var error = new tizen.WebAPIError(tizen.WebAPIException.NOT_FOUND_ERR);
+    if (errorCallback)
+      errorCallback(error);
     return;
+  }
 
   var msg = {
     'cmd': 'DestroyBonding',
@@ -718,7 +726,7 @@ BluetoothAdapter.prototype.destroyBonding = function(address, successCallback, e
       // BlueZ backends update the device state automatically when catching dbus signals
       // A better approach would be to adapt backends instances to have a single JSON protocol.
       if (result.capi)
-        _addConstProperty(adapter.known_devices[i], 'isBonded', false);
+        adapter.known_devices.splice(i, 1);
 
       successCallback(cb_device);
     }