diff options
author | Tri Vo <trong@google.com> | 2018-10-14 16:09:51 -0700 |
---|---|---|
committer | Tri Vo <trong@google.com> | 2018-10-16 13:30:58 -0700 |
commit | 8eb59a0050da42162b78444538e271989fed23f6 (patch) | |
tree | 84203a2f3c41d0d6b76092c177dacdc085648d2e | |
parent | aa8f6d2a2dcface3e5a51118a84152d98a6590f7 (diff) | |
download | libhardware_legacy-8eb59a0050da42162b78444538e271989fed23f6.tar.gz |
Simplify libpower
Changed:
- simplified getting system suspend service
- added isOk() check when releasing a wake lock
Bug: 117575503
Test: presubmit
Change-Id: I78f1f50a7670e7df88e59999c35f99a6df06e8ef
-rw-r--r-- | power.cpp | 17 |
1 files changed, 8 insertions, 9 deletions
@@ -36,13 +36,7 @@ static std::mutex gLock; static std::unordered_map<std::string, sp<IWakeLock>> gWakeLockMap; static sp<ISystemSuspend> getSystemSuspendServiceOnce() { - static std::once_flag initFlag; - static sp<ISystemSuspend> suspendService = nullptr; - std::call_once(initFlag, []() { - // It's possible for the calling process to not have permissions to - // ISystemSuspend. getService will then return nullptr. - suspendService = ISystemSuspend::getService(); - }); + static sp<ISystemSuspend> suspendService = ISystemSuspend::getService(); return suspendService; } @@ -64,8 +58,13 @@ int release_wake_lock(const char* id) { ATRACE_CALL(); std::lock_guard<std::mutex> l{gLock}; if (gWakeLockMap[id]) { - gWakeLockMap[id]->release(); - gWakeLockMap[id] = nullptr; + // Ignore errors on release() call since hwbinder driver will clean up the underlying object + // once we clear the corresponding strong pointer. + auto ret = gWakeLockMap[id]->release(); + if (!ret.isOk()) { + LOG(ERROR) << "IWakeLock::release() call failed: " << ret.description(); + } + gWakeLockMap[id].clear(); return 0; } return -1; |