پیاده‌سازی سرویس‌ها

اکنون می‌توانیم سرویس AIDL را پیاده‌سازی کنیم:

birthday_service/src/lib.rs:

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

birthday_service/Android.bp:

rust_library { name: "libbirthdayservice", srcs: ["src/lib.rs"], crate_name: "birthdayservice", rustlibs: [ "com.example.birthdayservice-rust", "libbinder_rs", ], }

Speaker Notes

  • به مسیر ایجاد IBirthdayService trait اشاره کنید و توضیح‌دهید که چرا هر یک از بخش‌ها ضروری است.
  • ‏ TODO: trait وویژگی binder::Interface چه کاری انجام می‌دهد؟ آیا متد‌هایی برای override وجود دارد؟ source کجاست؟