Simplify libpower

Changed:
- simplified getting system suspend service
- added isOk() check when releasing a wake lock

Bug: 117575503
Test: presubmit
Change-Id: I78f1f50a7670e7df88e59999c35f99a6df06e8ef
This commit is contained in:
Tri Vo 2018-10-14 16:09:51 -07:00
parent aa8f6d2a2d
commit 8eb59a0050

View file

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