Don't use service notifications if we can't.
When we only have one binder thread, calling waiter->wait()
will block forever.
Bug: 35117173
Test: boots
Change-Id: Ib5065bc384830b8056f6913ceecf98427e6f6788
diff --git a/transport/ServiceManagement.cpp b/transport/ServiceManagement.cpp
index 04f7290..34e6ea4 100644
--- a/transport/ServiceManagement.cpp
+++ b/transport/ServiceManagement.cpp
@@ -473,6 +473,18 @@
}
void onFirstRef() override {
+ // If this process only has one binder thread, and we're calling wait() from
+ // that thread, it will block forever because we hung up the one and only
+ // binder thread on a condition variable that can only be notified by an
+ // incoming binder call.
+ if (ProcessState::self()->getMaxThreads() <= 1 &&
+ IPCThreadState::self()->isLooperThread()) {
+ LOG(WARNING) << "Can't efficiently wait for " << mInterfaceName << "/"
+ << mInstanceName << ", because we are called from "
+ << "the only binder thread in this process.";
+ return;
+ }
+
Return<bool> ret = mSm->registerForNotifications(mInterfaceName, mInstanceName, this);
if (!ret.isOk()) {