Service Implementation

We can now implement the AIDL service:

birthday_service/src/lib.rs:

  1. //! Implementation of the `IBirthdayService` AIDL interface.
  2. use com_example_birthdayservice::aidl::com::example::birthdayservice::IBirthdayService::IBirthdayService;
  3. use com_example_birthdayservice::binder;
  4. /// The `IBirthdayService` implementation.
  5. pub struct BirthdayService;
  6. impl binder::Interface for BirthdayService {}
  7. impl IBirthdayService for BirthdayService {
  8. fn wishHappyBirthday(&self, name: &str, years: i32) -> binder::Result<String> {
  9. Ok(format!(
  10. "Happy Birthday {name}, congratulations with the {years} years!"
  11. ))
  12. }
  13. }

birthday_service/Android.bp:

  1. rust_library {
  2. name: "libbirthdayservice",
  3. srcs: ["src/lib.rs"],
  4. crate_name: "birthdayservice",
  5. rustlibs: [
  6. "com.example.birthdayservice-rust",
  7. "libbinder_rs",
  8. ],
  9. }