diff options
author | Nikita Putikhin <nputikhin@google.com> | 2023-12-12 16:51:58 +0100 |
---|---|---|
committer | Nikita Putikhin <nputikhin@google.com> | 2023-12-13 12:00:35 +0100 |
commit | 3ff648d5ffb150b43b0fd155af577ad0fe2613d1 (patch) | |
tree | 009d777191ba178478bfafb00cf5681740a3b057 | |
parent | 53f0ce5f59166a566701718860f39ac468b10f2e (diff) | |
download | libhardware_legacy-3ff648d5ffb150b43b0fd155af577ad0fe2613d1.tar.gz |
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
-rw-r--r-- | power.cpp | 11 |
1 files changed, 9 insertions, 2 deletions
@@ -40,8 +40,15 @@ static std::unordered_map<std::string, std::shared_ptr<IWakeLock>> gWakeLockMap; static const std::shared_ptr<ISystemSuspend> getSystemSuspendServiceOnce() { static std::shared_ptr<ISystemSuspend> suspendService = - ISystemSuspend::fromBinder(ndk::SpAIBinder(AServiceManager_waitForService( - (ISystemSuspend::descriptor + std::string("/default")).c_str()))); + []() -> std::shared_ptr<ISystemSuspend> { + 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; } |