AIDL 接口

您可以使用 AIDL 接口声明您的服务的 API:

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

  1. /** Birthday service interface. */
  2. interface IBirthdayService {
  3. /** Generate a Happy Birthday message. */
  4. String wishHappyBirthday(String name, int years);
  5. }

birthday_service/aidl/Android.bp:

  1. aidl_interface {
  2. name: "com.example.birthdayservice",
  3. srcs: ["com/example/birthdayservice/*.aidl"],
  4. unstable: true,
  5. backend: {
  6. rust: { // Rust is not enabled by default
  7. enabled: true,
  8. },
  9. },
  10. }
  • Note that the directory structure under the aidl/ directory needs to match the package name used in the AIDL file, i.e. the package is com.example.birthdayservice and the file is at aidl/com/example/IBirthdayService.aidl.