Merge "Define android.software.credentials.xml as prebuilt_etc" into main
diff --git a/libs/binder/Android.bp b/libs/binder/Android.bp
index 1abde5c..80720b0 100644
--- a/libs/binder/Android.bp
+++ b/libs/binder/Android.bp
@@ -267,7 +267,20 @@
"-Wunused-const-variable",
"-DANDROID_BASE_UNIQUE_FD_DISABLE_IMPLICIT_CONVERSION",
"-DANDROID_UTILS_REF_BASE_DISABLE_IMPLICIT_CONSTRUCTION",
+ // Hide symbols by default and set the BUILDING_LIBBINDER macro so that
+ // the code knows to export them.
+ "-fvisibility=hidden",
+ "-DBUILDING_LIBBINDER",
],
+
+ target: {
+ vendor: {
+ // Trimming the exported symbols reveals a bug in vendor code, so
+ // disable it for the vendor variant for now. http://b/349657329
+ // TODO: Fix the issue and remove this override.
+ cflags: ["-fvisibility=default"],
+ },
+ },
}
cc_defaults {
diff --git a/libs/binder/BackendUnifiedServiceManager.cpp b/libs/binder/BackendUnifiedServiceManager.cpp
index 496c5ef..b0d3048 100644
--- a/libs/binder/BackendUnifiedServiceManager.cpp
+++ b/libs/binder/BackendUnifiedServiceManager.cpp
@@ -15,6 +15,10 @@
*/
#include "BackendUnifiedServiceManager.h"
+#if defined(__BIONIC__) && !defined(__ANDROID_VNDK__)
+#include <android-base/properties.h>
+#endif
+
namespace android {
using AidlServiceManager = android::os::IServiceManager;
diff --git a/libs/binder/BackendUnifiedServiceManager.h b/libs/binder/BackendUnifiedServiceManager.h
index a67d5ba..d72b5bb 100644
--- a/libs/binder/BackendUnifiedServiceManager.h
+++ b/libs/binder/BackendUnifiedServiceManager.h
@@ -15,7 +15,6 @@
*/
#pragma once
-#include <android-base/properties.h>
#include <android/os/BnServiceManager.h>
#include <android/os/IServiceManager.h>
#include <binder/IPCThreadState.h>
diff --git a/libs/binder/IServiceManager.cpp b/libs/binder/IServiceManager.cpp
index 50d00ae..2095586 100644
--- a/libs/binder/IServiceManager.cpp
+++ b/libs/binder/IServiceManager.cpp
@@ -16,8 +16,8 @@
#define LOG_TAG "ServiceManagerCppClient"
-#include <BackendUnifiedServiceManager.h>
#include <binder/IServiceManager.h>
+#include "BackendUnifiedServiceManager.h"
#include <inttypes.h>
#include <unistd.h>
diff --git a/libs/binder/RpcServer.cpp b/libs/binder/RpcServer.cpp
index d9e926a..b8742af 100644
--- a/libs/binder/RpcServer.cpp
+++ b/libs/binder/RpcServer.cpp
@@ -71,8 +71,23 @@
return setupSocketServer(UnixSocketAddress(path));
}
-status_t RpcServer::setupVsockServer(unsigned int bindCid, unsigned int port) {
- return setupSocketServer(VsockSocketAddress(bindCid, port));
+status_t RpcServer::setupVsockServer(unsigned bindCid, unsigned port, unsigned* assignedPort) {
+ auto status = setupSocketServer(VsockSocketAddress(bindCid, port));
+ if (status != OK) return status;
+
+ if (assignedPort == nullptr) return OK;
+ sockaddr_vm addr;
+ socklen_t len = sizeof(addr);
+ if (0 != getsockname(mServer.fd.get(), reinterpret_cast<sockaddr*>(&addr), &len)) {
+ status = -errno;
+ ALOGE("setupVsockServer: Failed to getsockname: %s", strerror(-status));
+ return status;
+ }
+
+ LOG_ALWAYS_FATAL_IF(len != sizeof(addr), "Wrong socket type: len %zu vs len %zu",
+ static_cast<size_t>(len), sizeof(addr));
+ *assignedPort = addr.svm_port;
+ return OK;
}
status_t RpcServer::setupInetServer(const char* address, unsigned int port,
diff --git a/libs/binder/include/binder/BpBinder.h b/libs/binder/include/binder/BpBinder.h
index 8ac30ba..d7f74c4 100644
--- a/libs/binder/include/binder/BpBinder.h
+++ b/libs/binder/include/binder/BpBinder.h
@@ -176,10 +176,10 @@
BpBinder(BinderHandle&& handle, int32_t trackedUid);
explicit BpBinder(RpcHandle&& handle);
- virtual ~BpBinder();
- virtual void onFirstRef();
- virtual void onLastStrongRef(const void* id);
- virtual bool onIncStrongAttempted(uint32_t flags, const void* id);
+ virtual ~BpBinder();
+ virtual void onFirstRef();
+ virtual void onLastStrongRef(const void* id);
+ virtual bool onIncStrongAttempted(uint32_t flags, const void* id);
friend ::android::internal::Stability;
@@ -192,30 +192,30 @@
uint32_t flags;
};
- void reportOneDeath(const Obituary& obit);
- bool isDescriptorCached() const;
+ void reportOneDeath(const Obituary& obit);
+ bool isDescriptorCached() const;
- mutable RpcMutex mLock;
- volatile int32_t mAlive;
- volatile int32_t mObitsSent;
- Vector<Obituary>* mObituaries;
- ObjectManager mObjects;
- mutable String16 mDescriptorCache;
- int32_t mTrackedUid;
+ mutable RpcMutex mLock;
+ volatile int32_t mAlive;
+ volatile int32_t mObitsSent;
+ Vector<Obituary>* mObituaries;
+ ObjectManager mObjects;
+ mutable String16 mDescriptorCache;
+ int32_t mTrackedUid;
- static RpcMutex sTrackingLock;
- static std::unordered_map<int32_t,uint32_t> sTrackingMap;
- static int sNumTrackedUids;
- static std::atomic_bool sCountByUidEnabled;
- static binder_proxy_limit_callback sLimitCallback;
- static uint32_t sBinderProxyCountHighWatermark;
- static uint32_t sBinderProxyCountLowWatermark;
- static bool sBinderProxyThrottleCreate;
- static std::unordered_map<int32_t,uint32_t> sLastLimitCallbackMap;
- static std::atomic<uint32_t> sBinderProxyCount;
- static std::atomic<uint32_t> sBinderProxyCountWarned;
- static binder_proxy_warning_callback sWarningCallback;
- static uint32_t sBinderProxyCountWarningWatermark;
+ static RpcMutex sTrackingLock;
+ static std::unordered_map<int32_t, uint32_t> sTrackingMap;
+ static int sNumTrackedUids;
+ static std::atomic_bool sCountByUidEnabled;
+ static binder_proxy_limit_callback sLimitCallback;
+ static uint32_t sBinderProxyCountHighWatermark;
+ static uint32_t sBinderProxyCountLowWatermark;
+ static bool sBinderProxyThrottleCreate;
+ static std::unordered_map<int32_t, uint32_t> sLastLimitCallbackMap;
+ static std::atomic<uint32_t> sBinderProxyCount;
+ static std::atomic<uint32_t> sBinderProxyCountWarned;
+ static binder_proxy_warning_callback sWarningCallback;
+ static uint32_t sBinderProxyCountWarningWatermark;
};
} // namespace android
diff --git a/libs/binder/include/binder/RpcServer.h b/libs/binder/include/binder/RpcServer.h
index abea0fb..c241d31 100644
--- a/libs/binder/include/binder/RpcServer.h
+++ b/libs/binder/include/binder/RpcServer.h
@@ -85,9 +85,12 @@
/**
* Creates an RPC server binding to the given CID at the given port.
+ *
+ * Set |port| to VMADDR_PORT_ANY to pick an ephemeral port. In this case, |assignedPort|
+ * will be set to the picked port number, if it is not null.
*/
- [[nodiscard]] LIBBINDER_EXPORTED status_t setupVsockServer(unsigned int bindCid,
- unsigned int port);
+ [[nodiscard]] LIBBINDER_EXPORTED status_t setupVsockServer(unsigned bindCid, unsigned port,
+ unsigned* assignedPort = nullptr);
/**
* Creates an RPC server at the current port using IPv4.
diff --git a/libs/binder/ndk/tests/libbinder_ndk_unit_test.cpp b/libs/binder/ndk/tests/libbinder_ndk_unit_test.cpp
index 966ec95..666b3af 100644
--- a/libs/binder/ndk/tests/libbinder_ndk_unit_test.cpp
+++ b/libs/binder/ndk/tests/libbinder_ndk_unit_test.cpp
@@ -826,22 +826,22 @@
class MyResultReceiver : public BnResultReceiver {
public:
- Mutex mMutex;
- Condition mCondition;
+ std::mutex mMutex;
+ std::condition_variable mCondition;
bool mHaveResult = false;
int32_t mResult = 0;
virtual void send(int32_t resultCode) {
- AutoMutex _l(mMutex);
+ std::unique_lock<std::mutex> _l(mMutex);
mResult = resultCode;
mHaveResult = true;
- mCondition.signal();
+ mCondition.notify_one();
}
int32_t waitForResult() {
- AutoMutex _l(mMutex);
+ std::unique_lock<std::mutex> _l(mMutex);
while (!mHaveResult) {
- mCondition.wait(mMutex);
+ mCondition.wait(_l);
}
return mResult;
}
diff --git a/libs/binder/tests/BinderRpcTestServerConfig.aidl b/libs/binder/tests/BinderRpcTestServerConfig.aidl
index b2e0ef2..96550bc 100644
--- a/libs/binder/tests/BinderRpcTestServerConfig.aidl
+++ b/libs/binder/tests/BinderRpcTestServerConfig.aidl
@@ -20,7 +20,6 @@
int socketType;
int rpcSecurity;
int serverVersion;
- int vsockPort;
int socketFd; // Inherited from the parent process.
@utf8InCpp String addr;
}
diff --git a/libs/binder/tests/binderRpcTest.cpp b/libs/binder/tests/binderRpcTest.cpp
index 19882ea..9b1b64a 100644
--- a/libs/binder/tests/binderRpcTest.cpp
+++ b/libs/binder/tests/binderRpcTest.cpp
@@ -141,11 +141,6 @@
return ret;
};
-static unsigned int allocateVsockPort() {
- static unsigned int vsockPort = 34567;
- return vsockPort++;
-}
-
static unique_fd initUnixSocket(std::string addr) {
auto socket_addr = UnixSocketAddress(addr.c_str());
unique_fd fd(TEMP_FAILURE_RETRY(socket(socket_addr.addr()->sa_family, SOCK_STREAM, AF_UNIX)));
@@ -300,7 +295,6 @@
serverConfig.socketType = static_cast<int32_t>(socketType);
serverConfig.rpcSecurity = static_cast<int32_t>(rpcSecurity);
serverConfig.serverVersion = serverVersion;
- serverConfig.vsockPort = allocateVsockPort();
serverConfig.addr = addr;
serverConfig.socketFd = socketFd.get();
for (auto mode : options.serverSupportedFileDescriptorTransportModes) {
@@ -379,7 +373,7 @@
unique_fd(dup(bootstrapClientFd.get())));
break;
case SocketType::VSOCK:
- status = session->setupVsockClient(VMADDR_CID_LOCAL, serverConfig.vsockPort);
+ status = session->setupVsockClient(VMADDR_CID_LOCAL, serverInfo.port);
break;
case SocketType::INET:
status = session->setupInetClient("127.0.0.1", serverInfo.port);
@@ -1152,8 +1146,6 @@
#else // BINDER_RPC_TO_TRUSTY_TEST
bool testSupportVsockLoopback() {
// We don't need to enable TLS to know if vsock is supported.
- unsigned int vsockPort = allocateVsockPort();
-
unique_fd serverFd(
TEMP_FAILURE_RETRY(socket(AF_VSOCK, SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0)));
@@ -1165,16 +1157,21 @@
sockaddr_vm serverAddr{
.svm_family = AF_VSOCK,
- .svm_port = vsockPort,
+ .svm_port = VMADDR_PORT_ANY,
.svm_cid = VMADDR_CID_ANY,
};
int ret = TEMP_FAILURE_RETRY(
bind(serverFd.get(), reinterpret_cast<sockaddr*>(&serverAddr), sizeof(serverAddr)));
- LOG_ALWAYS_FATAL_IF(0 != ret, "Could not bind socket to port %u: %s", vsockPort,
+ LOG_ALWAYS_FATAL_IF(0 != ret, "Could not bind socket to port VMADDR_PORT_ANY: %s",
strerror(errno));
+ socklen_t len = sizeof(serverAddr);
+ ret = getsockname(serverFd.get(), reinterpret_cast<sockaddr*>(&serverAddr), &len);
+ LOG_ALWAYS_FATAL_IF(0 != ret, "Failed to getsockname: %s", strerror(errno));
+ LOG_ALWAYS_FATAL_IF(len < sizeof(serverAddr), "getsockname didn't read the full addr struct");
+
ret = TEMP_FAILURE_RETRY(listen(serverFd.get(), 1 /*backlog*/));
- LOG_ALWAYS_FATAL_IF(0 != ret, "Could not listen socket on port %u: %s", vsockPort,
+ LOG_ALWAYS_FATAL_IF(0 != ret, "Could not listen socket on port %u: %s", serverAddr.svm_port,
strerror(errno));
// Try to connect to the server using the VMADDR_CID_LOCAL cid
@@ -1183,13 +1180,13 @@
// and they return ETIMEDOUT after that.
unique_fd connectFd(
TEMP_FAILURE_RETRY(socket(AF_VSOCK, SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0)));
- LOG_ALWAYS_FATAL_IF(!connectFd.ok(), "Could not create socket for port %u: %s", vsockPort,
- strerror(errno));
+ LOG_ALWAYS_FATAL_IF(!connectFd.ok(), "Could not create socket for port %u: %s",
+ serverAddr.svm_port, strerror(errno));
bool success = false;
sockaddr_vm connectAddr{
.svm_family = AF_VSOCK,
- .svm_port = vsockPort,
+ .svm_port = serverAddr.svm_port,
.svm_cid = VMADDR_CID_LOCAL,
};
ret = TEMP_FAILURE_RETRY(connect(connectFd.get(), reinterpret_cast<sockaddr*>(&connectAddr),
@@ -1538,8 +1535,9 @@
};
} break;
case SocketType::VSOCK: {
- auto port = allocateVsockPort();
- auto status = rpcServer->setupVsockServer(VMADDR_CID_LOCAL, port);
+ unsigned port;
+ auto status =
+ rpcServer->setupVsockServer(VMADDR_CID_LOCAL, VMADDR_PORT_ANY, &port);
if (status != OK) {
return AssertionFailure() << "setupVsockServer: " << statusToString(status);
}
diff --git a/libs/binder/tests/binderRpcTestService.cpp b/libs/binder/tests/binderRpcTestService.cpp
index 28125f1..aef9464 100644
--- a/libs/binder/tests/binderRpcTestService.cpp
+++ b/libs/binder/tests/binderRpcTestService.cpp
@@ -143,8 +143,8 @@
break;
case SocketType::VSOCK:
LOG_ALWAYS_FATAL_IF(OK !=
- server->setupVsockServer(VMADDR_CID_LOCAL,
- serverConfig.vsockPort),
+ server->setupVsockServer(VMADDR_CID_LOCAL, VMADDR_PORT_ANY,
+ &outPort),
"Need `sudo modprobe vsock_loopback`?");
break;
case SocketType::INET: {