From 06c0d048b105d1f9cc1d4599ebfe69cde4cdd3eb Mon Sep 17 00:00:00 2001 From: Kalesh Singh Date: Wed, 4 Aug 2021 15:14:34 +0000 Subject: [PATCH] libpower: Check if suspend service is null Before requesting wakelock ensure that we have a valid suspend service. Use waitForService instead of checkService. Test: libpower_test Test: block_suspend Test: atest NexusLauncherOutOfProcTests:MemoryTests#testAppLaunchFromWorkspace --rerun-until-failure 10 Bug: 195319784 Change-Id: If13e233360a7b5f372dd2991c1891ee0bee8544b --- power.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/power.cpp b/power.cpp index c40baaa..98ce861 100644 --- a/power.cpp +++ b/power.cpp @@ -40,7 +40,7 @@ static std::unordered_map> gWakeLockMap; static const std::shared_ptr getSystemSuspendServiceOnce() { static std::shared_ptr suspendService = - ISystemSuspend::fromBinder(ndk::SpAIBinder(AServiceManager_checkService( + ISystemSuspend::fromBinder(ndk::SpAIBinder(AServiceManager_waitForService( (ISystemSuspend::descriptor + std::string("/default")).c_str()))); return suspendService; } @@ -49,7 +49,7 @@ int acquire_wake_lock(int, const char* id) { ATRACE_CALL(); const auto suspendService = getSystemSuspendServiceOnce(); if (!suspendService) { - LOG(ERROR) << "ISystemSuspend::getService() failed."; + LOG(ERROR) << "Failed to get SystemSuspend service"; return -1; } @@ -115,6 +115,11 @@ WakeLock::~WakeLock() = default; WakeLock::WakeLockImpl::WakeLockImpl(const std::string& name) : mWakeLock(nullptr) { const auto suspendService = getSystemSuspendServiceOnce(); + if (!suspendService) { + LOG(ERROR) << "Failed to get SystemSuspend service"; + return; + } + std::shared_ptr wl = nullptr; auto status = suspendService->acquireWakeLock(WakeLockType::PARTIAL, name, &wl); // It's possible that during device shutdown SystemSuspend service has already exited.