Back to Comprehensive Rust

Generated Service API

src/android/aidl/example-service/service-bindings.md

latest1.0 KB
Original Source
<!-- Copyright 2024 Google LLC SPDX-License-Identifier: CC-BY-4.0 -->

Generated Service API

Binder generates a trait for each interface definition.

birthday_service/aidl/com/example/birthdayservice/IBirthdayService.aidl:

java
{{#include ../birthday_service/aidl/com/example/birthdayservice/IBirthdayService.aidl:IBirthdayService}}
}

out/soong/.intermediates/.../com_example_birthdayservice.rs:

<!-- The example below is a cleaned up and simplified version of the real code. -->
rust,ignore
# // Copyright 2024 Google LLC
# // SPDX-License-Identifier: Apache-2.0
#
trait IBirthdayService {
    fn wishHappyBirthday(&self, name: &str, years: i32) -> binder::Result<String>;
}

Your service will need to implement this trait, and your client will use this trait to talk to the service.

<details>
  • Point out how the generated function signature, specifically the argument and return types, correspond to the interface definition.
    • String for an argument results in a different Rust type than String as a return type.
</details>