From 781b4ff19ef369b35678cd0cbbe5ab222fae494b Mon Sep 17 00:00:00 2001 From: Kelvin Zhang Date: Mon, 27 Jun 2022 16:29:53 -0700 Subject: [PATCH] Check if AIDL service is declared before calling wait If bootctl AIDL service is not installed and we call waitForService, caller will block indefinitely. So check with AServiceManager_isDeclared before calling waitForService. Test: th Bug: 227536004 Change-Id: I551040b222c6c9127fe79aceb36bb3d69b52c3b6 --- boot/aidl/client/BootControlClient.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/boot/aidl/client/BootControlClient.cpp b/boot/aidl/client/BootControlClient.cpp index 28070eb1de..89258d2713 100644 --- a/boot/aidl/client/BootControlClient.cpp +++ b/boot/aidl/client/BootControlClient.cpp @@ -327,9 +327,14 @@ std::unique_ptr BootControlClient::WaitForService() { const auto instance_name = std::string(::aidl::android::hardware::boot::IBootControl::descriptor) + "/default"; - if (auto module = ::aidl::android::hardware::boot::IBootControl::fromBinder( + if (AServiceManager_isDeclared(instance_name.c_str())) { + auto module = ::aidl::android::hardware::boot::IBootControl::fromBinder( ndk::SpAIBinder(AServiceManager_waitForService(instance_name.c_str()))); - module != nullptr) { + if (module == nullptr) { + LOG(ERROR) << "AIDL " << instance_name + << " is declared but waitForService returned nullptr."; + return nullptr; + } LOG(INFO) << "Using AIDL version of IBootControl"; return std::make_unique(module); }