getService: re-request HALs after timeout
am: 0771d8a8b8
Change-Id: I93957933583d370fa9528f8b7d090ca19b5d3fdb
diff --git a/transport/ServiceManagement.cpp b/transport/ServiceManagement.cpp
index f11acab..8c46506 100644
--- a/transport/ServiceManagement.cpp
+++ b/transport/ServiceManagement.cpp
@@ -537,7 +537,7 @@
return Void();
}
- void wait() {
+ void wait(bool timeout) {
using std::literals::chrono_literals::operator""s;
if (!mRegisteredForNotifications) {
@@ -548,7 +548,7 @@
}
std::unique_lock<std::mutex> lock(mMutex);
- while(true) {
+ do {
mCondition.wait_for(lock, 1s, [this]{
return mRegistered;
});
@@ -557,9 +557,8 @@
break;
}
- LOG(WARNING) << "Waited one second for " << mInterfaceName << "/" << mInstanceName
- << ". Waiting another...";
- }
+ LOG(WARNING) << "Waited one second for " << mInterfaceName << "/" << mInstanceName;
+ } while (!timeout);
}
// Be careful when using this; after calling reset(), you must always try to retrieve
@@ -600,7 +599,7 @@
void waitForHwService(
const std::string &interface, const std::string &instanceName) {
sp<Waiter> waiter = new Waiter(interface, instanceName, defaultServiceManager1_1());
- waiter->wait();
+ waiter->wait(false /* timeout */);
waiter->done();
}
@@ -710,7 +709,7 @@
if (waiter != nullptr) {
ALOGI("getService: Trying again for %s/%s...", descriptor.c_str(), instance.c_str());
- waiter->wait();
+ waiter->wait(true /* timeout */);
}
}
diff --git a/transport/include/hidl/ServiceManagement.h b/transport/include/hidl/ServiceManagement.h
index 4df156b..968c385 100644
--- a/transport/include/hidl/ServiceManagement.h
+++ b/transport/include/hidl/ServiceManagement.h
@@ -43,6 +43,7 @@
const std::string &interfaceName,
const std::string &instanceName);
+// Will not attempt to start a lazy HAL
// e.x.: android.hardware.foo@1.0::IFoo, default
void waitForHwService(const std::string &interface, const std::string &instanceName);