Merge "Don't use service notifications if we can't."
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()) {