Skip to content

Commit f0b5cee

Browse files
Treehugger Robotandroid-build-merge-worker-robot
authored andcommitted
Merge "Use ProcessState::selfOrNull in ServiceManager APIs" into main am: d3e05e7 am: 849c93e
Original change: https://android-review.googlesource.com/c/platform/frameworks/native/+/3315162 Change-Id: I1a07b1b5122f1c74c82a27d58ec0e02c108d32c2 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2 parents 4eb5f9f + 849c93e commit f0b5cee

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

libs/binder/BackendUnifiedServiceManager.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ static const char* kStaticCachableList[] = {
105105
};
106106

107107
bool BinderCacheWithInvalidation::isClientSideCachingEnabled(const std::string& serviceName) {
108-
if (ProcessState::self()->getThreadPoolMaxTotalThreadCount() <= 0) {
108+
sp<ProcessState> self = ProcessState::selfOrNull();
109+
if (!self || self->getThreadPoolMaxTotalThreadCount() <= 0) {
109110
ALOGW("Thread Pool max thread count is 0. Cannot cache binder as linkToDeath cannot be "
110111
"implemented. serviceName: %s",
111112
serviceName.c_str());

libs/binder/IServiceManager.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -561,8 +561,9 @@ sp<IBinder> CppBackendShim::getService(const String16& name) const {
561561
sp<IBinder> svc = checkService(name);
562562
if (svc != nullptr) return svc;
563563

564+
sp<ProcessState> self = ProcessState::selfOrNull();
564565
const bool isVendorService =
565-
strcmp(ProcessState::self()->getDriverName().c_str(), "/dev/vndbinder") == 0;
566+
self && strcmp(self->getDriverName().c_str(), "/dev/vndbinder") == 0;
566567
constexpr auto timeout = 5s;
567568
const auto startTime = std::chrono::steady_clock::now();
568569
// Vendor code can't access system properties
@@ -579,7 +580,7 @@ sp<IBinder> CppBackendShim::getService(const String16& name) const {
579580
const useconds_t sleepTime = gSystemBootCompleted ? 1000 : 100;
580581

581582
ALOGI("Waiting for service '%s' on '%s'...", String8(name).c_str(),
582-
ProcessState::self()->getDriverName().c_str());
583+
self ? self->getDriverName().c_str() : "RPC accessors only");
583584

584585
int n = 0;
585586
while (std::chrono::steady_clock::now() - startTime < timeout) {
@@ -661,7 +662,8 @@ sp<IBinder> CppBackendShim::waitForService(const String16& name16) {
661662
if (Status status = realGetService(name, &out); !status.isOk()) {
662663
ALOGW("Failed to getService in waitForService for %s: %s", name.c_str(),
663664
status.toString8().c_str());
664-
if (0 == ProcessState::self()->getThreadPoolMaxTotalThreadCount()) {
665+
sp<ProcessState> self = ProcessState::selfOrNull();
666+
if (self && 0 == self->getThreadPoolMaxTotalThreadCount()) {
665667
ALOGW("Got service, but may be racey because we could not wait efficiently for it. "
666668
"Threadpool has 0 guaranteed threads. "
667669
"Is the threadpool configured properly? "
@@ -695,9 +697,10 @@ sp<IBinder> CppBackendShim::waitForService(const String16& name16) {
695697
if (waiter->mBinder != nullptr) return waiter->mBinder;
696698
}
697699

700+
sp<ProcessState> self = ProcessState::selfOrNull();
698701
ALOGW("Waited one second for %s (is service started? Number of threads started in the "
699702
"threadpool: %zu. Are binder threads started and available?)",
700-
name.c_str(), ProcessState::self()->getThreadPoolMaxTotalThreadCount());
703+
name.c_str(), self ? self->getThreadPoolMaxTotalThreadCount() : 0);
701704

702705
// Handle race condition for lazy services. Here is what can happen:
703706
// - the service dies (not processed by init yet).

0 commit comments

Comments
 (0)