system/hardware/interfaces
Revisão | 0dbe3f326dec3d8378c27b19892d681a89a848e4 (tree) |
---|---|
Hora | 2018-12-21 06:11:35 |
Autor | Tri Vo <trong@goog...> |
Commiter | Tri Vo |
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
@@ -4,6 +4,7 @@ | ||
4 | 4 | #include <cutils/native_handle.h> |
5 | 5 | #include <hidl/HidlTransportSupport.h> |
6 | 6 | |
7 | +#include <sys/socket.h> | |
7 | 8 | #include <sys/stat.h> |
8 | 9 | #include <sys/types.h> |
9 | 10 |
@@ -12,6 +13,7 @@ | ||
12 | 13 | |
13 | 14 | using android::sp; |
14 | 15 | using android::status_t; |
16 | +using android::base::Socketpair; | |
15 | 17 | using android::base::unique_fd; |
16 | 18 | using android::hardware::configureRpcThreadpool; |
17 | 19 | using android::hardware::joinRpcThreadpool; |
@@ -26,12 +28,20 @@ int main() { | ||
26 | 28 | unique_fd wakeupCountFd{TEMP_FAILURE_RETRY(open(kSysPowerWakeupCount, O_CLOEXEC | O_RDWR))}; |
27 | 29 | if (wakeupCountFd < 0) { |
28 | 30 | PLOG(ERROR) << "error opening " << kSysPowerWakeupCount; |
29 | - return 1; | |
30 | 31 | } |
31 | 32 | unique_fd stateFd{TEMP_FAILURE_RETRY(open(kSysPowerState, O_CLOEXEC | O_RDWR))}; |
32 | 33 | if (stateFd < 0) { |
33 | 34 | PLOG(ERROR) << "error opening " << kSysPowerState; |
34 | - return 1; | |
35 | + } | |
36 | + | |
37 | + // If either /sys/power/wakeup_count or /sys/power/state fail to open, we construct | |
38 | + // SystemSuspend with blocking fds. This way this process will keep running, handle wake lock | |
39 | + // requests, collect stats, but won't suspend the device. We want this behavior on devices | |
40 | + // (hosts) where system suspend should not be handles by Android platform e.g. ARC++, Android | |
41 | + // virtual devices. | |
42 | + if (wakeupCountFd < 0 || stateFd < 0) { | |
43 | + // This will block all reads/writes to these fds from the suspend thread. | |
44 | + Socketpair(SOCK_STREAM, &wakeupCountFd, &stateFd); | |
35 | 45 | } |
36 | 46 | |
37 | 47 | configureRpcThreadpool(1, true /* callerWillJoin */); |