From 3ff648d5ffb150b43b0fd155af577ad0fe2613d1 Mon Sep 17 00:00:00 2001 From: Nikita Putikhin Date: Tue, 12 Dec 2023 16:51:58 +0100 Subject: [PATCH] Check that ISystemSuspend is declared before acquiring a wake lock On some systems (Minidroid & friends) there is no suspend-service, which means that acquiring a wake lock would wait indefinitely. In our case this prevented `adb bugreport` from working. With this change if the service is not declared, acquire_wake_lock would fail, as opposed to getting stuck. Test: atest libpower_test Test: block_suspend - works on aosp_cf_x86_64_phone-trunk_staging-userdebug - fails (expected) on aosp_cf_x86_64_minidroid-trunk_staging-userdebug Bug: 291070376 Change-Id: Ie25f3d96e457aa7945f36c301e70b751d529e6c7 --- power.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/power.cpp b/power.cpp index 98ce861..6041207 100644 --- a/power.cpp +++ b/power.cpp @@ -40,8 +40,15 @@ static std::unordered_map> gWakeLockMap; static const std::shared_ptr getSystemSuspendServiceOnce() { static std::shared_ptr suspendService = - ISystemSuspend::fromBinder(ndk::SpAIBinder(AServiceManager_waitForService( - (ISystemSuspend::descriptor + std::string("/default")).c_str()))); + []() -> std::shared_ptr { + std::string suspendServiceName = + ISystemSuspend::descriptor + std::string("/default"); + if (!AServiceManager_isDeclared(suspendServiceName.c_str())) { + return nullptr; + } + return ISystemSuspend::fromBinder(ndk::SpAIBinder( + AServiceManager_waitForService(suspendServiceName.c_str()))); + }(); return suspendService; }