Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2c674b06 authored by Andrei Homescu's avatar Andrei Homescu Committed by Matthew Maurer
Browse files

Implement Send trait for Binder<T>

Binder objects need to be Send for AIDL services which have a Binder
service in the response message.

Bug: 161559357
Test: atest rustBinderTest
Change-Id: I68f4219756a566fa9e8b48bbda8e292cd164de26
parent 2a3c250d
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -61,7 +61,7 @@ pub trait Interface {
/// the AIDL backend, users need only implement the high-level AIDL-defined
/// interface. The AIDL compiler then generates a container struct that wraps
/// the user-defined service and implements `Remotable`.
pub trait Remotable: Sync {
pub trait Remotable: Send + Sync {
    /// The Binder interface descriptor string.
    ///
    /// This string is a unique identifier for a Binder interface, and should be
+12 −0
Original line number Diff line number Diff line
@@ -36,6 +36,18 @@ pub struct Binder<T: Remotable> {
    rust_object: *mut T,
}

/// # Safety
///
/// A `Binder<T>` is a pair of unique owning pointers to two values:
///   * a C++ ABBinder which the C++ API guarantees can be passed between threads
///   * a Rust object which implements `Remotable`; this trait requires `Send + Sync`
///
/// Both pointers are unique (never escape the `Binder<T>` object and are not copied)
/// so we can essentially treat `Binder<T>` as a box-like containing the two objects;
/// the box-like object inherits `Send` from the two inner values, similarly
/// to how `Box<T>` is `Send` if `T` is `Send`.
unsafe impl<T: Remotable> Send for Binder<T> {}

impl<T: Remotable> Binder<T> {
    /// Create a new Binder remotable object.
    ///