Loading libs/binder/Android.bp +6 −0 Original line number Diff line number Diff line Loading @@ -329,6 +329,7 @@ cc_library { "libbinder_ndk", "libutils", ], export_include_dirs: ["include_rpc_unstable"], // enumerate stable entry points, for apex use stubs: { Loading @@ -342,6 +343,11 @@ cc_library { ], } filegroup { name: "libbinder_rpc_unstable_header", srcs: ["include_rpc_unstable/binder_rpc_unstable.hpp"], } // libbinder historically contained additional interfaces that provided specific // functionality in the platform but have nothing to do with binder itself. These // are moved out of libbinder in order to avoid the overhead of their vtables. Loading libs/binder/rust/src/binder_rpc_unstable.hpp→libs/binder/include_rpc_unstable/binder_rpc_unstable.hpp +44 −0 Original line number Diff line number Diff line Loading @@ -20,7 +20,25 @@ extern "C" { struct AIBinder; // Starts an RPC server on a given port and a given root IBinder object. // This function sets up the server and joins before returning. bool RunRpcServer(AIBinder* service, unsigned int port); // Starts an RPC server on a given port and a given root IBinder object. // This function sets up the server, calls readyCallback with a given param, and // then joins before returning. bool RunRpcServerCallback(AIBinder* service, unsigned int port, void (*readyCallback)(void* param), void* param); AIBinder* RpcClient(unsigned int cid, unsigned int port); // Connect to an RPC server with preconnected file descriptors. // // requestFd should connect to the server and return a valid file descriptor, or // -1 if connection fails. // // param will be passed to requestFd. Callers can use param to pass contexts to // the requestFd function. AIBinder* RpcPreconnectedClient(int (*requestFd)(void* param), void* param); } libs/binder/libbinder_rpc_unstable.cpp +20 −1 Original line number Diff line number Diff line Loading @@ -15,6 +15,7 @@ */ #include <android-base/logging.h> #include <android-base/unique_fd.h> #include <android/binder_libbinder.h> #include <binder/RpcServer.h> #include <binder/RpcSession.h> Loading @@ -24,10 +25,12 @@ using android::RpcServer; using android::RpcSession; using android::status_t; using android::statusToString; using android::base::unique_fd; extern "C" { bool RunRpcServer(AIBinder* service, unsigned int port) { bool RunRpcServerCallback(AIBinder* service, unsigned int port, void (*readyCallback)(void* param), void* param) { auto server = RpcServer::make(); server->iUnderstandThisCodeIsExperimentalAndIWillNotUseItInProduction(); if (status_t status = server->setupVsockServer(port); status != OK) { Loading @@ -36,6 +39,8 @@ bool RunRpcServer(AIBinder* service, unsigned int port) { return false; } server->setRootObject(AIBinder_toPlatformBinder(service)); if (readyCallback) readyCallback(param); server->join(); // Shutdown any open sessions since server failed. Loading @@ -43,6 +48,10 @@ bool RunRpcServer(AIBinder* service, unsigned int port) { return true; } bool RunRpcServer(AIBinder* service, unsigned int port) { return RunRpcServerCallback(service, port, nullptr, nullptr); } AIBinder* RpcClient(unsigned int cid, unsigned int port) { auto session = RpcSession::make(); if (status_t status = session->setupVsockClient(cid, port); status != OK) { Loading @@ -52,4 +61,14 @@ AIBinder* RpcClient(unsigned int cid, unsigned int port) { } return AIBinder_fromPlatformBinder(session->getRootObject()); } AIBinder* RpcPreconnectedClient(int (*requestFd)(void* param), void* param) { auto session = RpcSession::make(); auto request = [=] { return unique_fd{requestFd(param)}; }; if (status_t status = session->setupPreconnectedClient(unique_fd{}, request); status != OK) { LOG(ERROR) << "Failed to set up vsock client. error: " << statusToString(status).c_str(); return nullptr; } return AIBinder_fromPlatformBinder(session->getRootObject()); } } libs/binder/libbinder_rpc_unstable.map.txt +2 −0 Original line number Diff line number Diff line LIBBINDER_RPC_UNSTABLE_SHIM { # platform-only global: RunRpcServer; RunRpcServerCallback; RpcClient; RpcPreconnectedClient; local: *; }; libs/binder/rust/Android.bp +1 −1 Original line number Diff line number Diff line Loading @@ -109,7 +109,7 @@ rust_bindgen { // TODO(b/184872979): remove once the Rust API is created. rust_bindgen { name: "libbinder_rpc_unstable_bindgen", wrapper_src: "src/binder_rpc_unstable.hpp", wrapper_src: ":libbinder_rpc_unstable_header", crate_name: "binder_rpc_unstable_bindgen", source_stem: "bindings", shared_libs: [ Loading Loading
libs/binder/Android.bp +6 −0 Original line number Diff line number Diff line Loading @@ -329,6 +329,7 @@ cc_library { "libbinder_ndk", "libutils", ], export_include_dirs: ["include_rpc_unstable"], // enumerate stable entry points, for apex use stubs: { Loading @@ -342,6 +343,11 @@ cc_library { ], } filegroup { name: "libbinder_rpc_unstable_header", srcs: ["include_rpc_unstable/binder_rpc_unstable.hpp"], } // libbinder historically contained additional interfaces that provided specific // functionality in the platform but have nothing to do with binder itself. These // are moved out of libbinder in order to avoid the overhead of their vtables. Loading
libs/binder/rust/src/binder_rpc_unstable.hpp→libs/binder/include_rpc_unstable/binder_rpc_unstable.hpp +44 −0 Original line number Diff line number Diff line Loading @@ -20,7 +20,25 @@ extern "C" { struct AIBinder; // Starts an RPC server on a given port and a given root IBinder object. // This function sets up the server and joins before returning. bool RunRpcServer(AIBinder* service, unsigned int port); // Starts an RPC server on a given port and a given root IBinder object. // This function sets up the server, calls readyCallback with a given param, and // then joins before returning. bool RunRpcServerCallback(AIBinder* service, unsigned int port, void (*readyCallback)(void* param), void* param); AIBinder* RpcClient(unsigned int cid, unsigned int port); // Connect to an RPC server with preconnected file descriptors. // // requestFd should connect to the server and return a valid file descriptor, or // -1 if connection fails. // // param will be passed to requestFd. Callers can use param to pass contexts to // the requestFd function. AIBinder* RpcPreconnectedClient(int (*requestFd)(void* param), void* param); }
libs/binder/libbinder_rpc_unstable.cpp +20 −1 Original line number Diff line number Diff line Loading @@ -15,6 +15,7 @@ */ #include <android-base/logging.h> #include <android-base/unique_fd.h> #include <android/binder_libbinder.h> #include <binder/RpcServer.h> #include <binder/RpcSession.h> Loading @@ -24,10 +25,12 @@ using android::RpcServer; using android::RpcSession; using android::status_t; using android::statusToString; using android::base::unique_fd; extern "C" { bool RunRpcServer(AIBinder* service, unsigned int port) { bool RunRpcServerCallback(AIBinder* service, unsigned int port, void (*readyCallback)(void* param), void* param) { auto server = RpcServer::make(); server->iUnderstandThisCodeIsExperimentalAndIWillNotUseItInProduction(); if (status_t status = server->setupVsockServer(port); status != OK) { Loading @@ -36,6 +39,8 @@ bool RunRpcServer(AIBinder* service, unsigned int port) { return false; } server->setRootObject(AIBinder_toPlatformBinder(service)); if (readyCallback) readyCallback(param); server->join(); // Shutdown any open sessions since server failed. Loading @@ -43,6 +48,10 @@ bool RunRpcServer(AIBinder* service, unsigned int port) { return true; } bool RunRpcServer(AIBinder* service, unsigned int port) { return RunRpcServerCallback(service, port, nullptr, nullptr); } AIBinder* RpcClient(unsigned int cid, unsigned int port) { auto session = RpcSession::make(); if (status_t status = session->setupVsockClient(cid, port); status != OK) { Loading @@ -52,4 +61,14 @@ AIBinder* RpcClient(unsigned int cid, unsigned int port) { } return AIBinder_fromPlatformBinder(session->getRootObject()); } AIBinder* RpcPreconnectedClient(int (*requestFd)(void* param), void* param) { auto session = RpcSession::make(); auto request = [=] { return unique_fd{requestFd(param)}; }; if (status_t status = session->setupPreconnectedClient(unique_fd{}, request); status != OK) { LOG(ERROR) << "Failed to set up vsock client. error: " << statusToString(status).c_str(); return nullptr; } return AIBinder_fromPlatformBinder(session->getRootObject()); } }
libs/binder/libbinder_rpc_unstable.map.txt +2 −0 Original line number Diff line number Diff line LIBBINDER_RPC_UNSTABLE_SHIM { # platform-only global: RunRpcServer; RunRpcServerCallback; RpcClient; RpcPreconnectedClient; local: *; };
libs/binder/rust/Android.bp +1 −1 Original line number Diff line number Diff line Loading @@ -109,7 +109,7 @@ rust_bindgen { // TODO(b/184872979): remove once the Rust API is created. rust_bindgen { name: "libbinder_rpc_unstable_bindgen", wrapper_src: "src/binder_rpc_unstable.hpp", wrapper_src: ":libbinder_rpc_unstable_header", crate_name: "binder_rpc_unstable_bindgen", source_stem: "bindings", shared_libs: [ Loading