Merge "libpower: handle SystemSuspend shutdown on client side."
diff --git a/power.cpp b/power.cpp
index c4f2036..e9b6ccd 100644
--- a/power.cpp
+++ b/power.cpp
@@ -49,7 +49,15 @@
std::lock_guard<std::mutex> l{gLock};
if (!gWakeLockMap[id]) {
- gWakeLockMap[id] = suspendService->acquireWakeLock(WakeLockType::PARTIAL, id);
+ auto ret = suspendService->acquireWakeLock(WakeLockType::PARTIAL, id);
+ // It's possible that during device shutdown SystemSuspend service has already exited. In
+ // these situations HIDL calls to it will result in a DEAD_OBJECT transaction error. We
+ // check for DEAD_OBJECT so that libpower clients can shutdown cleanly.
+ if (ret.isDeadObject()) {
+ return -1;
+ } else {
+ gWakeLockMap[id] = ret;
+ }
}
return 0;
}