From 91508756d08fcf83be08ca0335fa6e92511529b4 Mon Sep 17 00:00:00 2001 From: Corentin Lecouvey Date: Fri, 17 Oct 2014 15:05:55 +0200 Subject: [PATCH] [Bluetooth] destroyBonding API : remove device from known_devices array 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 | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/bluetooth/bluetooth_api.js b/bluetooth/bluetooth_api.js index 3ac6a97..bd65e16 100644 --- a/bluetooth/bluetooth_api.js +++ b/bluetooth/bluetooth_api.js @@ -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); } -- 2.7.4