Service Implementation

We can now implement the AIDL service:

birthday_service/src/lib.rs:

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

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. }
  • Point out the path to the generated IBirthdayService trait, and explain why each of the segments is necessary.
  • TODO: What does the binder::Interface trait do? Are there methods to override? Where source?