From 17b3201259827f403872d6960c694c56715b4cad Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Mon, 6 Nov 2023 12:44:27 -0800 Subject: [PATCH] audio: Change mDeathHandler from a member into a local variable Since no data is retained in mDeathHandler across member function calls, it should be a local variable instead of a member variable. Change-Id: I58d6cc511a21e0e7f430b3cf528faba072e02ec7 Signed-off-by: Bart Van Assche --- audio/aidl/vts/AudioHalBinderServiceUtil.h | 33 +++++++++++++--------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/audio/aidl/vts/AudioHalBinderServiceUtil.h b/audio/aidl/vts/AudioHalBinderServiceUtil.h index 403690ebf7..1a19ae40e8 100644 --- a/audio/aidl/vts/AudioHalBinderServiceUtil.h +++ b/audio/aidl/vts/AudioHalBinderServiceUtil.h @@ -42,20 +42,9 @@ class AudioHalBinderServiceUtil { ndk::SpAIBinder restartService( std::chrono::milliseconds timeoutMs = std::chrono::milliseconds(3000)) { - mDeathHandler.reset(new AidlDeathRecipient(mBinder)); - if (STATUS_OK != mDeathHandler->linkToDeath()) { - LOG(ERROR) << "linkToDeath failed"; - return nullptr; + if (!stopService(timeoutMs)) { + return {}; } - if (!android::base::SetProperty("sys.audio.restart.hal", "1")) { - LOG(ERROR) << "SetProperty failed"; - return nullptr; - } - if (!mDeathHandler->waitForFired(timeoutMs)) { - LOG(ERROR) << "Timeout wait for death"; - return nullptr; - } - mDeathHandler.reset(); return connectToService(mServiceName); } @@ -93,7 +82,23 @@ class AudioHalBinderServiceUtil { } }; + bool stopService(std::chrono::milliseconds timeoutMs) { + AidlDeathRecipient deathHandler(mBinder); + if (STATUS_OK != deathHandler.linkToDeath()) { + LOG(ERROR) << "linkToDeath failed"; + return false; + } + if (!android::base::SetProperty("sys.audio.restart.hal", "1")) { + LOG(ERROR) << "SetProperty failed"; + return false; + } + if (!deathHandler.waitForFired(timeoutMs)) { + LOG(ERROR) << "Timeout wait for death"; + return false; + } + return true; + } + std::string mServiceName; ndk::SpAIBinder mBinder; - std::unique_ptr mDeathHandler; };