From 01d5a1d2f12f16c6f36309eab5cec9fd5a413933 Mon Sep 17 00:00:00 2001 From: Daniel Zheng Date: Wed, 16 Oct 2024 14:09:50 -0700 Subject: [PATCH] bootctl: fix reconnect logic Instead of just logging an error message, let's try reonnecting to the bootctl service if our death recipient is invoked. We should also reconnect our death recipient here. If binder is killed, our death recipient is automatically unlinked. Bug: 369289491 Test: kill bootctl service on CVD. Apply OTA Change-Id: I914643baaf1fa6fe1e192517a2e43e07ee749b70 --- boot/aidl/client/BootControlClient.cpp | 30 ++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/boot/aidl/client/BootControlClient.cpp b/boot/aidl/client/BootControlClient.cpp index 10f0ffe2e9..090d62416a 100644 --- a/boot/aidl/client/BootControlClient.cpp +++ b/boot/aidl/client/BootControlClient.cpp @@ -79,14 +79,32 @@ class BootControlClientAidl final : public BootControlClient { BootControlVersion GetVersion() const override { return BootControlVersion::BOOTCTL_AIDL; } - ~BootControlClientAidl() { - if (boot_control_death_recipient) { - AIBinder_unlinkToDeath(module_->asBinder().get(), boot_control_death_recipient, this); + void onBootControlServiceDied() { + LOG(ERROR) << "boot control service AIDL died. Attempting to reconnect..."; + const auto instance_name = + std::string(::aidl::android::hardware::boot::IBootControl::descriptor) + "/default"; + if (AServiceManager_isDeclared(instance_name.c_str())) { + module_ = ::aidl::android::hardware::boot::IBootControl::fromBinder( + ndk::SpAIBinder(AServiceManager_waitForService(instance_name.c_str()))); + if (module_ == nullptr) { + LOG(ERROR) << "AIDL " << instance_name + << " is declared but waitForService returned nullptr when trying to " + "reconnect boot control service"; + return; + } + LOG(INFO) << "Reconnected to AIDL version of IBootControl"; + binder_status_t status = AIBinder_linkToDeath(module_->asBinder().get(), + boot_control_death_recipient, this); + if (status != STATUS_OK) { + LOG(ERROR) << "Could not link to binder death"; + return; + } + + } else { + LOG(ERROR) << "Failed to get service manager for: " << instance_name; } } - void onBootControlServiceDied() { LOG(ERROR) << "boot control service AIDL died"; } - int32_t GetNumSlots() const override { int32_t ret = -1; LOG_NDK_STATUS(module_->getNumberSlots(&ret)); @@ -179,7 +197,7 @@ class BootControlClientAidl final : public BootControlClient { } private: - const std::shared_ptr module_; + std::shared_ptr module_; AIBinder_DeathRecipient* boot_control_death_recipient; static void onBootControlServiceDied(void* client) { BootControlClientAidl* self = static_cast(client);