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

Commit d14a1132 authored by Matthew Maurer's avatar Matthew Maurer Committed by Automerger Merge Worker
Browse files

Merge changes Id4db842d,I58e41d34 into main am: dcca938d

parents 52c39142 dcca938d
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -139,6 +139,9 @@ rust_bindgen {
        "--raw-line",
        "use libc::sockaddr;",
    ],
    cflags: [
        "-DANDROID_PLATFORM",
    ],
    shared_libs: [
        "libbinder_ndk",
    ],
@@ -179,6 +182,9 @@ rust_bindgen {
        // rustified
        "libbinder_ndk_bindgen_flags.txt",
    ],
    cflags: [
        "-DANDROID_PLATFORM",
    ],
    shared_libs: [
        "libbinder_ndk_on_trusty_mock",
        "libc++",
+15 −0
Original line number Diff line number Diff line
[package]
name = "android-binder"
version = "0.1.0"
edition = "2021"
description = "Safe bindings to Android Binder, restricted to the NDK"
license = "Apache-2.0"

[dependencies]
binder-ndk-sys = { package = "android-binder-ndk-sys", version = "0.1", path = "./sys" }
downcast-rs = "1.2.1"
libc = "0.2.159"

[lints.rust.unexpected_cfgs]
level = "warn"
check-cfg = ["cfg(android_vendor)", "cfg(android_ndk)", "cfg(android_vndk)", "cfg(trusty)"]
+4 −0
Original line number Diff line number Diff line
fn main() {
    // Anything with cargo is NDK only. If you want to access anything else, use Soong.
    println!("cargo::rustc-cfg=android_ndk");
}
+9 −4
Original line number Diff line number Diff line
@@ -207,8 +207,10 @@ pub const LAST_CALL_TRANSACTION: TransactionCode = sys::LAST_CALL_TRANSACTION;
/// Corresponds to TF_ONE_WAY -- an asynchronous call.
pub const FLAG_ONEWAY: TransactionFlags = sys::FLAG_ONEWAY;
/// Corresponds to TF_CLEAR_BUF -- clear transaction buffers after call is made.
#[cfg(not(android_ndk))]
pub const FLAG_CLEAR_BUF: TransactionFlags = sys::FLAG_CLEAR_BUF;
/// Set to the vendor flag if we are building for the VNDK, 0 otherwise
#[cfg(not(android_ndk))]
pub const FLAG_PRIVATE_LOCAL: TransactionFlags = sys::FLAG_PRIVATE_LOCAL;

/// Internal interface of binder local or remote objects for making
@@ -221,7 +223,7 @@ pub trait IBinderInternal: IBinder {
    fn is_binder_alive(&self) -> bool;

    /// Indicate that the service intends to receive caller security contexts.
    #[cfg(not(android_vndk))]
    #[cfg(not(any(android_vndk, android_ndk)))]
    fn set_requesting_sid(&mut self, enable: bool);

    /// Dump this object to the given file handle
@@ -346,7 +348,6 @@ impl InterfaceClass {
                panic!("Expected non-null class pointer from AIBinder_Class_define!");
            }
            sys::AIBinder_Class_setOnDump(class, Some(I::on_dump));
            sys::AIBinder_Class_setHandleShellCommand(class, None);
            class
        };
        InterfaceClass(ptr)
@@ -714,7 +715,7 @@ unsafe impl<T, V: AsNative<T>> AsNative<T> for Option<V> {
pub struct BinderFeatures {
    /// Indicates that the service intends to receive caller security contexts. This must be true
    /// for `ThreadState::with_calling_sid` to work.
    #[cfg(not(android_vndk))]
    #[cfg(not(any(android_vndk, android_ndk)))]
    pub set_requesting_sid: bool,
    // Ensure that clients include a ..BinderFeatures::default() to preserve backwards compatibility
    // when new fields are added. #[non_exhaustive] doesn't work because it prevents struct
@@ -916,8 +917,12 @@ macro_rules! declare_binder_interface {
        impl $native {
            /// Create a new binder service.
            pub fn new_binder<T: $interface + Sync + Send + 'static>(inner: T, features: $crate::BinderFeatures) -> $crate::Strong<dyn $interface> {
                #[cfg(not(android_ndk))]
                let mut binder = $crate::binder_impl::Binder::new_with_stability($native(Box::new(inner)), $stability);
                #[cfg(not(android_vndk))]
                #[cfg(android_ndk)]
                let mut binder = $crate::binder_impl::Binder::new($native(Box::new(inner)));

                #[cfg(not(any(android_vndk, android_ndk)))]
                $crate::binder_impl::IBinderInternal::set_requesting_sid(&mut binder, features.set_requesting_sid);
                $crate::Strong::new(Box::new(binder))
            }
+14 −10
Original line number Diff line number Diff line
@@ -100,11 +100,11 @@ mod error;
mod native;
mod parcel;
mod proxy;
#[cfg(not(trusty))]
#[cfg(not(any(trusty, android_ndk)))]
mod service;
#[cfg(not(trusty))]
#[cfg(not(any(trusty, android_ndk)))]
mod state;
#[cfg(not(any(android_vendor, android_vndk)))]
#[cfg(not(any(android_vendor, android_ndk, android_vndk)))]
mod system_only;

use binder_ndk_sys as sys;
@@ -114,15 +114,18 @@ pub use binder::{BinderFeatures, FromIBinder, IBinder, Interface, Strong, Weak};
pub use error::{ExceptionCode, IntoBinderResult, Status, StatusCode};
pub use parcel::{ParcelFileDescriptor, Parcelable, ParcelableHolder};
pub use proxy::{DeathRecipient, SpIBinder, WpIBinder};
#[cfg(not(trusty))]
#[cfg(not(any(trusty, android_ndk)))]
pub use service::{
    add_service, check_interface, check_service, force_lazy_services_persist,
    get_declared_instances, get_interface, get_service, is_declared, is_handling_transaction,
    register_lazy_service, wait_for_interface, wait_for_service, LazyServiceGuard,
    get_declared_instances, is_declared, is_handling_transaction, register_lazy_service,
    wait_for_interface, wait_for_service, LazyServiceGuard,
};
#[cfg(not(trusty))]
#[cfg(not(any(trusty, android_ndk)))]
#[allow(deprecated)]
pub use service::{get_interface, get_service};
#[cfg(not(any(trusty, android_ndk)))]
pub use state::{ProcessState, ThreadState};
#[cfg(not(any(android_vendor, android_vndk)))]
#[cfg(not(any(android_vendor, android_vndk, android_ndk)))]
pub use system_only::{delegate_accessor, Accessor, ConnectionInfo};

/// Binder result containing a [`Status`] on error.
@@ -134,9 +137,10 @@ pub mod binder_impl {
    pub use crate::binder::{
        IBinderInternal, InterfaceClass, LocalStabilityType, Remotable, Stability, StabilityType,
        ToAsyncInterface, ToSyncInterface, TransactionCode, TransactionFlags, VintfStabilityType,
        FIRST_CALL_TRANSACTION, FLAG_CLEAR_BUF, FLAG_ONEWAY, FLAG_PRIVATE_LOCAL,
        LAST_CALL_TRANSACTION,
        FIRST_CALL_TRANSACTION, FLAG_ONEWAY, LAST_CALL_TRANSACTION,
    };
    #[cfg(not(android_ndk))]
    pub use crate::binder::{FLAG_CLEAR_BUF, FLAG_PRIVATE_LOCAL};
    pub use crate::binder_async::BinderAsyncRuntime;
    pub use crate::error::status_t;
    pub use crate::native::Binder;
Loading