From 0648c83d4495fe6f98b458260a5b1762abc2c9fd Mon Sep 17 00:00:00 2001 From: Jakub Pawlowski <jpawlowski@google.com> Date: Mon, 9 Jan 2017 06:53:36 -0800 Subject: [PATCH] Zero is a valid advertiser id Test: start advertising using bluetooth-cli Change-Id: Iead31c5e73a70850c6a209b6bbbeaeb792202608 --- system/service/client/main.cc | 13 +++++++------ .../ipc/binder/interface_with_instances_base.cc | 1 - 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/system/service/client/main.cc b/system/service/client/main.cc index be3409cfe07..be6b15e72c6 100644 --- a/system/service/client/main.cc +++ b/system/service/client/main.cc @@ -96,8 +96,9 @@ std::atomic_int ble_client_id(0); // The registered IBluetoothLeAdvertiser handle. If |ble_advertiser_registering| // is true then an operation to register the advertiser is in progress. +const int invalid_advertiser_id = -1; std::atomic_bool ble_advertiser_registering(false); -std::atomic_int ble_advertiser_id(0); +std::atomic_int ble_advertiser_id(invalid_advertiser_id); // The registered IBluetoothLeScanner handle. If |ble_scanner_registering| is // true then an operation to register the scanner is in progress. @@ -440,7 +441,7 @@ void HandleRegisterBLEAdvertiser(IBluetooth* bt_iface, return; } - if (ble_advertiser_id.load()) { + if (ble_advertiser_id.load() != invalid_advertiser_id) { PrintError("Already registered"); return; } @@ -463,7 +464,7 @@ void HandleUnregisterBLEAdvertiser(IBluetooth* bt_iface, const vector<string>& args) { CHECK_NO_ARGS(args); - if (!ble_advertiser_id.load()) { + if (ble_advertiser_id.load() == invalid_advertiser_id) { PrintError("Not registered"); return; } @@ -476,7 +477,7 @@ void HandleUnregisterBLEAdvertiser(IBluetooth* bt_iface, } ble_advertiser_iface->UnregisterAdvertiser(ble_advertiser_id.load()); - ble_advertiser_id = 0; + ble_advertiser_id = invalid_advertiser_id; PrintCommandStatus(true); } @@ -638,7 +639,7 @@ void HandleStartAdv(IBluetooth* bt_iface, const vector<string>& args) { } } - if (!ble_advertiser_id.load()) { + if (ble_advertiser_id.load() == invalid_advertiser_id) { PrintError("BLE advertiser not registered"); return; } @@ -710,7 +711,7 @@ void HandleStartAdv(IBluetooth* bt_iface, const vector<string>& args) { } void HandleStopAdv(IBluetooth* bt_iface, const vector<string>& args) { - if (!ble_advertiser_id.load()) { + if (ble_advertiser_id.load() == invalid_advertiser_id) { PrintError("BLE advertiser not registered"); return; } diff --git a/system/service/ipc/binder/interface_with_instances_base.cc b/system/service/ipc/binder/interface_with_instances_base.cc index 2005bf09cd0..18b1eae4aa7 100644 --- a/system/service/ipc/binder/interface_with_instances_base.cc +++ b/system/service/ipc/binder/interface_with_instances_base.cc @@ -124,7 +124,6 @@ void InterfaceWithInstancesBase::OnRegisterInstance( std::lock_guard<std::mutex> lock(maps_lock_); int instance_id = instance->GetInstanceId(); - CHECK(instance_id); if (!id_to_cb_.Register(instance_id, callback, this)) { LOG(ERROR) << "Failed to store callback"; OnRegisterInstanceImpl(bluetooth::BLE_STATUS_FAILURE, callback, nullptr); -- GitLab