From e335e3c4abf2ccbdb10888bc8a8ee3ded13144c3 Mon Sep 17 00:00:00 2001 From: Michal Michalski Date: Mon, 17 Dec 2018 15:25:20 +0100 Subject: [PATCH] [bluetooth] Ignoring undocumented exceptions in removeValueChangeListener. Calling removeValueChangeListener was throwing undocumented errors. This commit supresses those exceptions to match the documentation. [Verification] Exception is not thrown (verified by modified TCT test). Change-Id: I4df3b810d27d48da7a0194473984e59d1beb067b Signed-off-by: Michal Michalski --- src/bluetooth/bluetooth_gatt_service.cc | 30 +++++++++++-------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/src/bluetooth/bluetooth_gatt_service.cc b/src/bluetooth/bluetooth_gatt_service.cc index 1200a7b1..270a7728 100644 --- a/src/bluetooth/bluetooth_gatt_service.cc +++ b/src/bluetooth/bluetooth_gatt_service.cc @@ -513,26 +513,22 @@ void BluetoothGATTService::RemoveValueChangeListener(const picojson::value& args ScopeLogger(); const auto& address = args.get("address").get(); if (!IsStillConnected(address)) { - LogAndReportError(PlatformResult(ErrorCode::INVALID_STATE_ERR, "Device is not connected"), &out, - ("Device with address %s is no longer connected", address.c_str())); - return; - } - - bt_gatt_h handle = (bt_gatt_h) static_cast(args.get(kHandle).get()); + LoggerW("Device with address %s is no longer connected", address.c_str()); + } else { + bt_gatt_h handle = (bt_gatt_h) static_cast(args.get(kHandle).get()); - int ret = bt_gatt_client_unset_characteristic_value_changed_cb(handle); + int ret = bt_gatt_client_unset_characteristic_value_changed_cb(handle); - if (BT_ERROR_NONE != ret) { - LogAndReportError( - util::GetBluetoothError(ret, "Failed to unregister listener"), &out, - ("bt_gatt_client_unset_characteristic_value_changed_cb() failed with: %d (%s)", ret, - get_error_message(ret))); - } else { - gatt_characteristic_.erase( - std::remove(gatt_characteristic_.begin(), gatt_characteristic_.end(), handle), - gatt_characteristic_.end()); - ReportSuccess(out); + if (BT_ERROR_NONE != ret) { + LoggerW("bt_gatt_client_unset_characteristic_value_changed_cb() failed with: %d (%s)", ret, + get_error_message(ret)); + } else { + gatt_characteristic_.erase( + std::remove(gatt_characteristic_.begin(), gatt_characteristic_.end(), handle), + gatt_characteristic_.end()); + } } + ReportSuccess(out); } common::PlatformResult BluetoothGATTService::GetServiceAllUuids(const std::string& address, -- 2.34.1