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

Commit 7ea547c0 authored by Andrew Walbran's avatar Andrew Walbran Committed by Automerger Merge Worker
Browse files

Merge "Reuse same AIBinder type in rpcbinder bindgen." am: a0eda3b5 am:...

Merge "Reuse same AIBinder type in rpcbinder bindgen." am: a0eda3b5 am: 31164f1d am: f38a1feb am: 7c3f08fe am: 280f6c0f

Original change: https://android-review.googlesource.com/c/platform/frameworks/native/+/2193647



Change-Id: If367433603e05ffffac1a4ae1e44e876a7fb8eec
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents f83fff92 280f6c0f
Loading
Loading
Loading
Loading
+42 −1
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@ rust_library {
    ],
    rustlibs: [
        "libbinder_ndk_sys",
        "libbinder_rpc_unstable_bindgen",
        "libbinder_rpc_unstable_bindgen_sys",
        "libbinder_rs",
        "libdowncast_rs",
        "liblibc",
@@ -29,6 +29,35 @@ rust_library {
    min_sdk_version: "Tiramisu",
}

// Build a separate rust_library rather than depending directly on libbinder_rpc_unstable_bindgen,
// to work around the fact that rust_bindgen targets only produce rlibs and not dylibs, which would
// result in duplicate conflicting versions of libbinder_ndk_sys. This will hopefully be fixed in
// the build system, at which point we can delete this target and go back to using
// libbinder_rpc_unstable_bindgen directly.
rust_library {
    name: "libbinder_rpc_unstable_bindgen_sys",
    crate_name: "binder_rpc_unstable_bindgen",
    srcs: [
        ":libbinder_rpc_unstable_bindgen",
    ],
    visibility: [":__subpackages__"],
    rustlibs: [
        "libbinder_ndk_sys",
    ],
    shared_libs: [
        "libbinder_rpc_unstable",
        "libutils",
    ],
    apex_available: [
        "com.android.compos",
        "com.android.uwb",
        "com.android.virt",
    ],
    min_sdk_version: "Tiramisu",
    lints: "none",
    clippy_lints: "none",
}

// TODO(b/184872979): remove once the RPC Binder API is stabilised.
rust_bindgen {
    name: "libbinder_rpc_unstable_bindgen",
@@ -36,6 +65,15 @@ rust_bindgen {
    crate_name: "binder_rpc_unstable_bindgen",
    visibility: [":__subpackages__"],
    source_stem: "bindings",
    bindgen_flags: [
        "--blocklist-type",
        "AIBinder",
        "--raw-line",
        "use binder_ndk_sys::AIBinder;",
    ],
    rustlibs: [
        "libbinder_ndk_sys",
    ],
    shared_libs: [
        "libbinder_rpc_unstable",
        "libutils",
@@ -52,6 +90,9 @@ rust_test {
    name: "libbinder_rpc_unstable_bindgen_test",
    srcs: [":libbinder_rpc_unstable_bindgen"],
    crate_name: "binder_rpc_unstable_bindgen",
    rustlibs: [
        "libbinder_ndk_sys",
    ],
    test_suites: ["general-tests"],
    auto_gen_config: true,
    clippy_lints: "none",
+3 −6
Original line number Diff line number Diff line
@@ -14,10 +14,7 @@
 * limitations under the License.
 */

use binder::{
    unstable_api::{new_spibinder, AIBinder},
    FromIBinder, SpIBinder, StatusCode, Strong,
};
use binder::{unstable_api::new_spibinder, FromIBinder, SpIBinder, StatusCode, Strong};
use std::os::{
    raw::{c_int, c_void},
    unix::io::RawFd,
@@ -27,7 +24,7 @@ use std::os::{
pub fn get_vsock_rpc_service(cid: u32, port: u32) -> Option<SpIBinder> {
    // SAFETY: AIBinder returned by RpcClient has correct reference count, and the ownership can
    // safely be taken by new_spibinder.
    unsafe { new_spibinder(binder_rpc_unstable_bindgen::RpcClient(cid, port) as *mut AIBinder) }
    unsafe { new_spibinder(binder_rpc_unstable_bindgen::RpcClient(cid, port)) }
}

/// Connects to an RPC Binder server for a particular interface over vsock.
@@ -54,7 +51,7 @@ pub fn get_preconnected_rpc_service(
        new_spibinder(binder_rpc_unstable_bindgen::RpcPreconnectedClient(
            Some(request_fd_wrapper),
            param,
        ) as *mut AIBinder)
        ))
    }
}

+7 −7
Original line number Diff line number Diff line
@@ -14,7 +14,10 @@
 * limitations under the License.
 */

use binder::{unstable_api::AsNative, SpIBinder};
use binder::{
    unstable_api::{AIBinder, AsNative},
    SpIBinder,
};
use std::{os::raw, ptr::null_mut};

/// Runs a binder RPC server, serving the supplied binder service implementation on the given vsock
@@ -44,7 +47,7 @@ where
    F: FnOnce(),
{
    fn run_server(&mut self, mut service: SpIBinder, port: u32) -> bool {
        let service = service.as_native_mut() as *mut binder_rpc_unstable_bindgen::AIBinder;
        let service = service.as_native_mut();
        let param = self.as_void_ptr();

        // SAFETY: Service ownership is transferring to the server and won't be valid afterward.
@@ -106,10 +109,7 @@ pub fn run_rpc_server_with_factory(
    }
}

unsafe extern "C" fn factory_wrapper(
    cid: u32,
    context: *mut raw::c_void,
) -> *mut binder_rpc_unstable_bindgen::AIBinder {
unsafe extern "C" fn factory_wrapper(cid: u32, context: *mut raw::c_void) -> *mut AIBinder {
    // SAFETY: `context` was created from an `&mut RpcServerFactoryRef` by
    // `run_rpc_server_with_factory`, and we are still within the lifetime of the value it is
    // pointing to.
@@ -117,7 +117,7 @@ unsafe extern "C" fn factory_wrapper(
    let factory = factory_ptr.as_mut().unwrap();

    if let Some(mut service) = factory(cid) {
        service.as_native_mut() as *mut binder_rpc_unstable_bindgen::AIBinder
        service.as_native_mut()
    } else {
        null_mut()
    }