summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKalesh Singh <kaleshsingh@google.com>2021-08-04 20:13:01 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2021-08-04 20:13:01 +0000
commita719829bb88db74c4acc0292ffc71c0d3df0f8f7 (patch)
tree64b9efd740e927068d674013fe87f1963728c67d
parentfc7f7499c24b736e3b9051e6cd98787cfc942e0a (diff)
parent06c0d048b105d1f9cc1d4599ebfe69cde4cdd3eb (diff)
downloadlibhardware_legacy-a719829bb88db74c4acc0292ffc71c0d3df0f8f7.tar.gz
Merge "libpower: Check if suspend service is null"
-rw-r--r--power.cpp9
1 files 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<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_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<IWakeLock> wl = nullptr;
auto status = suspendService->acquireWakeLock(WakeLockType::PARTIAL, name, &wl);
// It's possible that during device shutdown SystemSuspend service has already exited.