Zero is a valid advertiser id
Test: start advertising using bluetooth-cli
Change-Id: Iead31c5e73a70850c6a209b6bbbeaeb792202608
diff --git a/service/client/main.cc b/service/client/main.cc
index be3409c..be6b15e 100644
--- a/service/client/main.cc
+++ b/service/client/main.cc
@@ -96,8 +96,9 @@
// 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 @@
return;
}
- if (ble_advertiser_id.load()) {
+ if (ble_advertiser_id.load() != invalid_advertiser_id) {
PrintError("Already registered");
return;
}
@@ -463,7 +464,7 @@
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 @@
}
ble_advertiser_iface->UnregisterAdvertiser(ble_advertiser_id.load());
- ble_advertiser_id = 0;
+ ble_advertiser_id = invalid_advertiser_id;
PrintCommandStatus(true);
}
@@ -638,7 +639,7 @@
}
}
- if (!ble_advertiser_id.load()) {
+ if (ble_advertiser_id.load() == invalid_advertiser_id) {
PrintError("BLE advertiser not registered");
return;
}
@@ -710,7 +711,7 @@
}
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/service/ipc/binder/interface_with_instances_base.cc b/service/ipc/binder/interface_with_instances_base.cc
index 2005bf0..18b1eae 100644
--- a/service/ipc/binder/interface_with_instances_base.cc
+++ b/service/ipc/binder/interface_with_instances_base.cc
@@ -124,7 +124,6 @@
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);