Patrick Williams | ddad1a1 | 2017-02-23 20:36:32 -0600 | [diff] [blame^] | 1 | Subject: adb: Use local sockets where appropriate |
| 2 | Author: Hilko Bengen <bengen@debian.org> |
| 3 | |
| 4 | Upstream-Status: Inappropriate |
| 5 | --- |
| 6 | system/core/adb/adb.c | 6 +++++- |
| 7 | system/core/adb/adb_client.c | 5 +++-- |
| 8 | system/core/adb/transport_local.c | 3 ++- |
| 9 | 3 files changed, 10 insertions(+), 4 deletions(-) |
| 10 | |
| 11 | --- a/system/core/adb/adb.c |
| 12 | +++ b/system/core/adb/adb.c |
| 13 | @@ -1230,7 +1230,11 @@ int launch_server(int server_port) |
| 14 | */ |
| 15 | void build_local_name(char* target_str, size_t target_size, int server_port) |
| 16 | { |
| 17 | - snprintf(target_str, target_size, "tcp:%d", server_port); |
| 18 | + if (gListenAll > 0) { |
| 19 | + snprintf(target_str, target_size, "tcp:%d", server_port); |
| 20 | + } else { |
| 21 | + snprintf(target_str, target_size, "local:%d", server_port); |
| 22 | + } |
| 23 | } |
| 24 | |
| 25 | #if !ADB_HOST |
| 26 | --- a/system/core/adb/adb_client.c |
| 27 | +++ b/system/core/adb/adb_client.c |
| 28 | @@ -185,12 +185,12 @@ int _adb_connect(const char *service) |
| 29 | strcpy(__adb_error, "service name too long"); |
| 30 | return -1; |
| 31 | } |
| 32 | - snprintf(tmp, sizeof tmp, "%04x", len); |
| 33 | + snprintf(tmp, sizeof tmp, "%d", __adb_server_port); |
| 34 | |
| 35 | if (__adb_server_name) |
| 36 | fd = socket_network_client(__adb_server_name, __adb_server_port, SOCK_STREAM); |
| 37 | else |
| 38 | - fd = socket_loopback_client(__adb_server_port, SOCK_STREAM); |
| 39 | + fd = socket_local_client(tmp, ANDROID_SOCKET_NAMESPACE_ABSTRACT, SOCK_STREAM); |
| 40 | |
| 41 | if(fd < 0) { |
| 42 | strcpy(__adb_error, "cannot connect to daemon"); |
| 43 | @@ -201,6 +201,7 @@ int _adb_connect(const char *service) |
| 44 | return -1; |
| 45 | } |
| 46 | |
| 47 | + snprintf(tmp, sizeof tmp, "%04x", len); |
| 48 | if(writex(fd, tmp, 4) || writex(fd, service, len)) { |
| 49 | strcpy(__adb_error, "write failure during connection"); |
| 50 | adb_close(fd); |
| 51 | --- a/system/core/adb/transport_local.c |
| 52 | +++ b/system/core/adb/transport_local.c |
| 53 | @@ -121,7 +121,8 @@ int local_connect_arbitrary_ports(int co |
| 54 | } |
| 55 | #endif |
| 56 | if (fd < 0) { |
| 57 | - fd = socket_loopback_client(adb_port, SOCK_STREAM); |
| 58 | + snprintf(buf, sizeof buf, "%d", adb_port); |
| 59 | + fd = socket_local_client(buf, ANDROID_SOCKET_NAMESPACE_ABSTRACT, SOCK_STREAM); |
| 60 | } |
| 61 | |
| 62 | if (fd >= 0) { |