libpower: pass static-duration strong pointer as const reference.
With this change: 1. We avoid constructing a strong pointer on every call to getSystemSuspendServiceOnce(). 2. In case the function static pointer is corrupted, the error propagates to the API call where we're able to handle the errors instead of the compiler-generated code in the return statement of getSystemSuspendServiceOnce(). Bug: 117575503 Test: device builds/boots Change-Id: I85b5616efca25063c876b242529e2bf561f5b834
This commit is contained in:
parent
36c877ff06
commit
e1a9a6337f
1 changed files with 2 additions and 2 deletions
|
@ -35,14 +35,14 @@ using android::system::suspend::V1_0::WakeLockType;
|
||||||
static std::mutex gLock;
|
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 const sp<ISystemSuspend>& getSystemSuspendServiceOnce() {
|
||||||
static sp<ISystemSuspend> suspendService = ISystemSuspend::getService();
|
static sp<ISystemSuspend> suspendService = ISystemSuspend::getService();
|
||||||
return suspendService;
|
return suspendService;
|
||||||
}
|
}
|
||||||
|
|
||||||
int acquire_wake_lock(int, const char* id) {
|
int acquire_wake_lock(int, const char* id) {
|
||||||
ATRACE_CALL();
|
ATRACE_CALL();
|
||||||
sp<ISystemSuspend> suspendService = getSystemSuspendServiceOnce();
|
const auto& suspendService = getSystemSuspendServiceOnce();
|
||||||
if (!suspendService) {
|
if (!suspendService) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue