Merge "Regsiter BT HAL services if they are declared" into main

This commit is contained in:
Jooyung Han 2024-01-26 06:37:54 +00:00 committed by Gerrit Code Review
commit 9dec1ab884
3 changed files with 24 additions and 15 deletions

View file

@ -35,12 +35,16 @@ int main(int /* argc */, char** /* argv */) {
ndk::SharedRefBase::make<BluetoothFinder>();
std::string instance =
std::string() + BluetoothFinder::descriptor + "/default";
auto result =
AServiceManager_addService(service->asBinder().get(), instance.c_str());
if (result == STATUS_OK) {
ABinderProcess_joinThreadPool();
if (AServiceManager_isDeclared(instance.c_str())) {
auto result =
AServiceManager_addService(service->asBinder().get(), instance.c_str());
if (result != STATUS_OK) {
ALOGE("Could not register as a service!");
}
} else {
ALOGE("Could not register as a service!");
ALOGE("Could not register as a service because it's not declared.");
}
// Keep running
ABinderProcess_joinThreadPool();
return 0;
}

View file

@ -41,10 +41,11 @@ fn main() {
let lmp_event_service = lmp_event::LmpEvent::new();
let lmp_event_service_binder = BnBluetoothLmpEvent::new_binder(lmp_event_service, BinderFeatures::default());
binder::add_service(
&format!("{}/default", lmp_event::LmpEvent::get_descriptor()),
lmp_event_service_binder.as_binder(),
).expect("Failed to register service");
let descriptor = format!("{}/default", lmp_event::LmpEvent::get_descriptor());
if binder::is_declared(&descriptor).expect("Failed to check if declared") {
binder::add_service(&descriptor, lmp_event_service_binder.as_binder()).expect("Failed to register service");
} else {
info!("{LOG_TAG}: Failed to register service. Not declared.");
}
binder::ProcessState::join_thread_pool()
}

View file

@ -37,12 +37,16 @@ int main(int /* argc */, char** /* argv */) {
ndk::SharedRefBase::make<BluetoothChannelSounding>();
std::string instance =
std::string() + BluetoothChannelSounding::descriptor + "/default";
auto result =
AServiceManager_addService(service->asBinder().get(), instance.c_str());
if (result == STATUS_OK) {
ABinderProcess_joinThreadPool();
if (AServiceManager_isDeclared(instance.c_str())) {
auto result =
AServiceManager_addService(service->asBinder().get(), instance.c_str());
if (result != STATUS_OK) {
ALOGE("Could not register as a service!");
}
} else {
ALOGE("Could not register as a service!");
ALOGE("Could not register as a service because it's not declared.");
}
// Keep running
ABinderProcess_joinThreadPool();
return 0;
}