From: Tri Vo Date: Thu, 20 Dec 2018 20:53:04 +0000 (-0800) Subject: Handle /sys/power/* interfaces not being available. X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=0dbe3f326dec3d8378c27b19892d681a89a848e4;p=android-x86%2Fsystem-hardware-interfaces.git Handle /sys/power/* interfaces not being available. If either /sys/power/wakeup_count or /sys/power/state fail to open, we construct SystemSuspend with blocking fds. This way this process will keep running, handle wake lock requests, collect stats, but won't suspend the device. We want this behavior on devices (hosts) where system suspend should not be handles by Android platform e.g. ARC++, Android virtual devices. Bug: 118637369 Test: Remove system.suspend access to /sys/power/{ wakeup_count state } using SELinux. Device still boots and doesn't suspend. Change-Id: I068a584ada6968520219ee5288f598a53aa48c68 --- diff --git a/suspend/1.0/default/main.cpp b/suspend/1.0/default/main.cpp index 9f4bea1..3070e42 100644 --- a/suspend/1.0/default/main.cpp +++ b/suspend/1.0/default/main.cpp @@ -4,6 +4,7 @@ #include #include +#include #include #include @@ -12,6 +13,7 @@ using android::sp; using android::status_t; +using android::base::Socketpair; using android::base::unique_fd; using android::hardware::configureRpcThreadpool; using android::hardware::joinRpcThreadpool; @@ -26,12 +28,20 @@ int main() { unique_fd wakeupCountFd{TEMP_FAILURE_RETRY(open(kSysPowerWakeupCount, O_CLOEXEC | O_RDWR))}; if (wakeupCountFd < 0) { PLOG(ERROR) << "error opening " << kSysPowerWakeupCount; - return 1; } unique_fd stateFd{TEMP_FAILURE_RETRY(open(kSysPowerState, O_CLOEXEC | O_RDWR))}; if (stateFd < 0) { PLOG(ERROR) << "error opening " << kSysPowerState; - return 1; + } + + // If either /sys/power/wakeup_count or /sys/power/state fail to open, we construct + // SystemSuspend with blocking fds. This way this process will keep running, handle wake lock + // requests, collect stats, but won't suspend the device. We want this behavior on devices + // (hosts) where system suspend should not be handles by Android platform e.g. ARC++, Android + // virtual devices. + if (wakeupCountFd < 0 || stateFd < 0) { + // This will block all reads/writes to these fds from the suspend thread. + Socketpair(SOCK_STREAM, &wakeupCountFd, &stateFd); } configureRpcThreadpool(1, true /* callerWillJoin */);