summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikita Putikhin <nputikhin@google.com>2023-12-12 16:51:58 +0100
committerNikita Putikhin <nputikhin@google.com>2023-12-13 12:00:35 +0100
commit3ff648d5ffb150b43b0fd155af577ad0fe2613d1 (patch)
tree009d777191ba178478bfafb00cf5681740a3b057
parent53f0ce5f59166a566701718860f39ac468b10f2e (diff)
downloadlibhardware_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.cpp11
1 files 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<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;
}