From 19d80b878c3a91bec31bece096ca6ab012de77e7 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Tue, 21 Jul 2015 16:13:40 -0700 Subject: [PATCH] "adb tcpip" should require a numeric argument. Defaulting to port 0 just breaks stuff. Bug: http://b/22636927 Change-Id: I6239900e0828e71b31171d0184c24824957c99c8 --- adb/commandline.cpp | 4 +++- adb/services.cpp | 2 +- adb/tests/test_adb.py | 12 +++++++++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/adb/commandline.cpp b/adb/commandline.cpp index 4e0db2bf4..7d6de98d4 100644 --- a/adb/commandline.cpp +++ b/adb/commandline.cpp @@ -1200,10 +1200,12 @@ int adb_commandline(int argc, const char **argv) { return 0; } } + else if (!strcmp(argv[0], "tcpip") && argc > 1) { + return adb_connect_command(android::base::StringPrintf("tcpip:%s", argv[1])); + } else if (!strcmp(argv[0], "remount") || !strcmp(argv[0], "reboot") || !strcmp(argv[0], "reboot-bootloader") || - !strcmp(argv[0], "tcpip") || !strcmp(argv[0], "usb") || !strcmp(argv[0], "root") || !strcmp(argv[0], "unroot") || diff --git a/adb/services.cpp b/adb/services.cpp index b9c532aac..2e3ad98a5 100644 --- a/adb/services.cpp +++ b/adb/services.cpp @@ -486,7 +486,7 @@ int service_to_fd(const char *name) } else if(!strncmp(name, "tcpip:", 6)) { int port; if (sscanf(name + 6, "%d", &port) != 1) { - port = 0; + return -1; } ret = create_service_thread(restart_tcp_service, (void *) (uintptr_t) port); } else if(!strncmp(name, "usb:", 4)) { diff --git a/adb/tests/test_adb.py b/adb/tests/test_adb.py index 730f66839..309955447 100755 --- a/adb/tests/test_adb.py +++ b/adb/tests/test_adb.py @@ -186,7 +186,7 @@ class AdbWrapper(object): remote)) def tcpip(self, port): - return call_checked(self.adb_cmd + "tcpip {}".format(port)) + return call_combined(self.adb_cmd + "tcpip {}".format(port)) def usb(self): return call_checked(self.adb_cmd + "usb") @@ -326,6 +326,16 @@ class AdbBasic(unittest.TestCase): else: self.assertEqual(output, "Linux\n") + def test_tcpip(self): + """adb tcpip requires a port. http://b/22636927""" + output, status_code = AdbWrapper().tcpip("") + self.assertEqual(1, status_code) + self.assertIn("help message", output) + + output, status_code = AdbWrapper().tcpip("blah") + self.assertEqual(1, status_code) + self.assertIn("error", output) + class AdbFile(unittest.TestCase): SCRATCH_DIR = "/data/local/tmp"