Implementação do Serviço

Agora podemos implementar o serviço AIDL:

birthday_service/src/lib.rs:

use com_example_birthdayservice::aidl::com::example::birthdayservice::IBirthdayService::IBirthdayService; use com_example_birthdayservice::binder; /// A implementação de `IBirthdayService`. pub struct BirthdayService; impl binder::Interface for BirthdayService {} impl IBirthdayService for BirthdayService { fn wishHappyBirthday(&self, name: &str, years: i32) -> binder::Result<String> { Ok(format!("Feliz aniversário {name}, parabéns pelos seus {years} anos!")) } }

birthday_service/Android.bp:

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

Speaker Notes

  • Aponte o caminho para o trait IBirthdayService gerado e explique por que cada um dos segmentos é necessário.
  • TODO: O que o trait binder::Interface faz? Existem métodos para substituir? Onde está o código-fonte?