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:
Tri Vo 2018-10-22 13:29:24 -07:00
parent 36c877ff06
commit e1a9a6337f

View file

@ -35,14 +35,14 @@ using android::system::suspend::V1_0::WakeLockType;
static std::mutex gLock;
static std::unordered_map<std::string, sp<IWakeLock>> gWakeLockMap;
static sp<ISystemSuspend> getSystemSuspendServiceOnce() {
static const sp<ISystemSuspend>& getSystemSuspendServiceOnce() {
static sp<ISystemSuspend> suspendService = ISystemSuspend::getService();
return suspendService;
}
int acquire_wake_lock(int, const char* id) {
ATRACE_CALL();
sp<ISystemSuspend> suspendService = getSystemSuspendServiceOnce();
const auto& suspendService = getSystemSuspendServiceOnce();
if (!suspendService) {
return -1;
}