diff options
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). |