1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-04-07 07:30:01 +02:00
2024-02-09 15:11:10 -08:00

49 lines
1.4 KiB
Markdown

# AIDL Client
Finally, we can create a Rust client for our new service.
_birthday_service/src/client.rs_:
```rust,ignore
use com_example_birthdayservice::aidl::com::example::birthdayservice::IBirthdayService::IBirthdayService;
use com_example_birthdayservice::binder;
{{#include ../birthday_service/src/client.rs:main}}
}
```
_birthday_service/Android.bp_:
```javascript
{{#include ../birthday_service/Android.bp:birthday_client}}
```
Notice that the client does not depend on `libbirthdayservice`.
Build, push, and run the client on your device:
```shell
{{#include ../../build_all.sh:birthday_client}}
```
```text
Happy Birthday Charlie, congratulations with the 60 years!
```
<details>
- `Strong<dyn IBirthdayService>` is the trait object representing the service
that the client has connected to.
- `Strong` is a custom smart pointer type for Binder. It handles both an
in-process ref count for the service trait object, and the global Binder ref
count that tracks how many processes have a reference to the object.
- Note that the trait object that the client uses to talk to the service uses
the exact same trait that the server implements. For a given Binder
interface, there is a single Rust trait generated that both client and
server use.
- Use the same service identifier used when registering the service. This should
ideally be defined in a common crate that both the client and server can
depend on.
</details>