diff options
author | 2024-10-23 17:12:19 +0000 | |
---|---|---|
committer | 2024-10-25 21:58:02 +0000 | |
commit | 74bc589a226cf790a7d600dbe32a3a5861a5b265 (patch) | |
tree | 8546eae7f00c9fc5fd672b4a066fc94629eb03ae /libs/binder/IServiceManager.cpp | |
parent | dcca938df5392f77110c0a89820f0e22ae379b55 (diff) |
Use ProcessState::selfOrNull in ServiceManager APIs
Allow the APIs to be used when ProcessState isn't initialized.
This allows the use of these APIs in systems like microdroid where there
is no kernel binder driver.
Test: atest vm_accessor_test
Bug: 358427181
Change-Id: Ie981b0ca4335ddc7a5676d30721c01be1ffdf35e
Diffstat (limited to 'libs/binder/IServiceManager.cpp')
-rw-r--r-- | libs/binder/IServiceManager.cpp | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/libs/binder/IServiceManager.cpp b/libs/binder/IServiceManager.cpp index 32388db076..39d8c2446e 100644 --- a/libs/binder/IServiceManager.cpp +++ b/libs/binder/IServiceManager.cpp @@ -561,8 +561,9 @@ sp<IBinder> CppBackendShim::getService(const String16& name) const { sp<IBinder> svc = checkService(name); if (svc != nullptr) return svc; + sp<ProcessState> self = ProcessState::selfOrNull(); const bool isVendorService = - strcmp(ProcessState::self()->getDriverName().c_str(), "/dev/vndbinder") == 0; + self && strcmp(self->getDriverName().c_str(), "/dev/vndbinder") == 0; constexpr auto timeout = 5s; const auto startTime = std::chrono::steady_clock::now(); // Vendor code can't access system properties @@ -579,7 +580,7 @@ sp<IBinder> CppBackendShim::getService(const String16& name) const { const useconds_t sleepTime = gSystemBootCompleted ? 1000 : 100; ALOGI("Waiting for service '%s' on '%s'...", String8(name).c_str(), - ProcessState::self()->getDriverName().c_str()); + self ? self->getDriverName().c_str() : "RPC accessors only"); int n = 0; while (std::chrono::steady_clock::now() - startTime < timeout) { @@ -661,7 +662,8 @@ sp<IBinder> CppBackendShim::waitForService(const String16& name16) { if (Status status = realGetService(name, &out); !status.isOk()) { ALOGW("Failed to getService in waitForService for %s: %s", name.c_str(), status.toString8().c_str()); - if (0 == ProcessState::self()->getThreadPoolMaxTotalThreadCount()) { + sp<ProcessState> self = ProcessState::selfOrNull(); + if (self && 0 == self->getThreadPoolMaxTotalThreadCount()) { ALOGW("Got service, but may be racey because we could not wait efficiently for it. " "Threadpool has 0 guaranteed threads. " "Is the threadpool configured properly? " @@ -695,9 +697,10 @@ sp<IBinder> CppBackendShim::waitForService(const String16& name16) { if (waiter->mBinder != nullptr) return waiter->mBinder; } + sp<ProcessState> self = ProcessState::selfOrNull(); ALOGW("Waited one second for %s (is service started? Number of threads started in the " "threadpool: %zu. Are binder threads started and available?)", - name.c_str(), ProcessState::self()->getThreadPoolMaxTotalThreadCount()); + name.c_str(), self ? self->getThreadPoolMaxTotalThreadCount() : 0); // Handle race condition for lazy services. Here is what can happen: // - the service dies (not processed by init yet). |