mer-hybris / libgbinder

GLib-style interface to binder
BSD 3-Clause "New" or "Revised" License
51 stars 40 forks source link

[gbinder] Added writer and reader for parcelables #92

Closed g7 closed 2 years ago

g7 commented 2 years ago

Parcelables allow to serialize arbitrary objects inside an AIDL parcel.

The structure is pretty simple, and is as follows:

This pull request adds both a writer and a reader for parcelables, along with matching unit tests.

Useful to talk with AIDL HALs on Android 11+.

monich commented 2 years ago

Hmm, I couldn't find anything which would suggest that Parcelable::writeToParcel implementation is required to write the payload size into the parcel. The framework only adds an int32 flag and the rest is a just a blob of an unknown size containing arbitrary data. That kind of format can't be handled in a generic way. Or am I missing something?

g7 commented 2 years ago

I'm basing myself on what the android tools are doing, unfortunately I haven't seen an official piece of documentation in the Android docs :/

I have double checked with a bunch of generated interface code (like android.hardware.interface.light, which was actually my use case) and the behaviour matches.

monich commented 2 years ago

Ah, so it isn't a parcelable in android.os.Parcelable or android::Parcelable sense, it a parcelable in the aidl sense, whatever that means. That's confusing, but it's none of your fault 🙂

That deserves a comment in .c sources that these functions are supposed to be used with generated aidl parcelables and ain't guaranteed to work with any other kinds of parcelables, and I think I can accept that.

g7 commented 2 years ago

Oh yeah, I agree it's pretty confusing :/

Do you think it would be worth renaming the functions to something like gbinder_reader_read_aidl_parcelable and gbinder_writer_append_aidl_parcelable just to make that more clear (along with a comment as you suggested)?

monich commented 2 years ago

I think the naming is fine, just add a comment.

g7 commented 2 years ago

Alright, added a comment on gbinder_reader_read_parcelable and gbinder_writer_append_parcelable. Thanks for the feedback!

monich commented 2 years ago

Thanks!

monich commented 2 years ago

FYI, I've found a few issues in gbinder_reader_read_parcelable wrt handling of invalid input, but I'll fix that myself. You can check the git history later if you're curious.