• R/O
  • HTTP
  • SSH
  • HTTPS

コミット

タグ
未設定

よく使われているワード(クリックで追加)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

system/corennnnn


コミットメタ情報

リビジョン5f64296995844981fdfebebdd4b5d84044df3c28 (tree)
日時2009-08-26 08:32:35
作者Mike Lockwood <lockwood@andr...>
コミッターAndroid Git Automerger

ログメッセージ

am 968c8f07: Merge change 22503 into eclair

Merge commit '968c8f07031c881dbb2e27b308d88f76e2917121' into eclair-plus-aosp

* commit '968c8f07031c881dbb2e27b308d88f76e2917121':

adb: Improved support for running adb over TCP/IP

変更サマリ

差分

--- a/adb/adb.c
+++ b/adb/adb.c
@@ -832,6 +832,7 @@ int adb_main(int is_daemon)
832832 {
833833 #if !ADB_HOST
834834 int secure = 0;
835+ int port;
835836 char value[PROPERTY_VALUE_MAX];
836837 #endif
837838
@@ -918,14 +919,17 @@ int adb_main(int is_daemon)
918919 }
919920
920921 /* for the device, start the usb transport if the
921- ** android usb device exists, otherwise start the
922- ** network transport.
922+ ** android usb device exists and "service.adb.tcp"
923+ ** is not set, otherwise start the network transport.
923924 */
924- if(access("/dev/android_adb", F_OK) == 0 ||
925- access("/dev/android", F_OK) == 0) {
925+ property_get("service.adb.tcp.port", value, "0");
926+ if (sscanf(value, "%d", &port) == 0) {
927+ port = 0;
928+ }
929+ if (port == 0 && access("/dev/android_adb", F_OK) == 0) {
926930 usb_init();
927931 } else {
928- local_init();
932+ local_init(port);
929933 }
930934 init_jdwp();
931935 #endif
@@ -1006,6 +1010,43 @@ int handle_host_request(char *service, transport_type ttype, char* serial, int r
10061010 return 0;
10071011 }
10081012
1013+ // add a new TCP transport
1014+ if (!strncmp(service, "connect:", 8)) {
1015+ char buffer[4096];
1016+ int port, fd;
1017+ char* host = service + 8;
1018+ char* portstr = strchr(host, ':');
1019+
1020+ if (!portstr) {
1021+ snprintf(buffer, sizeof(buffer), "unable to parse %s as <host>:<port>\n", host);
1022+ goto done;
1023+ }
1024+ // zero terminate host by overwriting the ':'
1025+ *portstr++ = 0;
1026+ if (sscanf(portstr, "%d", &port) == 0) {
1027+ snprintf(buffer, sizeof(buffer), "bad port number %s\n", portstr);
1028+ goto done;
1029+ }
1030+
1031+ fd = socket_network_client(host, port, SOCK_STREAM);
1032+ if (fd < 0) {
1033+ snprintf(buffer, sizeof(buffer), "unable to connect to %s:%d\n", host, port);
1034+ goto done;
1035+ }
1036+
1037+ D("client: connected on remote on fd %d\n", fd);
1038+ close_on_exec(fd);
1039+ disable_tcp_nagle(fd);
1040+ snprintf(buf, sizeof buf, "%s:%d", host, port);
1041+ register_socket_transport(fd, buf, port, 0);
1042+ snprintf(buffer, sizeof(buffer), "connected to %s:%d\n", host, port);
1043+
1044+done:
1045+ snprintf(buf, sizeof(buf), "OKAY%04x%s",(unsigned)strlen(buffer),buffer);
1046+ writex(reply_fd, buf, strlen(buf));
1047+ return 0;
1048+ }
1049+
10091050 // returns our value for ADB_SERVER_VERSION
10101051 if (!strcmp(service, "version")) {
10111052 char version[12];
--- a/adb/adb.h
+++ b/adb/adb.h
@@ -33,7 +33,7 @@
3333 #define ADB_VERSION_MAJOR 1 // Used for help/version information
3434 #define ADB_VERSION_MINOR 0 // Used for help/version information
3535
36-#define ADB_SERVER_VERSION 23 // Increment this when we want to force users to start a new adb server
36+#define ADB_SERVER_VERSION 24 // Increment this when we want to force users to start a new adb server
3737
3838 typedef struct amessage amessage;
3939 typedef struct apacket apacket;
@@ -262,14 +262,14 @@ void run_transport_disconnects( atransport* t );
262262 void kick_transport( atransport* t );
263263
264264 /* initialize a transport object's func pointers and state */
265-int init_socket_transport(atransport *t, int s, int port);
265+int init_socket_transport(atransport *t, int s, int port, int local);
266266 void init_usb_transport(atransport *t, usb_handle *usb, int state);
267267
268268 /* for MacOS X cleanup */
269269 void close_usb_devices();
270270
271271 /* cause new transports to be init'd and added to the list */
272-void register_socket_transport(int s, const char *serial, int port);
272+void register_socket_transport(int s, const char *serial, int port, int local);
273273 void register_usb_transport(usb_handle *h, const char *serial, unsigned writeable);
274274
275275 /* this should only be used for transports with connection_state == CS_NOPERM */
--- a/adb/commandline.c
+++ b/adb/commandline.c
@@ -105,6 +105,7 @@ void help()
105105 " environment variable is used, which must\n"
106106 " be an absolute path.\n"
107107 " devices - list all connected devices\n"
108+ " connect <host>:<port> - connect to a device via TCP/IP"
108109 "\n"
109110 "device commands:\n"
110111 " adb push <local> <remote> - copy file/dir to device\n"
@@ -149,7 +150,9 @@ void help()
149150 " adb status-window - continuously print device status for a specified device\n"
150151 " adb remount - remounts the /system partition on the device read-write\n"
151152 " adb reboot [bootloader|recovery] - reboots the device, optionally into the bootloader or recovery program\n"
152- " adb root - restarts adb with root permissions\n"
153+ " adb root - restarts the adbd daemon with root permissions\n"
154+ " adb usb - restarts the adbd daemon listening on USB"
155+ " adb tcpip <port> - restarts the adbd daemon listening on TCP on the specified port"
153156 "\n"
154157 "networking:\n"
155158 " adb ppp <tty> [parameters] - Run PPP over USB.\n"
@@ -850,6 +853,22 @@ top:
850853 }
851854 }
852855
856+ if(!strcmp(argv[0], "connect")) {
857+ char *tmp;
858+ if (argc != 2) {
859+ fprintf(stderr, "Usage: adb connect <host>:<port>\n");
860+ return 1;
861+ }
862+ snprintf(buf, sizeof buf, "host:%s:%s", argv[0], argv[1]);
863+ tmp = adb_query(buf);
864+ if(tmp) {
865+ printf("%s\n", tmp);
866+ return 0;
867+ } else {
868+ return 1;
869+ }
870+ }
871+
853872 if (!strcmp(argv[0], "emu")) {
854873 return adb_send_emulator_command(argc, argv);
855874 }
@@ -908,35 +927,15 @@ top:
908927 return 0;
909928 }
910929
911- if(!strcmp(argv[0], "remount")) {
912- int fd = adb_connect("remount:");
913- if(fd >= 0) {
914- read_and_dump(fd);
915- adb_close(fd);
916- return 0;
917- }
918- fprintf(stderr,"error: %s\n", adb_error());
919- return 1;
920- }
921-
922- if(!strcmp(argv[0], "reboot")) {
923- int fd;
930+ if(!strcmp(argv[0], "remount") || !strcmp(argv[0], "reboot")
931+ || !strcmp(argv[0], "tcpip") || !strcmp(argv[0], "usb")
932+ || !strcmp(argv[0], "reboot")) {
933+ char command[100];
924934 if (argc > 1)
925- snprintf(buf, sizeof(buf), "reboot:%s", argv[1]);
935+ snprintf(command, sizeof(command), "%s:%s", argv[0], argv[1]);
926936 else
927- snprintf(buf, sizeof(buf), "reboot:");
928- fd = adb_connect(buf);
929- if(fd >= 0) {
930- read_and_dump(fd);
931- adb_close(fd);
932- return 0;
933- }
934- fprintf(stderr,"error: %s\n", adb_error());
935- return 1;
936- }
937-
938- if(!strcmp(argv[0], "root")) {
939- int fd = adb_connect("root:");
937+ snprintf(command, sizeof(command), "%s:", argv[0]);
938+ int fd = adb_connect(command);
940939 if(fd >= 0) {
941940 read_and_dump(fd);
942941 adb_close(fd);
--- a/adb/services.c
+++ b/adb/services.c
@@ -120,6 +120,7 @@ void restart_root_service(int fd, void *cookie)
120120 if (strcmp(value, "1") != 0) {
121121 snprintf(buf, sizeof(buf), "adbd cannot run as root in production builds\n");
122122 writex(fd, buf, strlen(buf));
123+ adb_close(fd);
123124 return;
124125 }
125126
@@ -134,13 +135,52 @@ void restart_root_service(int fd, void *cookie)
134135 }
135136 }
136137
137-void reboot_service(int fd, char *arg)
138+void restart_tcp_service(int fd, void *cookie)
139+{
140+ char buf[100];
141+ char value[PROPERTY_VALUE_MAX];
142+ int port = (int)cookie;
143+
144+ if (port <= 0) {
145+ snprintf(buf, sizeof(buf), "invalid port\n");
146+ writex(fd, buf, strlen(buf));
147+ adb_close(fd);
148+ return;
149+ }
150+
151+ snprintf(value, sizeof(value), "%d", port);
152+ property_set("service.adb.tcp.port", value);
153+ snprintf(buf, sizeof(buf), "restarting in TCP mode port: %d\n", port);
154+ writex(fd, buf, strlen(buf));
155+ adb_close(fd);
156+
157+ // quit, and init will restart us in TCP mode
158+ sleep(1);
159+ exit(1);
160+}
161+
162+void restart_usb_service(int fd, void *cookie)
163+{
164+ char buf[100];
165+
166+ property_set("service.adb.tcp.port", "0");
167+ snprintf(buf, sizeof(buf), "restarting in USB mode\n");
168+ writex(fd, buf, strlen(buf));
169+ adb_close(fd);
170+
171+ // quit, and init will restart us in USB mode
172+ sleep(1);
173+ exit(1);
174+}
175+
176+void reboot_service(int fd, void *arg)
138177 {
139178 char buf[100];
140179 int ret;
141180
142181 sync();
143- ret = __reboot(LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, LINUX_REBOOT_CMD_RESTART2, arg);
182+ ret = __reboot(LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2,
183+ LINUX_REBOOT_CMD_RESTART2, (char *)arg);
144184 if (ret < 0) {
145185 snprintf(buf, sizeof(buf), "reboot failed: %s\n", strerror(errno));
146186 writex(fd, buf, strlen(buf));
@@ -415,12 +455,20 @@ int service_to_fd(const char *name)
415455 } else if(!strncmp(name, "remount:", 8)) {
416456 ret = create_service_thread(remount_service, NULL);
417457 } else if(!strncmp(name, "reboot:", 7)) {
418- char* arg = name + 7;
458+ const char* arg = name + 7;
419459 if (*name == 0)
420460 arg = NULL;
421- ret = create_service_thread(reboot_service, arg);
461+ ret = create_service_thread(reboot_service, (void *)arg);
422462 } else if(!strncmp(name, "root:", 5)) {
423463 ret = create_service_thread(restart_root_service, NULL);
464+ } else if(!strncmp(name, "tcpip:", 6)) {
465+ int port;
466+ if (sscanf(name + 6, "%d", &port) == 0) {
467+ port = 0;
468+ }
469+ ret = create_service_thread(restart_tcp_service, (void *)port);
470+ } else if(!strncmp(name, "usb:", 4)) {
471+ ret = create_service_thread(restart_usb_service, NULL);
424472 #endif
425473 #if 0
426474 } else if(!strncmp(name, "echo:", 5)){
--- a/adb/transport.c
+++ b/adb/transport.c
@@ -849,11 +849,11 @@ void close_usb_devices()
849849 }
850850 #endif // ADB_HOST
851851
852-void register_socket_transport(int s, const char *serial, int port)
852+void register_socket_transport(int s, const char *serial, int port, int local)
853853 {
854854 atransport *t = calloc(1, sizeof(atransport));
855855 D("transport: %p init'ing for socket %d, on port %d\n", t, s, port);
856- if ( init_socket_transport(t, s, port) < 0 ) {
856+ if ( init_socket_transport(t, s, port, local) < 0 ) {
857857 adb_close(s);
858858 free(t);
859859 return;
--- a/adb/transport_local.c
+++ b/adb/transport_local.c
@@ -122,7 +122,7 @@ int local_connect(int port)
122122 close_on_exec(fd);
123123 disable_tcp_nagle(fd);
124124 snprintf(buf, sizeof buf, "%s%d", LOCAL_CLIENT_PREFIX, port - 1);
125- register_socket_transport(fd, buf, port);
125+ register_socket_transport(fd, buf, port, 1);
126126 return 0;
127127 }
128128 return -1;
@@ -147,17 +147,18 @@ static void *client_socket_thread(void *x)
147147 return 0;
148148 }
149149
150-static void *server_socket_thread(void *x)
150+static void *server_socket_thread(void * arg)
151151 {
152152 int serverfd, fd;
153153 struct sockaddr addr;
154154 socklen_t alen;
155+ int port = (int)arg;
155156
156157 D("transport: server_socket_thread() starting\n");
157158 serverfd = -1;
158159 for(;;) {
159160 if(serverfd == -1) {
160- serverfd = socket_inaddr_any_server(ADB_LOCAL_TRANSPORT_PORT, SOCK_STREAM);
161+ serverfd = socket_inaddr_any_server(port, SOCK_STREAM);
161162 if(serverfd < 0) {
162163 D("server: cannot bind socket yet\n");
163164 adb_sleep_ms(1000);
@@ -167,20 +168,20 @@ static void *server_socket_thread(void *x)
167168 }
168169
169170 alen = sizeof(addr);
170- D("server: trying to get new connection from %d\n", ADB_LOCAL_TRANSPORT_PORT);
171+ D("server: trying to get new connection from %d\n", port);
171172 fd = adb_socket_accept(serverfd, &addr, &alen);
172173 if(fd >= 0) {
173174 D("server: new connection on fd %d\n", fd);
174175 close_on_exec(fd);
175176 disable_tcp_nagle(fd);
176- register_socket_transport(fd,"host",ADB_LOCAL_TRANSPORT_PORT);
177+ register_socket_transport(fd, "host", port, 1);
177178 }
178179 }
179180 D("transport: server_socket_thread() exiting\n");
180181 return 0;
181182 }
182183
183-void local_init(void)
184+void local_init(int port)
184185 {
185186 adb_thread_t thr;
186187 void* (*func)(void *);
@@ -193,7 +194,7 @@ void local_init(void)
193194
194195 D("transport: local %s init\n", HOST ? "client" : "server");
195196
196- if(adb_thread_create(&thr, func, 0)) {
197+ if(adb_thread_create(&thr, func, (void *)port)) {
197198 fatal_errno("cannot create local socket %s thread",
198199 HOST ? "client" : "server");
199200 }
@@ -225,7 +226,7 @@ static void remote_close(atransport *t)
225226 adb_close(t->fd);
226227 }
227228
228-int init_socket_transport(atransport *t, int s, int port)
229+int init_socket_transport(atransport *t, int s, int port, int local)
229230 {
230231 int fail = 0;
231232
@@ -239,7 +240,7 @@ int init_socket_transport(atransport *t, int s, int port)
239240 t->type = kTransportLocal;
240241
241242 #if ADB_HOST
242- if (HOST) {
243+ if (HOST && local) {
243244 adb_mutex_lock( &local_transports_lock );
244245 {
245246 int index = (port - ADB_LOCAL_TRANSPORT_PORT)/2;