1 //! Test comms client, but in Rust
2
3 use binder::{StatusCode, Strong};
4 use com_android_minidroid_testservice::aidl::com::android::minidroid::testservice::ITestService::ITestService;
5 use com_android_minidroid_testservice::binder;
6 use log::{error, info};
7 use rpcbinder::RpcSession;
8
get_service(cid: u32, port: u32) -> Result<Strong<dyn ITestService>, StatusCode>9 fn get_service(cid: u32, port: u32) -> Result<Strong<dyn ITestService>, StatusCode> {
10 RpcSession::new().setup_vsock_client(cid, port)
11 }
12
main() -> Result<(), Box<dyn std::error::Error + Send + Sync>>13 fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
14 let _ = logger::init(
15 logger::Config::default()
16 .with_tag_on_device("client_minidroid_rust")
17 .with_max_level(log::LevelFilter::Debug),
18 );
19 // Redirect panic messages to logcat.
20 std::panic::set_hook(Box::new(|panic_info| {
21 error!("{}", panic_info);
22 }));
23
24 if std::env::args().len() != 3 {
25 return Err(format!("usage: {} CID port", std::env::args().next().unwrap()).into());
26 }
27
28 let service_host_cid =
29 std::env::args().nth(1).and_then(|arg| arg.parse::<u32>().ok()).expect("invalid CID");
30 let service_port =
31 std::env::args().nth(2).and_then(|arg| arg.parse::<u32>().ok()).expect("invalid port");
32
33 info!(
34 "Hello Rust Minidroid client! Connecting to CID {} and port {}",
35 service_host_cid, service_port
36 );
37
38 let service = get_service(service_host_cid, service_port)?;
39 service.sayHello()?;
40 service.printText("Hello from Rust client! ")?;
41 let result = service.addInteger(4, 6)?;
42 info!("Finished client. 4 + 6 = {}", result);
43
44 Ok(())
45 }
46