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

Commit 32814372 authored by Andrei Homescu's avatar Andrei Homescu
Browse files

Changes to UNEXPECTED_NULL handling in libbinder_rs.

Two changes related to UNEXPECTED_NULL in libbinder_rs:
1) Return UNEXPECTED_NULL from Deserialize for SpIBinder instead of
   panicking
2) Convert UNEXPECTED_NULL status codes to NULL_POINTER exceptions,
   for compatibility with C++ and Java services.

Test: atest aidl_integration_test with 1406447 applied
Change-Id: I2e7cc92b2e1cf08a35968f675827d7d917144110
parent e51e48b0
Loading
Loading
Loading
Loading
+11 −1
Original line number Diff line number Diff line
@@ -529,7 +529,17 @@ macro_rules! declare_binder_interface {
            }

            fn on_transact(&self, code: $crate::TransactionCode, data: &$crate::Parcel, reply: &mut $crate::Parcel) -> $crate::Result<()> {
                $on_transact(&*self.0, code, data, reply)
                match $on_transact(&*self.0, code, data, reply) {
                    // The C++ backend converts UNEXPECTED_NULL into an exception
                    Err($crate::StatusCode::UNEXPECTED_NULL) => {
                        let status = $crate::Status::new_exception(
                            $crate::ExceptionCode::NULL_POINTER,
                            None,
                        );
                        reply.write(&status)
                    },
                    result => result
                }
            }

            fn get_class() -> $crate::InterfaceClass {
+4 −1
Original line number Diff line number Diff line
@@ -346,7 +346,10 @@ impl SerializeArray for Option<&SpIBinder> {}

impl Deserialize for SpIBinder {
    fn deserialize(parcel: &Parcel) -> Result<SpIBinder> {
        parcel.read_binder().transpose().unwrap()
        parcel
            .read_binder()
            .transpose()
            .unwrap_or(Err(StatusCode::UNEXPECTED_NULL))
    }
}