use android_hardware_uwb::aidl::android::hardware::uwb::{IUwb, IUwbChip}; use android_hardware_uwb::binder; use binder::{Result, Strong}; use binder_tokio::TokioRuntime; use tokio::runtime::Handle as TokioHandle; use crate::uwb_chip; pub struct Uwb { chips: Vec>, } impl Uwb { pub fn from_chips( chips: impl IntoIterator, handle: TokioHandle, ) -> Self { Self { chips: chips .into_iter() .map(|chip| { IUwbChip::BnUwbChip::new_async_binder( chip, TokioRuntime(handle.clone()), binder::BinderFeatures::default(), ) }) .collect(), } } } impl binder::Interface for Uwb {} impl IUwb::IUwb for Uwb { fn getChips(&self) -> Result> { log::debug!("getChips"); self.chips.iter().map(|chip| chip.getName()).collect() } fn getChip(&self, name: &str) -> Result> { log::debug!("getChip {}", name); let chip = self .chips .iter() .find(|chip| chip.getName().as_deref() == Ok(name)); if let Some(chip) = chip { Ok(chip.clone()) } else { Err(binder::ExceptionCode::ILLEGAL_ARGUMENT.into()) } } }