Loading libs/binder/rust/src/binder.rs +63 −1 Original line number Diff line number Diff line Loading @@ -56,6 +56,26 @@ pub trait Interface: Send { } } /// Interface stability promise /// /// An interface can promise to be a stable vendor interface ([`Vintf`]), or /// makes no stability guarantees ([`Local`]). [`Local`] is /// currently the default stability. pub enum Stability { /// Default stability, visible to other modules in the same compilation /// context (e.g. modules on system.img) Local, /// A Vendor Interface Object, which promises to be stable Vintf, } impl Default for Stability { fn default() -> Self { Stability::Local } } /// A local service that can be remotable via Binder. /// /// An object that implement this interface made be made into a Binder service Loading Loading @@ -94,6 +114,8 @@ pub const LAST_CALL_TRANSACTION: TransactionCode = sys::LAST_CALL_TRANSACTION; pub const FLAG_ONEWAY: TransactionFlags = sys::FLAG_ONEWAY; /// Corresponds to TF_CLEAR_BUF -- clear transaction buffers after call is made. pub const FLAG_CLEAR_BUF: TransactionFlags = sys::FLAG_CLEAR_BUF; /// Set to the vendor flag if we are building for the VNDK, 0 otherwise pub const FLAG_PRIVATE_LOCAL: TransactionFlags = sys::FLAG_PRIVATE_LOCAL; /// Internal interface of binder local or remote objects for making /// transactions. Loading Loading @@ -602,6 +624,42 @@ macro_rules! declare_binder_interface { $interface[$descriptor] { native: $native($on_transact), proxy: $proxy {}, stability: $crate::Stability::default(), } } }; { $interface:path[$descriptor:expr] { native: $native:ident($on_transact:path), proxy: $proxy:ident, stability: $stability:expr, } } => { $crate::declare_binder_interface! { $interface[$descriptor] { native: $native($on_transact), proxy: $proxy {}, stability: $stability, } } }; { $interface:path[$descriptor:expr] { native: $native:ident($on_transact:path), proxy: $proxy:ident { $($fname:ident: $fty:ty = $finit:expr),* }, } } => { $crate::declare_binder_interface! { $interface[$descriptor] { native: $native($on_transact), proxy: $proxy { $($fname: $fty = $finit),* }, stability: $crate::Stability::default(), } } }; Loading @@ -612,6 +670,7 @@ macro_rules! declare_binder_interface { proxy: $proxy:ident { $($fname:ident: $fty:ty = $finit:expr),* }, stability: $stability:expr, } } => { $crate::declare_binder_interface! { Loading @@ -622,6 +681,7 @@ macro_rules! declare_binder_interface { proxy: $proxy { $($fname: $fty = $finit),* }, stability: $stability, } } }; Loading @@ -635,6 +695,8 @@ macro_rules! declare_binder_interface { proxy: $proxy:ident { $($fname:ident: $fty:ty = $finit:expr),* }, stability: $stability:expr, } } => { #[doc = $proxy_doc] Loading Loading @@ -669,7 +731,7 @@ macro_rules! declare_binder_interface { impl $native { /// Create a new binder service. pub fn new_binder<T: $interface + Sync + Send + 'static>(inner: T) -> $crate::Strong<dyn $interface> { let binder = $crate::Binder::new($native(Box::new(inner))); let binder = $crate::Binder::new_with_stability($native(Box::new(inner)), $stability); $crate::Strong::new(Box::new(binder)) } } Loading libs/binder/rust/src/lib.rs +3 −2 Original line number Diff line number Diff line Loading @@ -107,8 +107,9 @@ use binder_ndk_sys as sys; pub mod parcel; pub use crate::binder::{ FromIBinder, IBinder, IBinderInternal, Interface, InterfaceClass, Remotable, Strong, TransactionCode, TransactionFlags, Weak, FIRST_CALL_TRANSACTION, FLAG_CLEAR_BUF, FLAG_ONEWAY, FromIBinder, IBinder, IBinderInternal, Interface, InterfaceClass, Remotable, Stability, Strong, TransactionCode, TransactionFlags, Weak, FIRST_CALL_TRANSACTION, FLAG_CLEAR_BUF, FLAG_ONEWAY, FLAG_PRIVATE_LOCAL, LAST_CALL_TRANSACTION, }; pub use error::{status_t, ExceptionCode, Result, Status, StatusCode}; Loading libs/binder/rust/src/native.rs +50 −4 Original line number Diff line number Diff line Loading @@ -14,7 +14,7 @@ * limitations under the License. */ use crate::binder::{AsNative, Interface, InterfaceClassMethods, Remotable, TransactionCode}; use crate::binder::{AsNative, Interface, InterfaceClassMethods, Remotable, Stability, TransactionCode}; use crate::error::{status_result, status_t, Result, StatusCode}; use crate::parcel::{Parcel, Serialize}; use crate::proxy::SpIBinder; Loading Loading @@ -49,11 +49,19 @@ pub struct Binder<T: Remotable> { unsafe impl<T: Remotable> Send for Binder<T> {} impl<T: Remotable> Binder<T> { /// Create a new Binder remotable object. /// Create a new Binder remotable object with default stability /// /// This moves the `rust_object` into an owned [`Box`] and Binder will /// manage its lifetime. pub fn new(rust_object: T) -> Binder<T> { Self::new_with_stability(rust_object, Stability::default()) } /// Create a new Binder remotable object with the given stability /// /// This moves the `rust_object` into an owned [`Box`] and Binder will /// manage its lifetime. pub fn new_with_stability(rust_object: T, stability: Stability) -> Binder<T> { let class = T::get_class(); let rust_object = Box::into_raw(Box::new(rust_object)); let ibinder = unsafe { Loading @@ -65,10 +73,12 @@ impl<T: Remotable> Binder<T> { // ends. sys::AIBinder_new(class.into(), rust_object as *mut c_void) }; Binder { let mut binder = Binder { ibinder, rust_object, } }; binder.mark_stability(stability); binder } /// Set the extension of a binder interface. This allows a downstream Loading Loading @@ -161,6 +171,42 @@ impl<T: Remotable> Binder<T> { pub fn get_descriptor() -> &'static str { T::get_descriptor() } /// Mark this binder object with the given stability guarantee fn mark_stability(&mut self, stability: Stability) { match stability { Stability::Local => self.mark_local_stability(), Stability::Vintf => { unsafe { // Safety: Self always contains a valid `AIBinder` pointer, so // we can always call this C API safely. sys::AIBinder_markVintfStability(self.as_native_mut()); } } } } /// Mark this binder object with local stability, which is vendor if we are /// building for the VNDK and system otherwise. #[cfg(vendor_ndk)] fn mark_local_stability(&mut self) { unsafe { // Safety: Self always contains a valid `AIBinder` pointer, so // we can always call this C API safely. sys::AIBinder_markVendorStability(self.as_native_mut()); } } /// Mark this binder object with local stability, which is vendor if we are /// building for the VNDK and system otherwise. #[cfg(not(vendor_ndk))] fn mark_local_stability(&mut self) { unsafe { // Safety: Self always contains a valid `AIBinder` pointer, so // we can always call this C API safely. sys::AIBinder_markSystemStability(self.as_native_mut()); } } } impl<T: Remotable> Interface for Binder<T> { Loading libs/binder/rust/sys/BinderBindings.hpp +2 −0 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ #include <android/binder_parcel_platform.h> #include <android/binder_process.h> #include <android/binder_shell.h> #include <android/binder_stability.h> #include <android/binder_status.h> namespace android { Loading Loading @@ -80,6 +81,7 @@ enum { enum { FLAG_ONEWAY = FLAG_ONEWAY, FLAG_CLEAR_BUF = FLAG_CLEAR_BUF, FLAG_PRIVATE_LOCAL = FLAG_PRIVATE_LOCAL, }; } // namespace consts Loading Loading
libs/binder/rust/src/binder.rs +63 −1 Original line number Diff line number Diff line Loading @@ -56,6 +56,26 @@ pub trait Interface: Send { } } /// Interface stability promise /// /// An interface can promise to be a stable vendor interface ([`Vintf`]), or /// makes no stability guarantees ([`Local`]). [`Local`] is /// currently the default stability. pub enum Stability { /// Default stability, visible to other modules in the same compilation /// context (e.g. modules on system.img) Local, /// A Vendor Interface Object, which promises to be stable Vintf, } impl Default for Stability { fn default() -> Self { Stability::Local } } /// A local service that can be remotable via Binder. /// /// An object that implement this interface made be made into a Binder service Loading Loading @@ -94,6 +114,8 @@ pub const LAST_CALL_TRANSACTION: TransactionCode = sys::LAST_CALL_TRANSACTION; pub const FLAG_ONEWAY: TransactionFlags = sys::FLAG_ONEWAY; /// Corresponds to TF_CLEAR_BUF -- clear transaction buffers after call is made. pub const FLAG_CLEAR_BUF: TransactionFlags = sys::FLAG_CLEAR_BUF; /// Set to the vendor flag if we are building for the VNDK, 0 otherwise pub const FLAG_PRIVATE_LOCAL: TransactionFlags = sys::FLAG_PRIVATE_LOCAL; /// Internal interface of binder local or remote objects for making /// transactions. Loading Loading @@ -602,6 +624,42 @@ macro_rules! declare_binder_interface { $interface[$descriptor] { native: $native($on_transact), proxy: $proxy {}, stability: $crate::Stability::default(), } } }; { $interface:path[$descriptor:expr] { native: $native:ident($on_transact:path), proxy: $proxy:ident, stability: $stability:expr, } } => { $crate::declare_binder_interface! { $interface[$descriptor] { native: $native($on_transact), proxy: $proxy {}, stability: $stability, } } }; { $interface:path[$descriptor:expr] { native: $native:ident($on_transact:path), proxy: $proxy:ident { $($fname:ident: $fty:ty = $finit:expr),* }, } } => { $crate::declare_binder_interface! { $interface[$descriptor] { native: $native($on_transact), proxy: $proxy { $($fname: $fty = $finit),* }, stability: $crate::Stability::default(), } } }; Loading @@ -612,6 +670,7 @@ macro_rules! declare_binder_interface { proxy: $proxy:ident { $($fname:ident: $fty:ty = $finit:expr),* }, stability: $stability:expr, } } => { $crate::declare_binder_interface! { Loading @@ -622,6 +681,7 @@ macro_rules! declare_binder_interface { proxy: $proxy { $($fname: $fty = $finit),* }, stability: $stability, } } }; Loading @@ -635,6 +695,8 @@ macro_rules! declare_binder_interface { proxy: $proxy:ident { $($fname:ident: $fty:ty = $finit:expr),* }, stability: $stability:expr, } } => { #[doc = $proxy_doc] Loading Loading @@ -669,7 +731,7 @@ macro_rules! declare_binder_interface { impl $native { /// Create a new binder service. pub fn new_binder<T: $interface + Sync + Send + 'static>(inner: T) -> $crate::Strong<dyn $interface> { let binder = $crate::Binder::new($native(Box::new(inner))); let binder = $crate::Binder::new_with_stability($native(Box::new(inner)), $stability); $crate::Strong::new(Box::new(binder)) } } Loading
libs/binder/rust/src/lib.rs +3 −2 Original line number Diff line number Diff line Loading @@ -107,8 +107,9 @@ use binder_ndk_sys as sys; pub mod parcel; pub use crate::binder::{ FromIBinder, IBinder, IBinderInternal, Interface, InterfaceClass, Remotable, Strong, TransactionCode, TransactionFlags, Weak, FIRST_CALL_TRANSACTION, FLAG_CLEAR_BUF, FLAG_ONEWAY, FromIBinder, IBinder, IBinderInternal, Interface, InterfaceClass, Remotable, Stability, Strong, TransactionCode, TransactionFlags, Weak, FIRST_CALL_TRANSACTION, FLAG_CLEAR_BUF, FLAG_ONEWAY, FLAG_PRIVATE_LOCAL, LAST_CALL_TRANSACTION, }; pub use error::{status_t, ExceptionCode, Result, Status, StatusCode}; Loading
libs/binder/rust/src/native.rs +50 −4 Original line number Diff line number Diff line Loading @@ -14,7 +14,7 @@ * limitations under the License. */ use crate::binder::{AsNative, Interface, InterfaceClassMethods, Remotable, TransactionCode}; use crate::binder::{AsNative, Interface, InterfaceClassMethods, Remotable, Stability, TransactionCode}; use crate::error::{status_result, status_t, Result, StatusCode}; use crate::parcel::{Parcel, Serialize}; use crate::proxy::SpIBinder; Loading Loading @@ -49,11 +49,19 @@ pub struct Binder<T: Remotable> { unsafe impl<T: Remotable> Send for Binder<T> {} impl<T: Remotable> Binder<T> { /// Create a new Binder remotable object. /// Create a new Binder remotable object with default stability /// /// This moves the `rust_object` into an owned [`Box`] and Binder will /// manage its lifetime. pub fn new(rust_object: T) -> Binder<T> { Self::new_with_stability(rust_object, Stability::default()) } /// Create a new Binder remotable object with the given stability /// /// This moves the `rust_object` into an owned [`Box`] and Binder will /// manage its lifetime. pub fn new_with_stability(rust_object: T, stability: Stability) -> Binder<T> { let class = T::get_class(); let rust_object = Box::into_raw(Box::new(rust_object)); let ibinder = unsafe { Loading @@ -65,10 +73,12 @@ impl<T: Remotable> Binder<T> { // ends. sys::AIBinder_new(class.into(), rust_object as *mut c_void) }; Binder { let mut binder = Binder { ibinder, rust_object, } }; binder.mark_stability(stability); binder } /// Set the extension of a binder interface. This allows a downstream Loading Loading @@ -161,6 +171,42 @@ impl<T: Remotable> Binder<T> { pub fn get_descriptor() -> &'static str { T::get_descriptor() } /// Mark this binder object with the given stability guarantee fn mark_stability(&mut self, stability: Stability) { match stability { Stability::Local => self.mark_local_stability(), Stability::Vintf => { unsafe { // Safety: Self always contains a valid `AIBinder` pointer, so // we can always call this C API safely. sys::AIBinder_markVintfStability(self.as_native_mut()); } } } } /// Mark this binder object with local stability, which is vendor if we are /// building for the VNDK and system otherwise. #[cfg(vendor_ndk)] fn mark_local_stability(&mut self) { unsafe { // Safety: Self always contains a valid `AIBinder` pointer, so // we can always call this C API safely. sys::AIBinder_markVendorStability(self.as_native_mut()); } } /// Mark this binder object with local stability, which is vendor if we are /// building for the VNDK and system otherwise. #[cfg(not(vendor_ndk))] fn mark_local_stability(&mut self) { unsafe { // Safety: Self always contains a valid `AIBinder` pointer, so // we can always call this C API safely. sys::AIBinder_markSystemStability(self.as_native_mut()); } } } impl<T: Remotable> Interface for Binder<T> { Loading
libs/binder/rust/sys/BinderBindings.hpp +2 −0 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ #include <android/binder_parcel_platform.h> #include <android/binder_process.h> #include <android/binder_shell.h> #include <android/binder_stability.h> #include <android/binder_status.h> namespace android { Loading Loading @@ -80,6 +81,7 @@ enum { enum { FLAG_ONEWAY = FLAG_ONEWAY, FLAG_CLEAR_BUF = FLAG_CLEAR_BUF, FLAG_PRIVATE_LOCAL = FLAG_PRIVATE_LOCAL, }; } // namespace consts Loading