AIDL Server

Finally, we can create a server which exposes the service:

birthday_service/src/server.rs:

  1. //! Birthday service.
  2. use birthdayservice::BirthdayService;
  3. use com_example_birthdayservice::aidl::com::example::birthdayservice::IBirthdayService::BnBirthdayService;
  4. use com_example_birthdayservice::binder;
  5. const SERVICE_IDENTIFIER: &str = "birthdayservice";
  6. /// Entry point for birthday service.
  7. fn main() {
  8. let birthday_service = BirthdayService;
  9. let birthday_service_binder = BnBirthdayService::new_binder(
  10. birthday_service,
  11. binder::BinderFeatures::default(),
  12. );
  13. binder::add_service(SERVICE_IDENTIFIER, birthday_service_binder.as_binder())
  14. .expect("Failed to register service");
  15. binder::ProcessState::join_thread_pool()
  16. }

birthday_service/Android.bp:

  1. rust_binary {
  2. name: "birthday_server",
  3. crate_name: "birthday_server",
  4. srcs: ["src/server.rs"],
  5. rustlibs: [
  6. "com.example.birthdayservice-rust",
  7. "libbinder_rs",
  8. "libbirthdayservice",
  9. ],
  10. prefer_rlib: true,
  11. }