Merge "libpower: Check if suspend service is null" am: a719829bb8 am: 17c06cc780 am: 019e325e34 am: d6d2e1a677

Original change: https://android-review.googlesource.com/c/platform/hardware/libhardware_legacy/+/1786228

Change-Id: Ie5be5290f639e6c17882a9109917568c00e5be8d
This commit is contained in:
Kalesh Singh 2021-08-04 21:14:33 +00:00 committed by Automerger Merge Worker
commit f77e00c734

View file

@ -40,7 +40,7 @@ static std::unordered_map<std::string, std::shared_ptr<IWakeLock>> gWakeLockMap;
static const std::shared_ptr<ISystemSuspend> getSystemSuspendServiceOnce() {
static std::shared_ptr<ISystemSuspend> suspendService =
ISystemSuspend::fromBinder(ndk::SpAIBinder(AServiceManager_checkService(
ISystemSuspend::fromBinder(ndk::SpAIBinder(AServiceManager_waitForService(
(ISystemSuspend::descriptor + std::string("/default")).c_str())));
return suspendService;
}
@ -49,7 +49,7 @@ int acquire_wake_lock(int, const char* id) {
ATRACE_CALL();
const auto suspendService = getSystemSuspendServiceOnce();
if (!suspendService) {
LOG(ERROR) << "ISystemSuspend::getService() failed.";
LOG(ERROR) << "Failed to get SystemSuspend service";
return -1;
}
@ -115,6 +115,11 @@ WakeLock::~WakeLock() = default;
WakeLock::WakeLockImpl::WakeLockImpl(const std::string& name) : mWakeLock(nullptr) {
const auto suspendService = getSystemSuspendServiceOnce();
if (!suspendService) {
LOG(ERROR) << "Failed to get SystemSuspend service";
return;
}
std::shared_ptr<IWakeLock> wl = nullptr;
auto status = suspendService->acquireWakeLock(WakeLockType::PARTIAL, name, &wl);
// It's possible that during device shutdown SystemSuspend service has already exited.