1 use android_hardware_uwb::aidl::android::hardware::uwb::IUwb::{self, IUwb as _};
2 use android_hardware_uwb::binder;
3 
4 use tokio::runtime::Runtime;
5 
6 use std::env;
7 use std::panic;
8 
9 use log::LevelFilter;
10 
11 mod uwb;
12 mod uwb_chip;
13 
main() -> anyhow::Result<()>14 fn main() -> anyhow::Result<()> {
15     logger::init(
16         logger::Config::default()
17             .with_max_level(LevelFilter::Debug)
18             .with_tag_on_device("android.hardware.uwb"),
19     );
20 
21     // Redirect panic messages to logcat.
22     panic::set_hook(Box::new(|panic_info| {
23         log::error!("{}", panic_info);
24     }));
25 
26     log::info!("UWB HAL starting up");
27 
28     // Create the tokio runtime
29     let rt = Runtime::new()?;
30 
31     let chips = env::args()
32         .skip(1) // Skip binary name
33         .enumerate()
34         .map(|(i, arg)| uwb_chip::UwbChip::new(i.to_string(), arg));
35 
36     binder::add_service(
37         &format!("{}/default", IUwb::BpUwb::get_descriptor()),
38         IUwb::BnUwb::new_binder(
39             uwb::Uwb::from_chips(chips, rt.handle().clone()),
40             binder::BinderFeatures::default(),
41         )
42         .as_binder(),
43     )?;
44 
45     binder::ProcessState::join_thread_pool();
46     Ok(())
47 }
48