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

Commit 6f3674a1 authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Snap for 12439515 from 6d17c9b3 to 25Q1-release

Change-Id: I83e16773ad9bd4d6581707a0485fd6128a53f226
parents fbba6707 6d17c9b3
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -298,7 +298,8 @@ AIBinder_Class* ICInterface::defineClass(const char* interfaceDescriptor,
#endif

// TODO(b/368559337): fix versioning on product partition
#if !defined(__ANDROID_PRODUCT__) && \
// TODO(b/370091328): APEX modules call this function even it is unavailable.
#if !defined(__ANDROID_APEX__) && !defined(__ANDROID_PRODUCT__) && \
        (defined(__ANDROID_UNAVAILABLE_SYMBOLS_ARE_WEAK__) || __ANDROID_API__ >= 36)
    if API_LEVEL_AT_LEAST (36, 202504) {
        if (codeToFunction != nullptr) {
@@ -309,7 +310,8 @@ AIBinder_Class* ICInterface::defineClass(const char* interfaceDescriptor,
#else
    (void)codeToFunction;
    (void)functionCount;
#endif  // defined(__ANDROID_UNAVAILABLE_SYMBOLS_ARE_WEAK__) || __ANDROID_API__ >= 36
#endif  // !defined(__ANDROID_APEX__) && !defined(__ANDROID_PRODUCT__) && \
//     (defined(__ANDROID_UNAVAILABLE_SYMBOLS_ARE_WEAK__) || __ANDROID_API__ >= 36)
    return clazz;
}

+19 −0
Original line number Diff line number Diff line
@@ -15,6 +15,8 @@ rust_library {
        "libbinder_ndk_sys",
        "libdowncast_rs",
        "liblibc",
        "liblog_rust",
        "libnix",
    ],
    host_supported: true,
    vendor_available: true,
@@ -79,6 +81,9 @@ rust_library {
    shared_libs: [
        "libbinder_ndk",
    ],
    rustlibs: [
        "liblibc",
    ],
    host_supported: true,
    vendor_available: true,
    product_available: true,
@@ -129,9 +134,18 @@ rust_bindgen {
        // rustified
        "libbinder_ndk_bindgen_flags.txt",
    ],
    bindgen_flags: [
        "--blocklist-type",
        "sockaddr",
        "--raw-line",
        "use libc::sockaddr;",
    ],
    shared_libs: [
        "libbinder_ndk",
    ],
    rustlibs: [
        "liblibc",
    ],
    host_supported: true,
    vendor_available: true,
    product_available: true,
@@ -185,6 +199,8 @@ rust_test {
        "libbinder_ndk_sys",
        "libdowncast_rs",
        "liblibc",
        "liblog_rust",
        "libnix",
    ],
}

@@ -196,4 +212,7 @@ rust_test {
    auto_gen_config: true,
    clippy_lints: "none",
    lints: "none",
    rustlibs: [
        "liblibc",
    ],
}
+25 −0
Original line number Diff line number Diff line
@@ -136,6 +136,31 @@ impl TryFrom<i32> for Stability {
    }
}

/// Same as `Stability`, but in the form of a trait. Used when the stability should be encoded in
/// the type.
///
/// When/if the `adt_const_params` Rust feature is stabilized, this could be replace by using
/// `Stability` directly with const generics.
pub trait StabilityType {
    /// The `Stability` represented by this type.
    const VALUE: Stability;
}

/// `Stability::Local`.
#[derive(Debug)]
pub enum LocalStabilityType {}
/// `Stability::Vintf`.
#[derive(Debug)]
pub enum VintfStabilityType {}

impl StabilityType for LocalStabilityType {
    const VALUE: Stability = Stability::Local;
}

impl StabilityType for VintfStabilityType {
    const VALUE: Stability = Stability::Vintf;
}

/// A local service that can be remotable via Binder.
///
/// An object that implement this interface made be made into a Binder service
+8 −3
Original line number Diff line number Diff line
@@ -104,6 +104,8 @@ mod proxy;
mod service;
#[cfg(not(trusty))]
mod state;
#[cfg(not(any(android_vendor, android_vndk)))]
mod system_only;

use binder_ndk_sys as sys;

@@ -120,6 +122,8 @@ pub use service::{
};
#[cfg(not(trusty))]
pub use state::{ProcessState, ThreadState};
#[cfg(not(any(android_vendor, android_vndk)))]
pub use system_only::{Accessor, ConnectionInfo};

/// Binder result containing a [`Status`] on error.
pub type Result<T> = std::result::Result<T, Status>;
@@ -128,9 +132,10 @@ pub type Result<T> = std::result::Result<T, Status>;
/// without AIDL.
pub mod binder_impl {
    pub use crate::binder::{
        IBinderInternal, InterfaceClass, Remotable, Stability, ToAsyncInterface, ToSyncInterface,
        TransactionCode, TransactionFlags, FIRST_CALL_TRANSACTION, FLAG_CLEAR_BUF, FLAG_ONEWAY,
        FLAG_PRIVATE_LOCAL, LAST_CALL_TRANSACTION,
        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,
    };
    pub use crate::binder_async::BinderAsyncRuntime;
    pub use crate::error::status_t;
+28 −17
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
 */

use crate::binder::Stability;
use crate::binder::StabilityType;
use crate::error::StatusCode;
use crate::parcel::{
    BorrowedParcel, Deserialize, Parcel, Parcelable, Serialize, NON_NULL_PARCELABLE_FLAG,
@@ -60,7 +61,7 @@ enum ParcelableHolderData {
/// `Send` nor `Sync`), mainly because it internally contains
/// a `Parcel` which in turn is not thread-safe.
#[derive(Debug)]
pub struct ParcelableHolder {
pub struct ParcelableHolder<STABILITY: StabilityType> {
    // This is a `Mutex` because of `get_parcelable`
    // which takes `&self` for consistency with C++.
    // We could make `get_parcelable` take a `&mut self`
@@ -68,13 +69,17 @@ pub struct ParcelableHolder {
    // improvement, but then callers would require a mutable
    // `ParcelableHolder` even for that getter method.
    data: Mutex<ParcelableHolderData>,
    stability: Stability,

    _stability_phantom: std::marker::PhantomData<STABILITY>,
}

impl ParcelableHolder {
impl<STABILITY: StabilityType> ParcelableHolder<STABILITY> {
    /// Construct a new `ParcelableHolder` with the given stability.
    pub fn new(stability: Stability) -> Self {
        Self { data: Mutex::new(ParcelableHolderData::Empty), stability }
    pub fn new() -> Self {
        Self {
            data: Mutex::new(ParcelableHolderData::Empty),
            _stability_phantom: Default::default(),
        }
    }

    /// Reset the contents of this `ParcelableHolder`.
@@ -91,7 +96,7 @@ impl ParcelableHolder {
    where
        T: Any + Parcelable + ParcelableMetadata + std::fmt::Debug + Send + Sync,
    {
        if self.stability > p.get_stability() {
        if STABILITY::VALUE > p.get_stability() {
            return Err(StatusCode::BAD_VALUE);
        }

@@ -157,30 +162,36 @@ impl ParcelableHolder {

    /// Return the stability value of this object.
    pub fn get_stability(&self) -> Stability {
        self.stability
        STABILITY::VALUE
    }
}

impl<STABILITY: StabilityType> Default for ParcelableHolder<STABILITY> {
    fn default() -> Self {
        Self::new()
    }
}

impl Clone for ParcelableHolder {
    fn clone(&self) -> ParcelableHolder {
impl<STABILITY: StabilityType> Clone for ParcelableHolder<STABILITY> {
    fn clone(&self) -> Self {
        ParcelableHolder {
            data: Mutex::new(self.data.lock().unwrap().clone()),
            stability: self.stability,
            _stability_phantom: Default::default(),
        }
    }
}

impl Serialize for ParcelableHolder {
impl<STABILITY: StabilityType> Serialize for ParcelableHolder<STABILITY> {
    fn serialize(&self, parcel: &mut BorrowedParcel<'_>) -> Result<(), StatusCode> {
        parcel.write(&NON_NULL_PARCELABLE_FLAG)?;
        self.write_to_parcel(parcel)
    }
}

impl Deserialize for ParcelableHolder {
impl<STABILITY: StabilityType> Deserialize for ParcelableHolder<STABILITY> {
    type UninitType = Self;
    fn uninit() -> Self::UninitType {
        Self::new(Default::default())
        Self::new()
    }
    fn from_init(value: Self) -> Self::UninitType {
        value
@@ -191,16 +202,16 @@ impl Deserialize for ParcelableHolder {
        if status == NULL_PARCELABLE_FLAG {
            Err(StatusCode::UNEXPECTED_NULL)
        } else {
            let mut parcelable = ParcelableHolder::new(Default::default());
            let mut parcelable = Self::new();
            parcelable.read_from_parcel(parcel)?;
            Ok(parcelable)
        }
    }
}

impl Parcelable for ParcelableHolder {
impl<STABILITY: StabilityType> Parcelable for ParcelableHolder<STABILITY> {
    fn write_to_parcel(&self, parcel: &mut BorrowedParcel<'_>) -> Result<(), StatusCode> {
        parcel.write(&self.stability)?;
        parcel.write(&STABILITY::VALUE)?;

        let mut data = self.data.lock().unwrap();
        match *data {
@@ -236,7 +247,7 @@ impl Parcelable for ParcelableHolder {
    }

    fn read_from_parcel(&mut self, parcel: &BorrowedParcel<'_>) -> Result<(), StatusCode> {
        if self.stability != parcel.read()? {
        if self.get_stability() != parcel.read()? {
            return Err(StatusCode::BAD_VALUE);
        }

Loading