system/hardware/interfaces
Revisão | 5617a944cac2d498e2100d24a2e89d87bd5878d7 (tree) |
---|---|
Hora | 2018-12-22 08:46:15 |
Autor | Tri Vo <trong@goog...> |
Commiter | android-build-merger |
Handle /sys/power/* interfaces not being available. am: 0dbe3f326d
am: 155dc360a8
Change-Id: I6608aaa31c5e355ebad1b1b0cb35a6264cb85e98
@@ -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 */); |