Merge "Check that ISystemSuspend is declared before acquiring a wake lock" into main am: c315f49b2e am: a39da7cb44 am: 9cfa2eca98

Original change: https://android-review.googlesource.com/c/platform/hardware/libhardware_legacy/+/2870803

Change-Id: I81b054572ce193bdedf7b6f6b7f12ca430468f9f
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Nikita Putikhin 2023-12-15 11:19:52 +00:00 committed by Automerger Merge Worker
commit ce7bbb5409

View file

@ -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;
}