Loading libs/binder/Android.bp +26 −0 Original line number Diff line number Diff line Loading @@ -257,6 +257,32 @@ aidl_interface { }, } // TODO(b/184872979): remove once the Rust API is created. cc_library { name: "libbinder_rpc_unstable", srcs: ["libbinder_rpc_unstable.cpp"], defaults: ["libbinder_ndk_host_user"], shared_libs: [ "libbase", "libbinder", "libbinder_ndk", "libutils", ], // enumerate stable entry points, for apex use stubs: { symbol_file: "libbinder_rpc_unstable.map.txt", }, // This library is intentionally limited to these targets, and it will be removed later. // Do not expand the visibility. visibility: [ "//packages/modules/Virtualization/authfs:__subpackages__", "//packages/modules/Virtualization/compos", "//packages/modules/Virtualization/microdroid", ], } // 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/libbinder_rpc_unstable.cpp 0 → 100644 +50 −0 Original line number Diff line number Diff line /* * Copyright (C) 2021 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include <android-base/logging.h> #include <android/binder_libbinder.h> #include <binder/RpcServer.h> #include <binder/RpcSession.h> using android::RpcServer; using android::RpcSession; extern "C" { bool RunRpcServer(AIBinder* service, unsigned int port) { auto server = RpcServer::make(); server->iUnderstandThisCodeIsExperimentalAndIWillNotUseItInProduction(); if (!server->setupVsockServer(port)) { LOG(ERROR) << "Failed to set up vsock server with port " << port; return false; } server->setRootObject(AIBinder_toPlatformBinder(service)); server->join(); // Shutdown any open sessions since server failed. (void)server->shutdown(); return true; } AIBinder* RpcClient(unsigned int cid, unsigned int port) { auto session = RpcSession::make(); if (!session->setupVsockClient(cid, port)) { LOG(ERROR) << "Failed to set up vsock client with CID " << cid << " and port " << port; return nullptr; } return AIBinder_fromPlatformBinder(session->getRootObject()); } } libs/binder/libbinder_rpc_unstable.map.txt 0 → 100644 +7 −0 Original line number Diff line number Diff line LIBBINDER_RPC_UNSTABLE_SHIM { # platform-only global: RunRpcServer; RpcClient; local: *; }; libs/binder/rust/Android.bp +15 −0 Original line number Diff line number Diff line Loading @@ -106,6 +106,21 @@ 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", crate_name: "binder_rpc_unstable_bindgen", source_stem: "bindings", shared_libs: [ "libutils", ], apex_available: [ "com.android.compos", "com.android.virt", ], } rust_test { name: "libbinder_rs-internal_test", crate_name: "binder", Loading libs/binder/rust/src/binder_rpc_unstable.hpp 0 → 100644 +26 −0 Original line number Diff line number Diff line /* * Copyright (C) 2021 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #pragma once extern "C" { struct AIBinder; bool RunRpcServer(AIBinder* service, unsigned int port); AIBinder* RpcClient(unsigned int cid, unsigned int port); } Loading
libs/binder/Android.bp +26 −0 Original line number Diff line number Diff line Loading @@ -257,6 +257,32 @@ aidl_interface { }, } // TODO(b/184872979): remove once the Rust API is created. cc_library { name: "libbinder_rpc_unstable", srcs: ["libbinder_rpc_unstable.cpp"], defaults: ["libbinder_ndk_host_user"], shared_libs: [ "libbase", "libbinder", "libbinder_ndk", "libutils", ], // enumerate stable entry points, for apex use stubs: { symbol_file: "libbinder_rpc_unstable.map.txt", }, // This library is intentionally limited to these targets, and it will be removed later. // Do not expand the visibility. visibility: [ "//packages/modules/Virtualization/authfs:__subpackages__", "//packages/modules/Virtualization/compos", "//packages/modules/Virtualization/microdroid", ], } // 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/libbinder_rpc_unstable.cpp 0 → 100644 +50 −0 Original line number Diff line number Diff line /* * Copyright (C) 2021 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include <android-base/logging.h> #include <android/binder_libbinder.h> #include <binder/RpcServer.h> #include <binder/RpcSession.h> using android::RpcServer; using android::RpcSession; extern "C" { bool RunRpcServer(AIBinder* service, unsigned int port) { auto server = RpcServer::make(); server->iUnderstandThisCodeIsExperimentalAndIWillNotUseItInProduction(); if (!server->setupVsockServer(port)) { LOG(ERROR) << "Failed to set up vsock server with port " << port; return false; } server->setRootObject(AIBinder_toPlatformBinder(service)); server->join(); // Shutdown any open sessions since server failed. (void)server->shutdown(); return true; } AIBinder* RpcClient(unsigned int cid, unsigned int port) { auto session = RpcSession::make(); if (!session->setupVsockClient(cid, port)) { LOG(ERROR) << "Failed to set up vsock client with CID " << cid << " and port " << port; return nullptr; } return AIBinder_fromPlatformBinder(session->getRootObject()); } }
libs/binder/libbinder_rpc_unstable.map.txt 0 → 100644 +7 −0 Original line number Diff line number Diff line LIBBINDER_RPC_UNSTABLE_SHIM { # platform-only global: RunRpcServer; RpcClient; local: *; };
libs/binder/rust/Android.bp +15 −0 Original line number Diff line number Diff line Loading @@ -106,6 +106,21 @@ 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", crate_name: "binder_rpc_unstable_bindgen", source_stem: "bindings", shared_libs: [ "libutils", ], apex_available: [ "com.android.compos", "com.android.virt", ], } rust_test { name: "libbinder_rs-internal_test", crate_name: "binder", Loading
libs/binder/rust/src/binder_rpc_unstable.hpp 0 → 100644 +26 −0 Original line number Diff line number Diff line /* * Copyright (C) 2021 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #pragma once extern "C" { struct AIBinder; bool RunRpcServer(AIBinder* service, unsigned int port); AIBinder* RpcClient(unsigned int cid, unsigned int port); }