Merge "Simplify libpower"
This commit is contained in:
commit
e9f8002117
1 changed files with 8 additions and 9 deletions
17
power.cpp
17
power.cpp
|
@ -36,13 +36,7 @@ static std::mutex gLock;
|
||||||
static std::unordered_map<std::string, sp<IWakeLock>> gWakeLockMap;
|
static std::unordered_map<std::string, sp<IWakeLock>> gWakeLockMap;
|
||||||
|
|
||||||
static sp<ISystemSuspend> getSystemSuspendServiceOnce() {
|
static sp<ISystemSuspend> getSystemSuspendServiceOnce() {
|
||||||
static std::once_flag initFlag;
|
static sp<ISystemSuspend> suspendService = ISystemSuspend::getService();
|
||||||
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();
|
|
||||||
});
|
|
||||||
return suspendService;
|
return suspendService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,8 +58,13 @@ int release_wake_lock(const char* id) {
|
||||||
ATRACE_CALL();
|
ATRACE_CALL();
|
||||||
std::lock_guard<std::mutex> l{gLock};
|
std::lock_guard<std::mutex> l{gLock};
|
||||||
if (gWakeLockMap[id]) {
|
if (gWakeLockMap[id]) {
|
||||||
gWakeLockMap[id]->release();
|
// Ignore errors on release() call since hwbinder driver will clean up the underlying object
|
||||||
gWakeLockMap[id] = nullptr;
|
// 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 0;
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
|
|
Loading…
Reference in a new issue