Only construct waiter when we need it.
To avoid needless service notification registrations
when fetching passthrough services.
Test: sailfish boots
Bug: 74371737
Change-Id: Ia151322a8b4da10b60389b817be83200bbd00cf6
Merged-In: Ia151322a8b4da10b60389b817be83200bbd00cf6
diff --git a/transport/ServiceManagement.cpp b/transport/ServiceManagement.cpp
index e3c19e5..dd6736f 100644
--- a/transport/ServiceManagement.cpp
+++ b/transport/ServiceManagement.cpp
@@ -635,6 +635,7 @@
using Transport = ::android::hidl::manager::V1_0::IServiceManager::Transport;
using ::android::hidl::base::V1_0::IBase;
using ::android::hidl::manager::V1_0::IServiceManager;
+ sp<Waiter> waiter;
const sp<IServiceManager1_1> sm = defaultServiceManager1_1();
if (sm == nullptr) {
@@ -670,8 +671,10 @@
const bool vintfLegacy = (transport == Transport::EMPTY);
#endif // ENFORCE_VINTF_MANIFEST
- sp<Waiter> waiter = new Waiter(descriptor, instance, sm);
while (!getStub && (vintfHwbinder || vintfLegacy)) {
+ if (waiter == nullptr) {
+ waiter = new Waiter(descriptor, instance, sm);
+ }
waiter->reset(); // don't reorder this -- see comments on reset()
Return<sp<IBase>> ret = sm->get(descriptor, instance);
if (!ret.isOk()) {
@@ -699,7 +702,9 @@
waiter->wait();
}
- waiter->done();
+ if (waiter != nullptr) {
+ waiter->done();
+ }
if (getStub || vintfPassthru || vintfLegacy) {
const sp<IServiceManager> pm = getPassthroughServiceManager();