History log of /system/core/adb/transport.cpp
Revision Date Author Comments (<<< Hide modified files) (Show modified files >>>)
5d1756ceb58246a721e10464f788e81cdcdc455a 23-Feb-2017 Josh Gao <jmgao@google.com> adb: add `adb host-features`, report libusb status.

Add a 'host-features' command to get the features of the currently
running host adb server. Abuse it to report libusb status.

Bug: http://b/34983123
Test: adb host-features; adb kill-server; ADB_LIBUSB=1 adb start-server; adb host-features
Change-Id: I0e8d503a2dbdff9002ebb6ce8a298498a9421422
/system/core/adb/transport.cpp
cfe72e290b6e3fd70f443e666ef6929527831fc0 29-Nov-2016 Josh Gao <jmgao@google.com> adb: add tracing to transport.cpp.

Bug: http://b/31289465
Test: systrace
Change-Id: I41968f447b61ef1eea2b933a5fd8623605c4dea6
/system/core/adb/transport.cpp
1290fbf5eb21079d08f6aaed57c5aabd8d25b626 22-Nov-2016 Josh Gao <jmgao@google.com> adb: clang-format transport.cpp

Bug: http://b/31289465
Test: none
Change-Id: If99a9f1d4d6fa1d34b0ac3bbfc7f2e6bfc188ff2
/system/core/adb/transport.cpp
5a1e3fdaf82aee348b1b22992a8c1d15db38413b 06-Dec-2016 Josh Gao <jmgao@google.com> Revert "Revert "adb: extend sync protocol's stat support.""

This reverts commit afa4b5d6eb45bbee8671a1bb93ea70506fb326e3.

Add functions to translate errno to and from the linux asm-generic
values, since mips has different values.

Bug: http://b/33058958
Test: python test_device.py with both old and new adbd
Change-Id: I1a122235f3e793ed10b3bf3ad293388015134150
/system/core/adb/transport.cpp
afa4b5d6eb45bbee8671a1bb93ea70506fb326e3 05-Dec-2016 Josh Gao <jmgao@google.com> Revert "adb: extend sync protocol's stat support."

This reverts commit d6d5c38469203a63c686517d765a7e6d2bc24656.
/system/core/adb/transport.cpp
d6d5c38469203a63c686517d765a7e6d2bc24656 22-Nov-2016 Josh Gao <jmgao@google.com> adb: extend sync protocol's stat support.

Extend the file sync protocol to support calling regular stat (instead
of lstat), return error codes, and provide the entire stat struct.

Bug: http://b/33058958
Test: python test_device.py with both old and new adbd
Change-Id: I841123debc380f86194a19e91c97d85160112144
/system/core/adb/transport.cpp
22d2b3e1c2e1152ca9cf86c3eb42cd42e7448a31 27-Oct-2016 Josh Gao <jmgao@google.com> adb: add `adb reconnect offline` to reconnect offline devices.

Add a command to reconnect offline/unauthorized devices, mainly for use
with the inotify-monitoring of vendor key directories added by 2e671202.

Bug: http://b/29273531
Test: manually tested with a sailfish + copying vendor keys
Change-Id: If34cccee4ae553ada65d128b57d03cba8c0d7c46
/system/core/adb/transport.cpp
06d61d4d96d28777f76578fb5d3c823168853166 06-Oct-2016 Josh Gao <jmgao@google.com> adb: rationalize types.

Use fixed length types for structs going over the wire, constify
arguments where possible, use char* instead of unsigned char* for
apacket data, and assorted other refactoring.

Bug: http://b/29273531
Test: python test_device.py with every combination of old/new adb and adbd
Change-Id: I0b6f818a32be5386985aa4519f542003cf427f9d
/system/core/adb/transport.cpp
3bd2879d8e9bb0c0a1b8045e09f9cf87c2daeef3 06-Oct-2016 Josh Gao <jmgao@google.com> adb: split up adb_auth.cpp.

All of the functions in adb_auth.cpp were used in only one of
adb/adbd. Split up them up into adb_auth_host.cpp and adbd_auth.cpp
respectively.

Bug: http://b/29273531
Test: built and flashed bullhead, adb still works
Change-Id: Ib610c5157522634cc273511175152f1306cc52a7
/system/core/adb/transport.cpp
0cd3ae1c281fa890389987cd05b2bf01cdf1e4c5 21-Sep-2016 Josh Gao <jmgao@google.com> adb: kill adb_mutex_t, adb_cond_t.

Now that we have support for std::mutex and std::condition_variable on
Windows, remove our mutex compatibility layer in favor of the C++ one.

Bug: http://b/31653591
Test: mma && $ANDROID_HOST_OUT/nativetest64/adb_test/adb_test && \
python test_adb.py && python test_device.py
(also on Windows)

Change-Id: I5b7ed9c45cc2a32edcf4e77b56dc28e441f15f34
/system/core/adb/transport.cpp
8270912ed0ab160847bfcc1f5f4be7b3174333b1 22-Aug-2016 Josh Gao <jmgao@google.com> Merge changes I9761298a,I8d3312b2
am: 0b4fcb75d4

Change-Id: I330c467e408bc10ebdab0f5708d24d2297cf39a2
2e671202c38a9b17b0b034438a305e3067abb4ab 19-Aug-2016 Josh Gao <jmgao@google.com> adb: add support for vendor key directories.

Allow directories to be specified in ADB_VENDOR_KEYS. On Linux, monitor
this directory for new keys to be added.

Additionally, deduplicate keys by hashing their public key.

Bug: http://b/29273531
Bug: http://b/30927527
Change-Id: I8d3312b216b7f2c11900f2235f1f1b1d1c7aa767
Test: manually tested by adding a key to a directory, and verifying
that devices became authorized after replugging.
/system/core/adb/transport.cpp
81a3f71e45af5f19d426c7d0cc116ba3921d968a 12-Aug-2016 Josh Gao <jmgao@google.com> Merge "Clean up key handling in adb."
am: b859830450

Change-Id: I8d8ff82167a97e89eacbfcc97f3b704466927aa3
0aeb50500c76ea67d6f452907f5503d590e81a54 30-Jun-2016 Elliott Hughes <enh@google.com> Clean up key handling in adb.

This includes the locking we need to be able to re-load the keys at runtime.

We should rename "adb_auth_client.cpp" to "adb_auth_adbd.cpp" or
"adbd_auth.cpp" in a later change.

Change-Id: I9e1d5b6b7d0497d6f6e5d9c4fb660118cdff05a8
Test: "adb devices" works against a non-AOSP device with $ADB_VENDOR_KEYS set, says "unauthorized" without.
Bug: http://b/29273531
/system/core/adb/transport.cpp
16dad488b362d3812f9d67b4b751ba6cde22590d 26-May-2016 Yabin Cui <yabinc@google.com> Merge "adb: retry connecting disconnected emulators instead of always looping." am: 50e91fec0e
am: cfb0c5cd91

* commit 'cfb0c5cd913b689c8f9d0d930c92c6a0804e2995':
adb: retry connecting disconnected emulators instead of always looping.

Change-Id: I4b7f30bd3738ce53eb343e5d0e20f3d20faf7e2a
b74c6498aa2be70d591c900bda9ab7712c682a63 30-Apr-2016 Yabin Cui <yabinc@google.com> adb: retry connecting disconnected emulators instead of always looping.

Previously we loop through local ports every second, this patch improves
the strategy by retrying only just disconnected emulators.

Bug: 26468076
Bug: 19974213
Bug: 22920867

Change-Id: I43ccb746922d104202b0f81a3d163d850bbc890e
/system/core/adb/transport.cpp
e618f6cb367b83774274786bc28badae34a6c638 19-Apr-2016 Yabin Cui <yabinc@google.com> Merge "adb: use a custom thread to poll for usb devices on mac." am: 09c5fcf
am: 507f38f

* commit '507f38f6d7e8dcae4b513ea6c5f638ae43204245':
adb: use a custom thread to poll for usb devices on mac.

Change-Id: Idc21e33a8b0942afe0f6fa18076718d71d9d34f6
48d4c0c42afc1cb77c4573ac22adb61d2f92ccd3 25-Mar-2016 Yabin Cui <yabinc@google.com> adb: use a custom thread to poll for usb devices on mac.

On mac, if the adb server kicks a transport on some error, mac usb driver
will not report a new usb device. So instead of relying on mac usb driver
to report new usb devices, this CL uses a loop to search for usb devices
not exist before. Note that this is also the behavior on windows and linux
host.
`adb reconnect` can be used to verity this CL.

Bug: 25935458
Change-Id: I890e0eb1fae173f2e7a0c962ededa294d821e015
/system/core/adb/transport.cpp
2f46a7d0ecdbff4cc8f08d2f63e855dde681cb25 19-Apr-2016 Yabin Cui <yabinc@google.com> Merge "Fix kick_transport test." am: a960864
am: 119ca23

* commit '119ca2345d97db04d4114f5031d172f3694350d4':
Fix kick_transport test.

Change-Id: I4625174a1d62edfa8a1db52ced70356798d53c95
7f27490e7f386401dc38287a67dcb8826e2260c5 18-Apr-2016 Yabin Cui <yabinc@google.com> Fix kick_transport test.

Fix broken kick_transport test, and make it not access atransport
internal variables.

Bug: 25935458
Change-Id: I91b4d32a222b2f369f801bbe3903acac9c8ea4f7
/system/core/adb/transport.cpp
1a3ce9b3a6e70620b49fc6937280ecb7b6624f83 16-Apr-2016 Yabin Cui <yabinc@google.com> Merge "adb: add reconnect command." am: 643bc36
am: 1dd696a

* commit '1dd696a52687106d9926374d18895a911cc6fd28':
adb: add reconnect command.

Change-Id: Ibfdfe1675a8d3627d4fb8eef3592b9b836dc4d19
1f4ec19e499ba981e4117f647d191603c2713e79 05-Apr-2016 Yabin Cui <yabinc@google.com> adb: add reconnect command.

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
/system/core/adb/transport.cpp
29f8993098cbcb51a6218972c32aa2fd39555124 03-Mar-2016 David Pursell <dpursell@google.com> Merge "adb: relax serial matching rules." am: b4709c2cfd
am: a942881fdb

* commit 'a942881fdb8925373a8b8756301fa3a4d92cf174':
adb: relax serial matching rules.
3f902aad5b427a8162bf860a758878b55b13e775 01-Mar-2016 David Pursell <dpursell@google.com> adb: relax serial matching rules.

Currently targeting a device by serial requires matching the serial
number exactly. This CL relaxes the matching rules for local transports
to ignore protocol prefixes and make the port optional:
[tcp:|udp:]<hostname>[:port]

The purpose of this is to allow a user to set ANDROID_SERIAL to
something like "tcp:100.100.100.100" and have it work for both fastboot
and adb (assuming the device comes up at 100.100.100.100 in both
modes).

This CL also adds some unit tests for the modified functions to make
sure they work as expected.

Bug: 27340240
Change-Id: I006e0c70c84331ab44d05d0a0f462d06592eb879
/system/core/adb/transport.cpp
1c98db1ab19639d46f4b76b3ee4253fb8970143f 13-Feb-2016 Josh Gao <jmgao@google.com> Merge "adb: make adb_thread_func_t return void, add adb_thread_exit."
am: 69c81c75df

* commit '69c81c75df2e196aea679d24464a68233dcb5393':
adb: make adb_thread_func_t return void, add adb_thread_exit.
b5fea14e13bb6e41b36f374c954dc55faeef4627 12-Feb-2016 Josh Gao <jmgao@google.com> adb: make adb_thread_func_t return void, add adb_thread_exit.

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
/system/core/adb/transport.cpp
2e83684537326b027ef042d5712d2b861af8e626 14-Dec-2015 Elliott Hughes <enh@google.com> Merge "Share the new adb USB diagnostic code with fastboot." am: efd8c3289e
am: 40f80e25d3

* commit '40f80e25d3f399ece26d5f1ac145921ccb7f5f80':
Share the new adb USB diagnostic code with fastboot.
1b708d368f29e6053064c9cf6949ab6ebdbb7ac5 12-Dec-2015 Elliott Hughes <enh@google.com> Share the new adb USB diagnostic code with fastboot.

Bug: http://b/26134129
Change-Id: Ieaf0651c7b3f8a028760982091ec63a21a5484ba
/system/core/adb/transport.cpp
9046c23ed69214bcec87568cbe082320ffc6fc81 08-Dec-2015 David Pursell <dpursell@google.com> Merge "adb: add help text for USB permission errors." am: 663e949b2b am: e37325defc
am: 4542b62cca

* commit '4542b62ccafb749542bddaf0b442db554e7210e3':
adb: add help text for USB permission errors.
663e949b2bbda5dcc2b92e4d1936555019cdd66b 08-Dec-2015 David Pursell <dpursell@google.com> Merge "adb: add help text for USB permission errors."
ef119a14b8f5a7eca18930e272e550ebf25217bd 08-Dec-2015 Elliott Hughes <enh@google.com> Merge "Track rename of base/ to android-base/." am: 912ed3d8ca am: e2a9563be1
am: 3608ee5e90

* commit '3608ee5e903689ea7c433587be664649689816e1':
Track rename of base/ to android-base/.
4f71319df011d796a60a43fc1bc68e16fbf7d321 05-Dec-2015 Elliott Hughes <enh@google.com> Track rename of base/ to android-base/.

Change-Id: Idf9444fece4aa89c93e15640de59a91f6e758ccf
/system/core/adb/transport.cpp
d2acbd19312a66cbee2c49f455eddd82b6700d1d 03-Dec-2015 David Pursell <dpursell@google.com> adb: add help text for USB permission errors.

The current permission messages can be confusing for users who don't
know about udev and USB access permissions. This CL adds some checks to
try to identify common udev problems, and adds a link to online
documentation.

Example messages:

1) adb server is in plugdev group but access is still denied:
$ adb devices
List of devices attached
082f59270073e1e3 no permissions (verify udev rules); see [developer.android.com/tools/device.html]

2) plugdev group exists but adb server is not in it:
$ adb shell
error: USB permission failure: udev requires plugdev group membership.
See [developer.android.com/tools/device.html] for more information.

3) plugdev group does not exist:
$ adb shell
error: USB permission failure.
See [developer.android.com/tools/device.html] for more information.

Bug: http://b/25777880
Change-Id: I536565adc12ab657c75151309795674181205db0
/system/core/adb/transport.cpp
80a9bc872c7add5da12f7a23f79a44a1a0b81675 13-Nov-2015 Josh Gao <jmgao@google.com> Merge changes Ic124ecb9,I94de55d2 am: 26f2e1fd4f am: 9a3f299ec0
am: 33bc6f38e7

* commit '33bc6f38e7946108ff2fba947e2a2be0c8d62d7f':
libbase: remove exit-time destructors.
adb: remove exit-time destructors.
b7b1edf974a93cc4bb9a2de7a5e9c9bce9ad178b 12-Nov-2015 Josh Gao <jmgao@google.com> adb: remove exit-time destructors.

On exit, these destructors get invoked while other threads might
still be using them, potentially causing a crash, and definitely
causing tsan to report a race condition.

Bug: http://b/23384853
Change-Id: I94de55d22f97f4edd1d7cc1f34e8c1f8dfd56a5a
/system/core/adb/transport.cpp
51c05ec56832811eefff96bc76440a54e75c61cb 10-Nov-2015 Todd Kennedy <toddke@google.com> Revert "Revert "use new cmd command""

This reverts commit 3e3b4ec00770258f4e66684addded262dc13003a.

Change-Id: I8bfcd8a2a285f4254539ebca9f70222aa2448ef4
/system/core/adb/transport.cpp
4cb77fc2a343839ce2dfc00e0d73033b5650482c 09-Nov-2015 Elliott Hughes <enh@google.com> Merge "adb/base: minor compiler portability improvements" am: 892f0e9300 am: 8163cbc535
am: 3396ad2c16

* commit '3396ad2c16037c0fda6273708a750eb6a15e2038':
adb/base: minor compiler portability improvements
363af568b8491af1a4256b09b04cfa8a0606d8cc 08-Nov-2015 Spencer Low <CompareAndSwap@gmail.com> adb/base: minor compiler portability improvements

I've been using these changes to compile with Visual Studio.

- GetFileBasename(): __FILE__ uses \ with Visual Studio.

- adb_trace.cpp: Apparently VS needs an ampersand before the function name.

- "expr1 ? : expr2" is a GCC extension.

- <algorithm> contains std::min().

- seekdir can't always be #define'd because some headers have members
named seekdir.

- adb_utils.cpp: Not really a compiler issue, just a random fix:
0x7F/DEL is not printable.

Change-Id: I0dfb634f1ba4ccbc0d1b9f71b00e838fbebb3b41
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
/system/core/adb/transport.cpp
3e3b4ec00770258f4e66684addded262dc13003a 09-Nov-2015 Todd Kennedy <toddke@google.com> Revert "use new cmd command"

This reverts commit d039800a4e008b52c532f901e3bb34b40877cf30.

Change-Id: Ia9b81c47120088593a56ae09a9b002338d524b8a
/system/core/adb/transport.cpp
79e1c7a7f8a6caf8fe77c6fa1ef46b3ddac9fb99 07-Nov-2015 Elliott Hughes <enh@google.com> AOSP master doesn't have "cmd".

Change-Id: I0f524b779a623a9e2db923fd9003b102460ae46f
/system/core/adb/transport.cpp
6fa848adbab275c76d590a133290a59a6ef9a4d5 04-Nov-2015 Todd Kennedy <toddke@google.com> use new cmd command

Instead of using the pm command, 'adb install' and 'adb uninstall' will now
use the cmd command. Additionally, the APK will be streamed directly to
package installer instead of creating a temporary file.

(cherry-pick of d039800a4e008b52c532f901e3bb34b40877cf30.)
Change-Id: Ie7529afa5b039d29cc8183f36085ff4e66b3457a
/system/core/adb/transport.cpp
d039800a4e008b52c532f901e3bb34b40877cf30 04-Nov-2015 Todd Kennedy <toddke@google.com> use new cmd command

Instead of using the pm command, 'adb install' and 'adb uninstall' will now
use the cmd command. Additionally, the APK will be streamed directly to
package installer instead of creating a temporary file.

Change-Id: Ie7529afa5b039d29cc8183f36085ff4e66b3457a
/system/core/adb/transport.cpp
65fe2516b402ed8903f2ce39a86fa0bdc2b263a6 08-Oct-2015 Elliott Hughes <enh@google.com> Use const auto&/auto&& in adb.

Change-Id: I74a7e511302e15e207906f572d181634e0ed5604
/system/core/adb/transport.cpp
8d28e191c5ba81b82e51e3fd120d03851e1d905f 07-Oct-2015 Elliott Hughes <enh@google.com> Fix adb -d/-e error reporting.

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
/system/core/adb/transport.cpp
70ef7b40f96e44ebb86f4eb23ccfa1a9230cdb65 30-Sep-2015 David Pursell <dpursell@google.com> adb: put legacy shell: service back in.

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
/system/core/adb/transport.cpp
a36f4d680a02dbf2bf2166f148f4c5200ec1d8f4 28-Sep-2015 David Pursell <dpursell@google.com> Merge "adb: bump server version to prevent feature mismatch."
d2b588e23901538f4b459a71fefdac6fc2748f7e 25-Sep-2015 David Pursell <dpursell@google.com> adb: fix adbd feature parsing for no features.

Previously the transport features list was only overwritten if a
new feature list was found. However, adbd can reuse the same atransport
object even if the adb server is killed and restarted, so the feature
list was not cleared properly if the newly started adb server didn't
provide one.

This CL fixes the bug by clearing the transport features list whenever
a connection banner is parsed.

Bug: http://b/24405971
Change-Id: Ia6ee6c9a46a621534681f6d4d7df77156b885eb9
/system/core/adb/transport.cpp
bbe3d210ba9776f2e72f17c6213438890e1a8683 25-Sep-2015 David Pursell <dpursell@google.com> adb: bump server version to prevent feature mismatch.

Devices get a list of supported features from the adb server, not the
client, so a mismatch between client and server features can cause the
device to use an incorrect feature set.

Bumping the server version is the easiest way to make sure the client
and server features match and seems like the best solution at the
moment.

A more automated fix could be to compare client/server features on each
connection and restart if they don't match. This requires an extra
client <-> server round-trip per command, but removes the need to
manually bump the server version number on feature change. Unless the
feature set changes often it didn't seem worth the extra overhead.

Bug: http://b/24370690
Change-Id: I4e43825d1c15c61e5d924fc8d4110b467debde37
/system/core/adb/transport.cpp
aed3c61c4437ebb05eadfb3bf85d6962c30b9935 23-Sep-2015 Yabin Cui <yabinc@google.com> Adb: use VLOG() to replace D() for verbose logging.

As there are too many D(), we can keep both VLOG() and D() now, and get
rid of D() gradually.

Change-Id: I2f1cb70bcab3e82c99fed939341d03f6b2216076
/system/core/adb/transport.cpp
4e2fd36bc8c16147cab323b0418a7666812d3bc7 22-Sep-2015 David Pursell <dpursell@google.com> adb: add -Tt options to `adb shell`.

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
/system/core/adb/transport.cpp
606835ae5c4b9519009cdff8b1c33169cff32cb1 09-Sep-2015 David Pursell <dpursell@google.com> adb: add client side shell protocol and enable.

Adds the shell protocol functionality to the client side and enables it
if the transport supports the feature.

Bug:http://b/23031026
Change-Id: I9abe1c8b1d39f8dd09666321b1c761ad708a8854
/system/core/adb/transport.cpp
0955c66b226db7a7f34613f834f7b0a145fd407d 31-Aug-2015 David Pursell <dpursell@google.com> adb: implement shell protocol.

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
/system/core/adb/transport.cpp
7a3f8d6691b3fbd8014a98de8455dbcfcc9629e4 03-Sep-2015 Yabin Cui <yabinc@google.com> adb: clean up debug tracing a little.

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
/system/core/adb/transport.cpp
d6ab3c2245b6c71605bad746a535028b717e899a 31-Aug-2015 Yabin Cui <yabinc@google.com> adb: improve names for transport threads.

The old names seems confusing. output_thread was reading remote data and writing to
local sockets. input_thread was reading local sockets data and writing to remote.
This change tries to make it clear by renaming output_thread to read_transport thread,
and renaming input_thread to write_transport thread.

Change-Id: I2e7b4cde7a94d436f3745e9e3ab10780e7caa8ac
/system/core/adb/transport.cpp
0c3914a44d608614a2cf5225e0072f41b2910d3c 31-Aug-2015 Elliott Hughes <enh@google.com> Distinguish transport threads.

Use "<-" and "->" to work around Linux's very short thread name limit.

Bug: http://b/23423333
Change-Id: I9f3f096415b47162dacb660cd0a97ac7ff6107e6
/system/core/adb/transport.cpp
49ee7cf9a10f66ffa9a3490c69db5fa46e0a966b 29-Aug-2015 Siva Velusamy <vsiva@google.com> adb: set thread names (linux & mac)

Bug: 23423333
Change-Id: I0069f32ddbae2a10fb130064f721facf45b2cc09
/system/core/adb/transport.cpp
b329824e6c5373ae303269dca285d835ce57e514 29-Aug-2015 Yabin Cui <yabinc@google.com> adb: clean up transport disconnect operations.

Move operations from global functions into member functions.
Add unit test.

Change-Id: Id4543d8e78541eb08c8e629f180c605c699737ec
/system/core/adb/transport.cpp
12d7f0909a4332c0f03ea0bd49741cc6c46a2353 28-Aug-2015 Yabin Cui <yabinc@google.com> adb: call run_transport_disconnects() only once.

Currently run_transport_disconnects() are called twice. One is in
handle_offline(), another is before destroying transport.
The users of disconnect callback are listener, adb_auth_client, and
remote_sockets. All of them need only to be called once. And after
handle_offline, no new listeners, adb_auth_client, or remote_sockets
can be connected to the offlined transport. So I think we can remove
the second call to run_transport_disconnects().

Change-Id: I1ef8b6b7b5ab7ae1bad109be107c85973d65a2e3
/system/core/adb/transport.cpp
f4b9928563e97620fc1d9bd5c2efdaa0ded96488 27-Aug-2015 Yabin Cui <yabinc@google.com> adb: disconnect: fix write-after-free memory corruption and crash.

Transport atransport objects are semi-reference counted: the input and
output threads each hold a reference. The adb disconnect command was
calling transport_unref to release a reference that it never had in the
first place. This meant that the refcount dropped to zero and the object
was deleted before either the input or output thread released its
reference. When that last thread released its reference, it wrote to
freed memory and also sometimes crashed.

This fix is to not release any unheld reference, instead it just kicks
the transport to break remote_read in output_thread. So all transport
close flow goes the following way:
output_thread (exit) -> main thread (offline the transport) ->
input thread (exit) -> main thread (destroy the transport)

Change-Id: Iad1fe718acc8716f3a79c8c22b426a1b2450452c
/system/core/adb/transport.cpp
f3068123039e81cee85ce9103d01b5b2aceb2ba3 27-Aug-2015 Yabin Cui <yabinc@google.com> Merge "adb: fix a fake data race on transport:kick reported by tsan."
d8459b3d3c8f9b1bfb3b6871b9c7d6e235cca6fa 26-Aug-2015 Yabin Cui <yabinc@google.com> adb: fix a fake data race on transport:kick reported by tsan.

It is reported by tsan as a double checked locking. But I think
it is not a real data race. Because I think the old code is able
to make sure t->kick() is only called once, and the caller of
kick_transport is not relying on the side-effect of calling
t->kick().
But as it is not perf critical, I don't mind breaking the double
checked locking pattern.

Bug: 23385662
Change-Id: Ie3597dd56bb514117c3865d2afcfd7c115731a78
/system/core/adb/transport.cpp
34f45c566365c966c78264e8a4dc0cf69957b6fa 26-Aug-2015 Yabin Cui <yabinc@google.com> adb: keep all asocket operations in the main thread.

As far as I can see, all asockets operations happen in fdevent_loop()
in the main thread, excepting close_all_sockets(). Instead of adding
lock and ref_count for each asocket, a simpler way would be moving
close_all_sockets() from input_thread to the main thread.

In input_thread(), there are two path to break the loop and call
close_all_sockets(). One path is when receiving offline A_SYNC, which
is sent by the main thread. The other path is when read_packet
fails, which I believe is almost not possible and doesn't matter
(Because t->fd is closed just before t is freed.). So I move
close_all_sockets() to handle_offline() in the main thread.

the socket_list_lock in sockets.cpp could be removed. But I prefer
to leave it for the following changes.

Bug: 6558362
Change-Id: I5da23f60a67a331262c62693b9b127fe2689c799
/system/core/adb/transport.cpp
8fcd8bc046188abe0b0e87754af472d4838b4c50 25-Aug-2015 Elliott Hughes <enh@google.com> EINTR is handled by adb_read/unix_read and friends.

No need to clutter the code with cases that won't happen.

Change-Id: I47c5a2e6170f902d2618719f44492234a4869567
/system/core/adb/transport.cpp
aa2454919098ee14cd232669f1e7dbb33ed07ccf 03-Aug-2015 Elliott Hughes <enh@google.com> adb sync cleanup.

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
/system/core/adb/transport.cpp
1792c23cb892ab58590b2cdfce0d0ece30c21787 18-May-2015 Dan Albert <danalbert@google.com> Add feature list to connection banner.

This allows us to test for features explicitly rather than relying on
the protocol version number, allowing us to fall back gracefully if a
feature is not supported.

This will be needed for the upcoming shell upgrades for stdout/stderr
separation and exit code reporting.

Change-Id: Ibb1d8ad2611f7209901ee76d51346b453e9c5873
/system/core/adb/transport.cpp
6264129434e511da38faedeb5739c3e4bd4a710e 31-Jul-2015 Yabin Cui <yabinc@google.com> Make clear of the data length sent by write_packet.

Change-Id: If51b4feaa19a710874999ad7e6131ff2e56a9f8a
/system/core/adb/transport.cpp
3d2904cdf2371e26c0465184436bd063979a5d97 13-Jul-2015 Tamas Berghammer <tberghammer@google.com> Increase size of the the adb packets sent over the wire

The reason behing this change is to increase the adb push/pull speed
with reduceing the number of packets sent between the host and the
device because the communication is heavily bound by packet latency.

The change maintains two way compatibility in the communication
protocol with negotiating a packet size between the target and the
host with the CONNECT packets.

After this change the push/pull speeds improved significantly
(measured from Linux-x86_64 with 100MB of data):

| Old push | Old pull || New push | New pull |
-----------------------------------------------------------
Hammerhead | 4.6 MB/s | 3.9 MB/s || 13.1 MB/s | 16.5 MB/s |
-----------------------------------------------------------
Volantis | 6.0 MB/s | 6.2 MS/s || 25.9 MB/s | 29.0 MB/s |
-----------------------------------------------------------
Fugu | 6.0 MB/s | 5.1 MB/s || 27.9 MB/s | 33.2 MB/s |
-----------------------------------------------------------

Change-Id: Id9625de31266e43394289e325c7e7e473379c5d8
/system/core/adb/transport.cpp
8d8126a705dd3c5734a0894f88c2c758784bd469 21-Jul-2015 Spencer Low <CompareAndSwap@gmail.com> adb: logging: newlines, thread ids, error code overwriting

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>
/system/core/adb/transport.cpp
64d303a0e750e5604564d6a91c11aea663f6874a 18-Jul-2015 Elliott Hughes <enh@google.com> Fix adbd/adb server confusion in an error message.

Change-Id: Iacb8bcfb1e8e1d46198ee4ba8cf0ec0d1b98c75a
/system/core/adb/transport.cpp
e2d3677cc2239a8530d33e3c5e24e65fff096801 23-Jun-2015 Elliott Hughes <enh@google.com> Improve the "device '(null)' not found" error.

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
/system/core/adb/transport.cpp
c7915a3470292349017f94ca066ed515babfcc23 19-May-2015 Dan Albert <danalbert@google.com> Make atransport be a real class.

Using non-POD types in atransport means we'll need to start treating
it as a real class (specifically with regards to new/delete rather
than malloc/free).

I've also cleaned up the home grown linked lists for transport_list
and pending_list to just be std::lists. We might want to refactor that
again to be an std::unordered_map keyed on serial, since that seems to
be a common way to search it.

Change-Id: I7f5e23cdc47944a9278099723ca029585fe52105
/system/core/adb/transport.cpp
dcd78a15d0be143d48fc93af6a9fa5748dbf9790 19-May-2015 Dan Albert <danalbert@google.com> Make connection states a proper type.

Change-Id: I809f9b327c832b88dd63151bf7dcb012d88e81c4
/system/core/adb/transport.cpp
d99d902abdbcb86fd0f1db5d6204c02126d1e818 07-May-2015 Dan Albert <danalbert@google.com> Be tolerant of devices that don't report serials.

The USB spec explicitly says this is optional, so we shouldn't be
relying on it.

Bug: http://b/20883914
Change-Id: Icf38405b00275199bcf51a70c47d428ae7264f2b
/system/core/adb/transport.cpp
9b0f354fa25e3d5add516000c761e07c81c3bbc1 05-May-2015 Elliott Hughes <enh@google.com> Simplify adb_thread_create.

Change-Id: I36d6021ef8fbc23e8bcd4ddbe1dac0eba467cc70
/system/core/adb/transport.cpp
3bd73c12c07dcefc965abeef535ac53c4754d682 05-May-2015 Elliott Hughes <enh@google.com> Give enum types CamelCase names for clarity.

Change-Id: I1c89f1cc155ee839f372fb14d972a288183b8bcd
/system/core/adb/transport.cpp
ab52c181fa4c1c9891644635dc5653cda5b90e2b 02-May-2015 Elliott Hughes <enh@google.com> Add WriteFdFmt and clean up more code.

Also say *which* device wasn't found.

Bug: http://b/20666660
Change-Id: I50e234ad89e39ae0a8995083c0b642c61275c5a3
/system/core/adb/transport.cpp
e67f1f87d9b1188ec8617035db7006c37ee7b21e 01-May-2015 Elliott Hughes <enh@google.com> More adb buffer fixes.

This patch factors out a lot of the basic protocol code: sending OKAY,
sending FAIL, and sending a length-prefixed string.

ADB_TRACE has been non-optional for a long time, so let's just remove
the #ifs.

Also actually build the device tracker test tool (and remove its duplicate).

Bug: http://b/20666660
Change-Id: I6c7d59f18707bdc62ca69dea45547617f9f31fc6
/system/core/adb/transport.cpp
6452a89aa8934231e12ab77e0d90f12c3e892ad1 29-Apr-2015 Elliott Hughes <enh@google.com> More fixed-length buffer removal.

Bug: http://b/20666660
Change-Id: I0c738e9fed2defed48a9cf2d0a4f7b99c08dcf3d
/system/core/adb/transport.cpp
dc3b459ff9f0ff71d404ba7198083e532a0dd894 22-Apr-2015 Elliott Hughes <enh@google.com> Add missing null checks after allocations.

Bug: http://b/20317729
Change-Id: I62bb761d48ee59a1f4ddd0cdd0632432305ca2ca
/system/core/adb/transport.cpp
0b8ecb32908f0ccde550dd510f4a562239085806 17-Apr-2015 Elliott Hughes <enh@google.com> Merge "Remove extern "C" barriers to using C++."
2d4121c0dcc93382bcd7ea6476f433d8254919dd 17-Apr-2015 Elliott Hughes <enh@google.com> Remove extern "C" barriers to using C++.

Change-Id: Ic046d6aa540738cb46b54531bc59ba3b47b0136d
/system/core/adb/transport.cpp
7be29c819b4fb8bf9b1d4b69a4333f8765de0281 17-Apr-2015 Elliott Hughes <enh@google.com> Show $ADB_VENDOR_KEYS if authentication fails.

Incorrectly set $ADB_VENDOR_KEYS is the most likely cause of failed
adb connections. Make it easier to debug such problems by including
the value in use in the error message.

Bug: 20165551
Change-Id: I64c1d98ae6d3fb40eea9e1f0ddcfcf4f2d9d7318
/system/core/adb/transport.cpp
09a45a1927415de1540ad9c94ed0052ef2eb2184 04-Apr-2015 Elliott Hughes <enh@google.com> Fix "adb devices -l".

Change 055f1aa4ff58ba71133d506b202ad46612758ded switched to using isalnum(3)
but didn't take into account that isalnum has the opposite sense to the
function it replaced, so the tests should have been inverted.

Bug: http://b/20056546
Change-Id: I90630c0bea69ddbb4a95dc09f79f49d23fd497de
/system/core/adb/transport.cpp
3313426fad9eaaf53017cdbde889ebcec91358ec 19-Mar-2015 Dan Albert <danalbert@google.com> File header cleanup.

* sysdeps.h should always be included first.
* TRACE_TAG needs to be defined before anything is included.
* Some files were missing copyright headers.
* Save precious bytes on my SSD by removing useless whitespace.

Change-Id: I88980e6e00b5be1093806cf286740d9e4a033b94
/system/core/adb/transport.cpp
bac3474a8256cb32a29e8d46f78cad95a5502692 26-Feb-2015 Dan Albert <danalbert@google.com> Move adb to C++.

I keep trying to clean things up and needing std::strings. Might as
well just do this now.

usb_linux_client.c is going to stay as C because GCC isn't smart
enough to deal with the designated initializers it uses (though for
some reason it is in C mode).

The Darwin files are staying as C because I don't have a way to test
that they build.

The Windows files are staying as C because while I can actually build
for them, it's slow and painful.

Change-Id: I75367d29205a9049d34460032b3bb36384f43941
/system/core/adb/transport.cpp