1 use alloc::rc::Rc;
2 use binder::{BinderFeatures, Status};
3 use rpcbinder::RpcServer;
4 use service_manager_test_service::aidl::com::android::trusty::test_service::ISMTestService::{
5 BnSMTestService, ISMTestService,
6 };
7 use tipc::{service_dispatcher, wrap_service, Manager, PortCfg};
8
9 const DIRECT_TEST_SERVICE_PORT: &str = "com.android.trusty.test_service.ISMTestService/direct.bnd";
10
11 struct TestService;
12
13 impl binder::Interface for TestService {}
14 impl ISMTestService for TestService {
hello(&self) -> Result<String, Status>15 fn hello(&self) -> Result<String, Status> {
16 Ok("Hello from the service manager test service!".to_owned())
17 }
18 }
19
20 wrap_service!(DirectTestService(RpcServer: UnbufferedService));
21
22 service_dispatcher! {
23 enum TestServices {
24 DirectTestService,
25 }
26 }
27
main()28 fn main() {
29 trusty_log::init();
30 let direct_service = BnSMTestService::new_binder(TestService, BinderFeatures::default());
31 let direct_rpc_server =
32 RpcServer::new_per_session(move |_uuid| Some(direct_service.as_binder()));
33 let direct = DirectTestService(direct_rpc_server);
34
35 let mut dispatcher = TestServices::<1>::new().expect("Failed to create dispatcher");
36
37 let cfg = PortCfg::new(DIRECT_TEST_SERVICE_PORT)
38 .expect("could not create port config")
39 .allow_ta_connect();
40
41 dispatcher
42 .add_service(Rc::new(direct), cfg)
43 .expect("failed to add direct test service to dispatcher");
44
45 Manager::<_, _, 1, 1>::new_with_dispatcher(dispatcher, [])
46 .expect("Service manager could not be created")
47 .run_event_loop()
48 .expect("Service manager test service failed");
49 }
50