Merge "libpower: Check if suspend service is null" am: a719829bb8

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

Change-Id: I7419ba70ee90ea493f8b0174a31040d1225d2af8
This commit is contained in:
Kalesh Singh 2021-08-04 20:29:06 +00:00 committed by Automerger Merge Worker
commit 17c06cc780

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.