Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Binder/AIDL content updates #1618

Merged
merged 23 commits into from
Feb 9, 2024
Merged

Binder/AIDL content updates #1618

merged 23 commits into from
Feb 9, 2024

Conversation

randomPoison
Copy link
Collaborator

So far this PR makes two broad improvements to the Android course materials:

  • It fleshes out the existing course materials by adding more speaker notes and showing more of the generated code.
  • It adds a new section going over how AIDL types are supported by Rust and mapped to Rust types.

There are still additional changes to do (add an exercise, add a section on async binder), but those can be split into separate PRs if necessary.

This PR is still WIP because I need to test the code examples around the Binder types; Some of them are basically just psuedo-code at the moment.

Copy link
Collaborator

@rinon rinon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking really great! More depth than was there before, and I like the new notes you've incorporated. I think that covers most of what I've added off slides when I've taught this, but I'll think if there's anything else we should add.

@@ -1,4 +1,4 @@
// Copyright 2022 Google LLC
// Copyright 2024 Google LLC
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: 2022-2024 or just keep the original year?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a new file I created, so I thought we'd want to use 2024 in the comment since that's when it's written?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think using 2024 is correct for new files. My understanding is that we leave the years alone in existing files.

Way back when I first read about licenses for open source projects, the advice was to update the year of files that have received "significant changes" or so. Many projects just updated the year of every file in the beginning of the year. It's now my understanding that we don't do that, we just leave the files alone and only add new notices to new files.

@randomPoison randomPoison force-pushed the legare/binder-updates branch from 59ebd7b to b7f4655 Compare January 20, 2024 01:32
@randomPoison randomPoison marked this pull request as ready for review January 20, 2024 01:32
@randomPoison
Copy link
Collaborator Author

@ahomescu @rinon I've finished updating the example code and have addressed the feedback from your first review. Give this another look over when you have a chance.

&self,
provider: &SpIBinder,
) -> binder::Result<String> {
use binder::binder_impl::Proxy;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this re-exported by binder? If it's not but it's needed, we should fix that upstream.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does not currently appear to be re-exported.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never mind, see the next comment.

| ---------------------- | ------------- |
| `in` argument | `&[T]` |
| `out`/`inout` argument | `&mut Vec<T>` |
| Return | `Vec<T>` |
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also parcelable fields.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about parcelable fields? I'm not sure how that's relevant on this slide.

Copy link
Collaborator

@ahomescu ahomescu Jan 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm saying if you have a parcelable field that's an array, it will also use a Vec<T>. E.g.

parcelable Foo {
    int[] a;
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, that makes sense. I think I'll keep the slide specific to arrays in function signatures, but I'll add this to the speaker notes.

* Add speaker notes covering more details about how AIDL/Binder works.
* Add examples of generated Rust bindings.
* Flesh out the section on updating a Binder API.
* Add interface methods for passing binder objects and file descriptors.
* Partially implement the Rust service/client/server changes for the updated AIDL definitions.
* Fix code in `client.rs` for sending Binder objects.
* Add client code for sending a file descriptor.
@randomPoison randomPoison force-pushed the legare/binder-updates branch from 3dea292 to 7eb9cb7 Compare January 24, 2024 16:16
/// Call the birthday service.
fn main() -> Result<(), binder::Status> {
fn main() -> Result<(), Box<dyn Error>> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hope people don't start doing this in their production code. Otoh I'm not sure it's worth talking about anyhow and thiserror here.

&self,
provider: &SpIBinder,
) -> binder::Result<String> {
use binder::binder_impl::Proxy;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never mind, see the next comment.


The array types (`T[]`, `byte[]`, and `List<T>`) get translated to the
appropriate Rust array type depending on how they are used in the function
signature:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this was the source of the confusion: types can occur in function signatures but also in parcelable field definitions. References are never used for the latter, because they would add lifetimes to the corresponding Rust types.

| --------- | --------- | ----------------------------------- |
| `boolean` | `bool` | |
| `byte` | `i8` | Note that bytes are signed. |
| `char` | `u16` | Note the usage of `u16`, NOT `u32`. |
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Depending which language you come from, you'd expect a different type here: char would be u8 coming from C, u16 from Java, or u32 from Rust. AIDL picked the Java option.

Copy link
Collaborator

@ahomescu ahomescu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, looks like I'm not allowed to approve the PR.

Copy link
Collaborator

@thedataking thedataking left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving on behalf of Andrei 🚀

@randomPoison randomPoison merged commit f5f2c6b into main Feb 9, 2024
35 checks passed
@randomPoison randomPoison deleted the legare/binder-updates branch February 9, 2024 23:11
mani-chand pushed a commit to mani-chand/comprehensive-rust that referenced this pull request Feb 16, 2024
@mgeisler
Copy link
Collaborator

Thanks all for the much-needed updates here! 😄

Two ideas:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants