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>(); ndk::SharedRefBase::make<BluetoothFinder>();
std::string instance = std::string instance =
std::string() + BluetoothFinder::descriptor + "/default"; std::string() + BluetoothFinder::descriptor + "/default";
auto result = if (AServiceManager_isDeclared(instance.c_str())) {
AServiceManager_addService(service->asBinder().get(), instance.c_str()); auto result =
if (result == STATUS_OK) { AServiceManager_addService(service->asBinder().get(), instance.c_str());
ABinderProcess_joinThreadPool(); if (result != STATUS_OK) {
ALOGE("Could not register as a service!");
}
} else { } 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; return 0;
} }

View file

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

View file

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