summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikita Putikhin <nputikhin@google.com>2023-12-15 09:47:35 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2023-12-15 09:47:35 +0000
commitc315f49b2ee6b88ad0883346a6a999971326b425 (patch)
tree009d777191ba178478bfafb00cf5681740a3b057
parent53f0ce5f59166a566701718860f39ac468b10f2e (diff)
parent3ff648d5ffb150b43b0fd155af577ad0fe2613d1 (diff)
downloadlibhardware_legacy-c315f49b2ee6b88ad0883346a6a999971326b425.tar.gz
Merge "Check that ISystemSuspend is declared before acquiring a wake lock" into main
-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;
}