summaryrefslogtreecommitdiffstats
path: root/adb/services.cpp
Commit message (Collapse)AuthorAgeFilesLines
* adb: fix `adb reverse` when adbd has multiple transports.Josh Gao2018-04-131-6/+5
| | | | | | | | | | | | | Plumb the transport that we received the adb reverse request on through to reverse_service, instead of trying to get a unique transport on devices that have multiple active transports (e.g. a device with USB (even unplugged) connected via TCP). Bug: http://b/37066218 Bug: http://b/71898863 Test: `echo foo | nc -l 12345 & adb reverse tcp:12345 tcp:12345; adb shell nc localhost 12345` on a device connected via TCP Change-Id: Iae199ae787f2e344126bbcacca8544cfc9844a4c (cherry picked from commit 44899eeb53eb6260c20891723709ab38ed246349)
* Fix a memory leakGeorge Burgess IV2018-02-191-0/+1
| | | | | | | | | | | | If create_service_thread fails, we'll leak `arg`. This fixes a static analyzer complaint: system/core/adb/services.cpp:298:13: warning: Potential leak of memory pointed to by 'arg' Bug: None Test: Reran the static analyzer. No more complaints about this leak. Change-Id: I5aec7fd78f2cc775b650501b02bdf0039d1647ca
* adb: extract atransport's connection interface.Josh Gao2018-01-301-8/+0
| | | | | | | | | | | | | As step one of refactoring atransport to separate out protocol handling from its underlying connection, extract atransport's existing hand-rolled connection vtable out to its own abstract interface. This should not change behavior except in one case: emulators are now treated as TCP devices for the purposes of `adb disconnect`. Test: python test_device.py, with walleye over USB + TCP Test: manually connecting and disconnecting devices/emulators Change-Id: I877b8027e567cc6a7461749432b49f6cb2c2f0d7
* adbd: improve thread names.Josh Gao2017-09-281-18/+21
| | | | | | | | Name each service thread specifically to improve debuggability. Bug: http://b/65648324 Test: adb shell debuggerd -b `adb shell pidof adbd` during a sync Change-Id: I644e25fc2f14a26eafd19f596e4e8f3c2bb79967
* adb: reboot: last boot command defaultMark Salyzyn2017-09-121-0/+1
| | | | | | | | | For reboot [reboot_arg] requests via either reboot or adb reboot, if reboot_arg is empty then report "shell" or "adb" respectively. Test: boot_reason_test.sh shell_reboot adb_reboot Bug: 63736262 Change-Id: Ie613d9e62db6a705885e4e7520aede27af3aa1b9
* adb: add track-devices-l service.Josh Gao2017-08-211-1/+3
| | | | | | | Add a way to get the full `devices -l` output on a continuous basis. Test: manual Change-Id: I2270cc0a0d7e1384ce19631724ddf2462d963ade
* adb: allow selection of a specific transport.Josh Gao2017-08-211-3/+6
| | | | | | | | | | | | Extend device selection to allow selecting a specific transport via monotonically increasing identifier (visible in devices -l). This is useful when using multiple devices (like hikey960...) that have identical bogus serial numbers like 0123456789ABCDEF. Bug: http://b/37043226 Test: adb -t {1, 2, 9999999} {get-serialno, shell, features} Change-Id: I55e5dc5a406a4eeee0012e39b52e8cd232e608a6
* Fix a potential memory leakTing-Yuan Huang2017-08-151-1/+7
| | | | | Test: Built without seeing the warnings Change-Id: I934509c78482af9ef7dc447c807f6450484b4b38
* Merge "adb: fix two device offline problems."Treehugger Robot2017-04-201-1/+1
|\
| * adb: fix two device offline problems.Yabin Cui2017-04-201-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When device goes offline, user usually has to manually replug the usb device. This patch tries to solve two offline situations, all because when adb on host is killed, the adbd on device is not notified. 1. When adb server is killed while pushing a large file to device, the device is still reading the unfinished large message. So the device thinks of the CNXN message as part of the previous unfinished message, so it doesn't reply and the device is in offline state. The solution is to add a write_msg_lock in atransport struct. And it kicks the transport only after sending a whole message. By kicking all transports before exit, we ensure that we don't write part of a message to any device. So next time we start adb server, the device should be waiting for a new message. 2. When adb server is killed while pulling a large file from device, the device is still trying to send the unfinished large message. So adb on host usually reads data with EOVERFLOW error. This is because adb on host is reading less than one packet sent from device. The solution is to use buffered read on host. The max packet size of bulk transactions in USB 3.0 is 1024 bytes. By preparing an at least 1024 bytes buffer when reading, EOVERFLOW no longer occurs. And teach adb host to ignore wrong messages. To be safe, this patch doesn't change any logic on device. Bug: http://b/32952319 Test: run python -m unittest -q test_device.DeviceOfflineTest Test: on linux/mac/windows with bullhead, ryu. Change-Id: Ib149d30028a62a6f03857b8a95ab5a1d6e9b9c4e
* | libcutils: compile with BOARD_VNDK_VERSION currentSteven Moreland2017-04-171-1/+1
|/ | | | | | | | | | | | | | | | | | | - moved __android_log_is_debuggable to a new public header (log_properties.h) - vendor version of sched_policy uses ALOG* instead SLOG* Test: (sanity) liblog-unit-tests Test: (sanity) libcutils_test (noting b/b/32972117, two tests continue to fail) Test: system/core as a whole makes with BOARD_VNDK_VERSION := current now with no problems. Test: boots/works on internal marlin Bug: 33241851 (cherry picked from commit 1f83aa424f537cf3f07e1d27dbbcc524818b5358) Merged-In: I5bc1f348dc0f0c8814bec5b5c3d2c52c825ab640 Change-Id: I5bc1f348dc0f0c8814bec5b5c3d2c52c825ab640
* adb: kill adb_thread_{create, join, detach, exit}.Josh Gao2017-04-121-7/+3
| | | | | | | | | | We have std::thread now, so we can delete this cruft. Test: python test_device.py Test: adb_test Test: wine adb_test.exe Test: /data/nativetest/adbd_test/adbd_test Change-Id: Ie1c1792547b20dec45e2a62ce6515fcb981c3ef8
* Add mDNS device discovery for adb clientCasey Dahlin2017-03-071-39/+0
| | | | | | | | Test: Was able to discover a raspberry pi. Bug: 28074466 (cherry picked from e292cd16760321fccc99c8c261cb92fa4b6462ab) Change-Id: Id9571576457a4a0a078e48a274a4e8eac78bfe2b
* adb: Set max socket sizes to larger values.Jerry Zhang2017-02-131-0/+9
| | | | | | | | This improves performance of push/pull. Test: adb push/pull multi GB files. Bug: 31722483 Change-Id: Ia01574c3db6a740d7a7e64ba1f5bc1fc279fb3f6
* adb: Fix the 'adb reboot sideload' for A/B devices.Tao Bao2017-01-051-11/+7
| | | | | | | | | | | | We used to write the command file (/cache/recovery/command) to trigger the sideload mode. A/B devices don't support that (may not have /cache paritition). This CL switches to using libbootloader_message which writes the command to BCB (bootloader control block) instead. Test: "adb root && adb reboot sideload" reboots sailfish into recovery sideload mode. Change-Id: I158fd7cbcfa9a5d0609f1f684a2d03675217628f
* adb: use __android_log_is_debuggable()Mark Salyzyn2016-10-141-2/+3
| | | | | | | Test: compile and months of adb functionality use Bug: 27566046 Bug: 31456426 Change-Id: I6568eea0eda8dc67dec2ba34cd4c3f56fb0ff0e9
* Switch adb to <android-base/properties.h>.Elliott Hughes2016-09-261-20/+9
| | | | | | Bug: http://b/23102347 Test: manual Change-Id: Iffa66258c01f84f41b9af99ab5e768a0a2669106
* adb: factor out socket specification.Josh Gao2016-08-251-29/+6
| | | | | | | | | | Move the logic for string socket specification out to separate functions to facilitate using arbitrary sockets for the adb command socket. Bug: http://b/30445394 Change-Id: Icd8fdb853272edc029fb3a0f5b18e941dc8ef52c Test: adb_test, adbd_test, test_device.py
* Merge "adb: add reconnect command."Yabin Cui2016-04-161-0/+9
|\
| * adb: add reconnect command.Yabin Cui2016-04-051-0/+9
| | | | | | | | | | | | | | | | | | | | Add reconnect command for debugging. `reconnect` kicks a transport from the host side, `reconnect device` kicks a transport from the device side. They can be used to produce transport errors. Bug: 25935458 Change-Id: I47daa338796b561941e7aba44a51a6dd117d1e98
* | adb: add support for 'wait-for-any'.Josh Gao2016-04-131-1/+3
|/ | | | | | | Allow waiting for a device in any state. Bug: http://b/28168212 Change-Id: I1876ecd70089ca88f2da5de4182e13724ec50501
* adb: use TCP keepalive.David Pursell2016-02-231-0/+5
| | | | | | | | | | | | | | | | Currently adb only realizes a TCP transport has gone away when it tries to send a packet, which caused problems in particular for `adb reboot` since no packets are sent, leading to the client hanging until Ctrl+C. This CL turns on TCP keepalive packets to send 1 packet every second, allowing up to 10 failures before disconnecting. Using built-in TCP functionality turns out to be much cleaner in this case than trying to implement our own keepalive packets at the application layer, and should be more lightweight since it's all done in the TCP stack. Bug: http://b/23093474 Change-Id: Ifb41cbb85b9752a9f394e1eed3c6ac4da47a4e4d
* adb: detect when the client disconnects in wait-for-device.Josh Gao2016-02-191-2/+12
| | | | | | | | | Avoid leaking a thread and its associated resources when a user cancels wait-for-device. Bug: http://b/26966721 Bug: https://code.google.com/p/android/issues/detail?id=199088 Change-Id: Idac80a24e9739ddd24e500fe14826a78f350c018
* adb: make adb_thread_func_t return void, add adb_thread_exit.Josh Gao2016-02-121-3/+1
| | | | | | | | | Windows restricts the return value of threads to 32-bits, even on 64-bit platforms. Since we don't actually return meaningful values from thread, resolve this inconsistency with POSIX by making adb's thread abstraction only take void functions. Change-Id: I5c23b4432314f13bf16d606fd5e6b6b7b6ef98b5
* base: add network address parsing function from adb.David Pursell2016-01-211-1/+2
| | | | | | | | | | | | | | | | | | | | This CL moves the network address parsing function from adb to libbase so that it can be used by fastboot as well as adb. libbase seemed like the right choice because: 1. It already has some parsing functions (parseint) 2. The net address parsing function uses the libbase string functions so we have a libbase dependency anyway. The parsing function has been modified slightly to make the canonical address optional, and debug logging on success has been removed. For adb the only functional difference is that parsing a network address will no longer print the result to the debug log, which seemed unnecessary. Bug: http://b/26236380 Change-Id: Ife6df02937225fc66de87884d3572d79c092c522
* WA: Fix adb wait-for-device commandLeo Sartre2016-01-051-2/+3
| | | | | | | | | | | Without -s argument, adb wait-for-device will make a call to acquire_one_transport() with sinfo->serial.c_str() == "". Waiting for acquire_one_transport() to be reworked to use std::string rather than const char * for serial, work around this by passing NULL when sinfo->serial is not initialized in host_service_to_socket(). Change-Id: Ifef53e0e82850364f5029ee36560376f2a4a5104 Signed-off-by: Leo Sartre <leox.sartre@intel.com>
* adb host: add device state in "adb wait-for-*"Leo Sartre2015-12-161-28/+29
| | | | | | | | | | | | | | | The current implementation of the host commands "adb wait-for-*" allows to specify only the transport layer (local, usb or any). This patch allows the specification of the expected device state (bootloader, recovery, device or sideload), this is usefull for scripting purposes. Use case: $ adb reboot sideload-auto-reboot $ adb wait-for-usb-sideload && adb sideload package.zip Change-Id: I276a6be4d82f8b7901f74e1e5395b86d16548e8f Signed-off-by: Leo Sartre <leox.sartre@intel.com>
* Track rename of base/ to android-base/.Elliott Hughes2015-12-041-3/+3
| | | | Change-Id: Idf9444fece4aa89c93e15640de59a91f6e758ccf
* Pass $TERM to the device.Elliott Hughes2015-11-161-9/+11
| | | | | | | | | | | | | | Unfortunately, this isn't backwards-compatible with the current shell protocol because we made unknown shell: arguments errors. We could try to commit the change to make them just warnings first, but how would we know when everyone was running adbd with that change? Bumping the protocol version doesn't help because that only affects the code running on the host. And although we could add another feature to the reported features, since shell_v2 is still in development, that doesn't seem worthwhile. Bug: http://b/25601436 Change-Id: I12b81aa656cd25b91d14ef691dcbd2b7dab49535
* adb: run reverse_service() in main thread.Yabin Cui2015-11-021-17/+12
| | | | | | | | | | | reverse_service() calls handle_forward_request(), which calls functions in fdevent.cpp. fdevent functions is only supposed to be called in the main thread. Add check in fdevent.cpp to make sure all operations come from main thread. Bug: 25355808 Change-Id: Iceb9273f3056acc0713eaafe086ac950ca80ff4f
* Fix adb -d/-e error reporting.Elliott Hughes2015-10-071-10/+18
| | | | | | | | | | | | | | | | If -d/-e fail, get-serialno and friends will now report an error and return a failure status code on exit. Also fix the behavior of -d/-e with $ANDROID_SERIAL --- -d/-e should override $ANDROID_SERIAL, not the other way round. I'm deleting my own comment here about always returning "unknown" for scripts. I can't find any evidence that there are scripts relying on that, so I think my comment meant "I fear that there are scripts doing so". Bug: http://b/24403699 Change-Id: Ie13a751f1137abcfe0cc6c46a0630ba5e02db676
* adb: put legacy shell: service back in.David Pursell2015-09-301-17/+22
| | | | | | | | | | | | | | | | | | | | ddmlib does not use the ADB client, but instead connects directly to the adb server. This breaks some of the assumptions I previously made when enabling the shell protocol. To fix this, the adb server now defaults to no protocol for the standalone command, and the shell protocol must be explicitly requested by the client. For example: shell:echo foo -- no shell protocol shell,v2:echo foo -- shell protocol As long as I was touching the shell service arguments I also changed them to no longer duplicate the command-line arguments. This allows more flexibility to change the adb client CLI if necessary and makes the code more readable. Bug: http://b/24148636 Change-Id: I28d5ae578cf18cbe79347dc89cea1750ff4571a8
* Adb: use VLOG() to replace D() for verbose logging.Yabin Cui2015-09-231-1/+1
| | | | | | | As there are too many D(), we can keep both VLOG() and D() now, and get rid of D() gradually. Change-Id: I2f1cb70bcab3e82c99fed939341d03f6b2216076
* adb: add -Tt options to `adb shell`.David Pursell2015-09-221-9/+35
| | | | | | | | | | | | | | | Adds -T (no PTY) and -t (force PTY) options to `adb shell` to mimic ssh options. Small cleanup to send an entire FeatureSet to the adb client at once to avoid multiple round-trips when querying multiple features. Known issue: humans using `adb shell -T` to start a non-PTY interactive session may experience problems since neither side will have PTY features like echoing or newline translation. This is probably OK for now as the -Tt options are primarily useful for scripting. Bug: http://b/23825231 Change-Id: I4d0df300db0abd1f7410bab59dd4d5b991babda7
* adb: implement shell protocol.David Pursell2015-09-111-11/+12
| | | | | | | | | | | | | | | | | Adds functionality for handling stdin/stdout/stderr streams and exit codes using the shell protocol. This CL just contains implementation for adbd which will not yet be enabled. Once we have the ability to query transport features from the adb client, another CL will add the implementation for the client side and update the feature list to turn this on. Note: this CL must be submitted together with a minadbd CL to update the service_to_fd() function signature. Bug: http://b/23030641 Change-Id: Ibed55e9c1946d8a35190696163ff63e8fb880238
* adb: move shell service to a separate file.David Pursell2015-09-041-222/+8
| | | | | | | | | | | Upcoming changes to the shell will require significant additions to the subprocess code, and it will be cleaner if it's in a separate file. The only functional change here is a new debug tag specifically for the shell service. Everything else has been copied exactly as-is in order to make it easier to determine what's changing in upcoming CLs. Change-Id: I13bd4294059051ee10e0d0c6a06affd8eca62967
* adb: clean up debug tracing a little.Yabin Cui2015-09-021-19/+19
| | | | | | | | | Always use LOG() for debug tracing. Remove useless D_lock. I believe it is useless to lock just before and after fprintf. I verified the log output both on host and on device. The output looks fine to me. Change-Id: I96ccfe408ff56864361551afe9ad464d197ae104
* adb: set thread names (linux & mac)Siva Velusamy2015-08-311-0/+1
| | | | | Bug: 23423333 Change-Id: I0069f32ddbae2a10fb130064f721facf45b2cc09
* adb sync cleanup.Elliott Hughes2015-08-241-10/+6
| | | | | | | | | | | | | | | | | We can double the speed of "adb sync" (on N9) if we increase SYNC_DATA_MAX from 64KiB to 256KiB. This change doesn't do that, because I still haven't managed to plumb through the information about whether we're a new adb/adbd to file_sync_client.cpp and file_sync_service.cpp. But this is already a big change with a lot of cleanup, so let's do the cleanup and worry about the intended change another day... This change does improve performance somewhat by halving the number of lstat(2) calls made on the client side, and ensuring that most packets are sent with a single write. This has the pleasing result of making the null sync on an AOSP N9 go from just over 300ms to around 100ms, which means it now seems instantaneous (https://en.wikipedia.org/wiki/Mental_chronometry). Change-Id: If9f6d4c1f93ec752b95f71211bbbb1c513045166
* adb: Fix PTY logic for non-interactive shells.David Pursell2015-08-121-10/+34
| | | | | | | | | | | | | Change `adb shell` so that interactive sessions use a PTY but non-interactive do not. This matches `ssh` functionality better and also enables future work to split stdout/stderr for non-interactive sessions. A test to verify this behavior is added to test_device.py with supporting modifications in device.py. Bug: http://b/21215503 Change-Id: Ib4ba40df85f82ddef4e0dd557952271c859d1c7b
* Remove confusing variable HOST.Yabin Cui2015-08-111-2/+2
| | | | | | | | | | | First, HOST is always 0 in adbd, which matches ADB_HOST=0. Second, HOST is always 1 when adb_main is called, which matches ADB_HOST=1. For adb client that doesn't call adb_main, it never touches local_init(), init_transport_registration() and fdevent_loop(). So the changes in adb.cpp, services.cpp and transport_local.cpp do nothing with it. As a conclusion, I think we can remove HOST and use ADB_HOST instead. Change-Id: Ide0e0eca7468b6c3c130f6b50974406280678b2e
* adb: win32: initial IPv6 support and improved Winsock error reportingSpencer Low2015-07-301-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Call getaddrinfo() for connecting to IPv6 destinations. Winsock APIs do not set errno. WSAGetLastError() returns Winsock errors that are more numerous than BSD sockets, so it really doesn't make sense to map those to BSD socket errors. Plus, even if we did that, the Windows C Runtime (that mingw binaries use) has a strerror() that does not recognize BSD socket error codes. The solution is to wrap the various libcutils socket_* APIs with sysdeps.h network_* APIs. For POSIX, the network_* APIs just call strerror(). For Windows, they call SystemErrorCodeToString() (adapted from Chromium). Also in this change: - Various other code was modified to return errors in a std::string* argument, to be able to surface the error string to the end-user. - Improved error checking and use of D() to log Winsock errors for improved debuggability. - For sysdeps_win32.cpp, added unique_fh class that works like std::unique_ptr, for calling _fh_close(). - Fix win32 adb_socketpair() setting of errno in error case. - Improve _socket_set_errno() D() logging to reduce confusion. Map a few extra error codes. - Move adb_shutdown() lower in sysdeps_win32.cpp so it can call _socket_set_errno(). - Move network_connect() from adb_utils.cpp to sysdeps.h. - Merge socket_loopback_server() and socket_inaddr_any_server() into _network_server() since most of the code was identical. Change-Id: I945f36870f320578b3a11ba093852ba6f7b93400 Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
* Use _WIN32 rather than HAVE_WINSOCK.Elliott Hughes2015-07-291-1/+1
| | | | Change-Id: I9855b6fe72e2f2f3a8360c0993a67cb988024ee4
* Report getaddrinfo failures correctly.Elliott Hughes2015-07-231-6/+10
| | | | | | | Also move us off the "convenience" function because you can't get useful error reporting from it. Change-Id: I5fcc6a6d762f5f60906980a7835f01a35045be65
* "adb tcpip" should require a numeric argument.Elliott Hughes2015-07-211-1/+1
| | | | | | | Defaulting to port 0 just breaks stuff. Bug: http://b/22636927 Change-Id: I6239900e0828e71b31171d0184c24824957c99c8
* Merge "Recognize IPv6 addresses for "adb connect"."Elliott Hughes2015-07-211-20/+13
|\
| * Recognize IPv6 addresses for "adb connect".Elliott Hughes2015-07-211-20/+13
| | | | | | | | | | Bug: http://b/22559299 Change-Id: I32891d706b5010c38db84a056e76dd279b780f75
* | adb: logging: newlines, thread ids, error code overwritingSpencer Low2015-07-211-2/+2
|/ | | | | | | | | | | | | | | | | | Add missing \n to uses of legacy D() macro. This should make the legacy logging easier to read (and harder to miss important stuff). On POSIX, use gettid() from libcutils instead of pthread_self() so that the output shows a more reasonable number instead of a pointer value. This should be ok since libbase's logging already uses gettid(). Win32: Don't let the Win32 last error get overwritten by API calls after the original error'ing API. When encountering an unknown error, log the specific error code. Change-Id: Ib8f72754efa7ba895d2f1cd914251fec2a1d894c Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
* Improve the "device '(null)' not found" error.Elliott Hughes2015-06-241-1/+1
| | | | | | | | | Now we'll say "no devices found" if you haven't set ANDROID_SERIAL and there's no device connected to default to. Also clean up the relevant code a little. Change-Id: Id254929629ce0888628d5ba8e67cd996ffbf9c8a
* adb: fix adb_close() vs. unix_close() usageSpencer Low2015-05-221-8/+8
| | | | | | | | | | | | | | | | | Document the differences between adb_*() and unix_*() in the function prototypes in sysdeps.h. See the file for the details (CR/LF translation, well-known file descriptors, etc.). Fix adb_read(), adb_write(), and adb_close() calls that should really be unix_read(), unix_write(), and unix_close(). Note that this should have no impact on unix because on unix, unix_read/unix_write/unix_close are macros that map to adb_read/adb_write/adb_close. Improve sysdeps_win32.cpp file descriptor diagnostic logging to output the name of the function that was passed a bad file descriptor. Change-Id: I0a1d9c28772656c80bcc303ef8b61fccf4cd637c Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>