Merge "Check that ISystemSuspend is declared before acquiring a wake lock" into main

This commit is contained in:
Nikita Putikhin 2023-12-15 09:47:35 +00:00 committed by Gerrit Code Review
commit c315f49b2e

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 const std::shared_ptr<ISystemSuspend> getSystemSuspendServiceOnce() {
static std::shared_ptr<ISystemSuspend> suspendService = static std::shared_ptr<ISystemSuspend> suspendService =
ISystemSuspend::fromBinder(ndk::SpAIBinder(AServiceManager_waitForService( []() -> std::shared_ptr<ISystemSuspend> {
(ISystemSuspend::descriptor + std::string("/default")).c_str()))); 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; return suspendService;
} }