system/corennnnn
Révision | e88c967073070679cc114579023cd0dbe0ddb5f7 (tree) |
---|---|
l'heure | 2016-07-27 03:49:13 |
Auteur | Andrew Boie <andrew.p.boie@inte...> |
Commiter | Jaap Jan Meijer |
adb: reserve a wakelock when clients are connected over socket
USB OTG connections already have a wakelock reserved, but if a network
socket connection is made, the device can unexpectedly suspend
in the middle of a session. The lock is released when the client
disconnects.
Change-Id: Id5ac01699fab9350955c9814042259542fc6a694
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
@@ -44,7 +44,46 @@ | ||
44 | 44 | ADB_MUTEX_DEFINE( local_transports_lock ); |
45 | 45 | |
46 | 46 | static atransport* local_transports[ ADB_LOCAL_TRANSPORT_MAX ]; |
47 | -#endif /* ADB_HOST */ | |
47 | +#else /* !ADB_HOST */ | |
48 | + | |
49 | +#define WAKE_LOCK_NAME "adb-socket-connection" | |
50 | +#define WAKE_LOCK_ACQUIRE "/sys/power/wake_lock" | |
51 | +#define WAKE_LOCK_RELEASE "/sys/power/wake_unlock" | |
52 | + | |
53 | +static int sysfs_write(const char *node, const char *message) | |
54 | +{ | |
55 | + int fd; | |
56 | + ssize_t to_write; | |
57 | + int ret = 0; | |
58 | + | |
59 | + fd = adb_open(node, O_RDWR); | |
60 | + if (!fd) { | |
61 | + D("open '%s' failed: %s\n", node, strerror(errno)); | |
62 | + return -1; | |
63 | + } | |
64 | + | |
65 | + to_write = strlen(message); | |
66 | + if (adb_write(fd, message, to_write) != to_write) { | |
67 | + D("write '%s' failed: %s\n", node, strerror(errno)); | |
68 | + ret = -1; | |
69 | + } | |
70 | + adb_close(fd); | |
71 | + return ret; | |
72 | +} | |
73 | + | |
74 | +static void get_wakelock(void) | |
75 | +{ | |
76 | + if (sysfs_write(WAKE_LOCK_ACQUIRE, WAKE_LOCK_NAME)) | |
77 | + D("couldn't reserve wakelock for socket connection\n"); | |
78 | +} | |
79 | + | |
80 | +static void release_wakelock(void) | |
81 | +{ | |
82 | + if (sysfs_write(WAKE_LOCK_RELEASE, WAKE_LOCK_NAME)) | |
83 | + D("couldn't release wakelock for socket connection\n"); | |
84 | +} | |
85 | + | |
86 | +#endif /* !ADB_HOST */ | |
48 | 87 | |
49 | 88 | static int remote_read(apacket *p, atransport *t) |
50 | 89 | { |
@@ -157,6 +196,9 @@ static void *server_socket_thread(void * arg) | ||
157 | 196 | fd = adb_socket_accept(serverfd, &addr, &alen); |
158 | 197 | if(fd >= 0) { |
159 | 198 | D("server: new connection on fd %d\n", fd); |
199 | +#if !ADB_HOST | |
200 | + get_wakelock(); | |
201 | +#endif | |
160 | 202 | close_on_exec(fd); |
161 | 203 | disable_tcp_nagle(fd); |
162 | 204 | register_socket_transport(fd, "host", port, 1); |
@@ -334,6 +376,9 @@ static void remote_kick(atransport *t) | ||
334 | 376 | |
335 | 377 | static void remote_close(atransport *t) |
336 | 378 | { |
379 | +#if !ADB_HOST | |
380 | + release_wakelock(); | |
381 | +#endif | |
337 | 382 | adb_close(t->fd); |
338 | 383 | } |
339 | 384 |