Commit graph

1684 commits

Author SHA1 Message Date
Elliott Hughes
1ef5bf839e Fix buffer overrun in adb wait-for-device.
Bug: http://b/27444063

(cherry picked from commit 34e560b9a1)

Change-Id: Ic71cb2070f509d76fb4208dbab6711c5dd5e1f62
2016-03-11 08:55:01 -08:00
Prathmesh Prabhu
01d76eb1ec Merge "emulator: Use distinct serial names for simultaneous qemu pipes." into nyc-dev 2016-03-10 17:13:26 +00:00
Prathmesh Prabhu
251d46e68a emulator: Use distinct serial names for simultaneous qemu pipes.
ADB local transport for the emulator based on qemu pipes uses a socket
transport. Before this CL, multiple connection requests accepted by the
qemu pipe device would result in ADB transport with the same serial.
The register function would fail as a result, and all subsequent
connections would fail.

Test:
while true; do adb kill-server; adb devices; done
Doesn't fail for > 10 minutes.

This CL replaces an earlier CL
(I0fdcf2694516151c5f8f8e1580648b940679c981) that was unsafe for real
devices.

BUG=27441661

Change-Id: I7d801b175f3bee10fc7e0ab1b12d5623984371b9
2016-03-09 13:51:30 -08:00
Josh Gao
8238dd8499 adbd: fix spurious close of uninitialized fd.
forkpty only returns an fd on the master side; trying to keep track of
it on both sides is incorrect.

Bug: http://b/27504427
Change-Id: Ia4a454d8490c77738f9c3350a4236b3d99c8758b
(cherry picked from commit fcb063ce37)
2016-03-04 19:15:11 -08:00
Josh Gao
5767d0dd5a adb: wait for restore to complete before returning.
If we return before waiting for the other side to finish, it'll get sent
SIGHUP.

Bug: http://b/27414382
Change-Id: I93514d2242ed0d7aa93a6ec6836270dc0783506d
(cherry picked from commit d26abed750)
2016-03-04 19:15:11 -08:00
Josh Gao
06c73ae942 adb: wait for adbd to die and respawn in root/unroot.
Bug: http://b/19749057
Change-Id: I57dbc113803b6fd3016c1801410be0f4023245d9
(cherry picked from commit d26212207d)
2016-03-04 19:15:11 -08:00
Josh Gao
a9eb38d6a5 adb: make ScopedFd universally accessible and useful.
Change-Id: I707ffbd10958e7449b4c95dff48638480c746939
(cherry picked from commit f0d3b4fc11)
2016-03-04 19:15:11 -08:00
Josh Gao
a996c2963a adb: clean up quotes in test_device.py.
Change-Id: I7fe7724578ad89a004665d1bbff0d5c02c34c35e
(cherry picked from commit 255c5c8077)
2016-03-03 15:46:51 -08:00
Josh Gao
379612b128 adb: mkdir the correct directory name when pulling.
The directory name should be based off of the local path, not the remote
path.

Change-Id: I75b089b8734e9dbf8e466b1e00ea18549fd101bb
(cherry picked from commit 89ec3a8d0f)
2016-03-03 15:46:51 -08:00
Josh Gao
48bc0d7853 adb: cleanup file skipping logic.
Bug: http://b/26355212
Change-Id: Iafa250ce6c5ea8da9f5f00125165e5b67ef1013f
(cherry picked from commit a31ea55c55)
2016-03-03 15:46:51 -08:00
Josh Gao
74e0fe73c0 adb: symlinks to dirs count as dirs for pull destination.
This matches scp's behavior when pulling a directory that collides
with a symlink to a directory.

Bug: http://b/27362811
Change-Id: I0936d1ad48f13e24cd382e8e8400cc752bac3b66
(cherry picked from commit 1e611a33d5)
2016-03-03 15:46:50 -08:00
David Pursell
802c54ebb7 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
(cherry picked from commit 3f902aad5b)
2016-03-03 15:46:50 -08:00
Josh Gao
f22bc60fc9 adb: report progress for small files.
Bug: http://b/27407725
Change-Id: I7515144402a487fb3d4d403e2f5f82423c1b5ed6
(cherry picked from commit 9fd2f77dcc)
2016-03-03 15:46:50 -08:00
Ying Wang
f48503b4a0 Also archive adb.exe/fastboot.exe when building win_sdk.
On linux we archive both Linux and Windows binaries.

Bug: 27315911
Change-Id: I17d25cd1ea611a9c917f1e78b47f21a8959eea20
(cherry picked from commit 71edfc8b9a)
2016-03-03 15:46:50 -08:00
Josh Gao
a63b17f76c adb: fix directory creation logic.
Previously, for `adb pull $remote $local`, we would do the equivalent of
mkdir -p on `dirname $local`. This patch changes the behavior to only
creating directories that are being pulled, like scp.

Bug: http://b/27362811
Change-Id: I79f975ee9f2d9bc9e8be6a7c4f2de6d7ae2d2d23
(cherry picked from commit 71728ca300)
2016-03-03 15:46:50 -08:00
Josh Gao
d382d2bb51 adb: fix mistaken use of PLOG.
Change-Id: I60bfa3d8cf1572a877d6f0c9369d8f72f10e5aef
(cherry picked from commit 443a52c298)
2016-03-03 15:46:50 -08:00
David Pursell
a76e5f035e adb: use TCP keepalive.
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
(cherry picked from commit bfd9503d1d)
2016-03-03 15:42:11 -08:00
bohu
8ac1b044af Emulator: fix adbd qemu pipe partial write
It does happens that the adb_write only writes to the
qemu pipe partially which throws host side's adb backend
into confusion and crashes.

This CL replaces adb_write with WriteFdExactly;
adb_read with ReadFdExactly.

(cherry picked from commit f66c5938be)

Change-Id: I684f5df79b1e3f00b4b7a2452c2712a73c15973c
2016-03-01 17:39:31 -08:00
Alex Klyubin
8a67c09e7d Merge "Only debuggable packages can be downgraded." into nyc-dev 2016-02-25 20:26:54 +00:00
Josh Gao
2eaa41a6df adb: fix leak of framework_fd.
Move the fdevent for the framework authentication connection out of
atransport into its own static variable in adb_auth_client, since its
lifetime is completely unrelated to that of the USB connection.

Bug: http://b/27297963
Change-Id: Ie6180d0b59d133120c5755e239e76ab33ed3cc1d
(cherry picked from commit 9f48611554)
2016-02-25 11:01:59 -08:00
Josh Gao
b6117c4397 adb: bail out if wait_for_device fails in send_shell_command.
Bug: http://b/27166186
Change-Id: Ib7e9d7e6b909d67a3af94c3517a6a0b54cf17db7
(cherry picked from commit f56c39194f)
2016-02-25 11:01:38 -08:00
Alex Klyubin
85ed97518c Only debuggable packages can be downgraded.
This reflects the change in PackageManager service:
frameworks/base commit 921dd754ab49df0cd580ff96503f7616c4c85f4a.

Bug: 27327503
Change-Id: Ifcc7268cd271640417b8cfc9db81ea954b491cb1
2016-02-24 16:07:47 -08:00
Dan Willemsen
ed1d7aeee4 Remove duplicate fdevent.cpp entry
Fixes the following warnings:

build/core/binary.mk:894: warning: overriding commands for target
`out/target/product/bullhead/obj/STATIC_LIBRARIES/libadbd_intermediates/fdevent.o'
build/core/binary.mk:894: warning: ignoring old commands for target
`out/target/product/bullhead/obj/STATIC_LIBRARIES/libadbd_intermediates/fdevent.o'
build/core/binary.mk:894: warning: overriding commands for target
`out/target/product/bullhead/obj_arm/STATIC_LIBRARIES/libadbd_intermediates/fdevent.o'
build/core/binary.mk:894: warning: ignoring old commands for target
`out/target/product/bullhead/obj_arm/STATIC_LIBRARIES/libadbd_intermediates/fdevent.o'

Change-Id: Id4b13574e568284cefbc3a763d40843e73ddbd3d
(cherry picked from commit 582c8fe1d4)
2016-02-24 12:14:48 -08:00
Josh Gao
fa3e0bc67f adb: sysdeps_test: improve smoke test.
Make sure that adb_poll sets revents for all of the structs passed in.
Also, zero initialize all of the adb_pollfd structs in the tests.

Change-Id: Ia639679a7e6f77483655f1552e89081c4673aa87
(cherry picked from commit 2275f7da73)
2016-02-22 15:57:09 -08:00
Josh Gao
da8119596f adb: check for an error response from adbd between each write.
When sending a file, do a 0-timeout poll to check to see if an error has
occurred, so that we can immediately report failure.

Bug: http://b/26816782
Change-Id: I4a8aa8408a36940bfda7b0ecfa5d13755f4aa14d
(cherry picked from commit afcdcd703e)
2016-02-22 15:57:09 -08:00
Josh Gao
4d74811cd4 adbd: restore the old error handling behavior.
Restore the previous file sync error handling behavior of reporting
failure, and then consuming packets from the other end until receiving a
DONE packet.

Bug: http://b/26816782
Change-Id: I9708f2a36c072547e191fa0b6b42dffc31f8a2f2
(cherry picked from commit 20a96c7d79)
2016-02-22 15:57:09 -08:00
Josh Gao
8d68591c46 adb: change unsigned to uint32_t in sync struct definitions.
Change-Id: I9757ab853cfad1a2e1393ef32bcab222ab84acef
(cherry picked from commit 69469c4e9f)
2016-02-22 15:57:09 -08:00
Josh Gao
cd2039e484 adb: detect when the client disconnects in wait-for-device.
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
(cherry picked from commit 09855472f4)
2016-02-22 15:57:08 -08:00
Josh Gao
b582fa3bd8 adb: make fdevent_test, socket_test compile on Windows.
Switch pthread_* to use the adb_thread_* abstractions to allow the fdevent
and socket tests to compile on Win32.

Bug: http://b/27105824
Change-Id: I6541bb1398780b999837e701837d7f86a5eee8ca
(cherry picked from commit 022d447e9e)
2016-02-22 15:57:08 -08:00
Josh Gao
c1d252bec2 adb: add fd exhaustion test, fix errno reporting in sysdeps_win32.
Add a test for FD exhaustion, and fix cases where we weren't properly
setting errno.

Change-Id: I486055bb9ead31089ce76b210c11de9e973f3256
(cherry picked from commit 6487e74a59)
2016-02-22 15:57:08 -08:00
Josh Gao
8443fd994a adb: move win32 fd base to 2048, fix fd allocation.
Windows has a maximum fd limit of 2048, so we can avoid collision with
real file descriptors by starting from there. Also, fds would be
previously be allocated by a linear walk from the last allocated FD,
instead of the lowest available FD, as required by POSIX. Keep track of
the lowest available file descriptor to make things feel more familiar.

Change-Id: Id6ac1c54f4f7964a6cdfa8d3f4f96262e4881964
(cherry picked from commit b6232b96dd)
2016-02-22 15:57:08 -08:00
Josh Gao
addab3d84d adb: don't emulate fdevent or socketpair on Windows.
Change-Id: I16cf7d4427eb79f36db39e91f85402a268fa72f5
(cherry picked from commit 3777d2ecc0)
2016-02-22 15:57:08 -08:00
Josh Gao
0b57ef735a adb: fix clang-format for access modifier dedent.
It was previously -1 (the default from Google style, since it uses 2
space indentation), instead of -2.

Change-Id: I1865505ce17a2cc13b85de58bda55c3b1dfcf08c
(cherry picked from commit 5da522ec45)
2016-02-22 15:57:08 -08:00
Dimitry Ivanov
8b642e42b4 Add missing liblog dependency
Bug: http://b/27171986
Change-Id: Ia7f03c72de9a8e5d61896bde6b4b1af396376f54
(cherry picked from commit 01f21da732)
2016-02-22 15:57:08 -08:00
Josh Gao
2674cd922e adb: sysdeps_win32: actually change ExitThread to _endthreadex.
Forgot to amend this into b5fea14e.

Change-Id: Id04e639eb87043901681db789d7a7925300fa867
(cherry picked from commit d7b3749202)
2016-02-22 15:57:08 -08:00
Josh Gao
d9db09c315 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
(cherry picked from commit b5fea14e13)
2016-02-22 15:57:08 -08:00
Josh Gao
7e76c89544 adb: redact reference to secret internal time machine.
Change-Id: Ic6744cc7c858576d7e6172460b32902e007b6fd3
(cherry picked from commit 6b42a2bfd5)
2016-02-22 15:57:08 -08:00
Spencer Low
a1071c6924 adb: mkdirs fixes
Fix pathological case where the directory to be created can't be created
because there is already a file there. This was previously returning
success because the wrong var was passed to directory_exists().

Fix test to exercise this situation. Also clarify tests.

Change-Id: I0dc0f14084e0eda4e1498874d4ab2a6445d322ac
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
(cherry picked from commit 85c45bd5a1)
2016-02-22 15:57:08 -08:00
Josh Gao
d302a15a60 adb: sysdeps: add support for joining threads.
Bug: http://b/27105824
Change-Id: I44e4edbb2a59565c35f1f3e6a6394ac258591f95
(cherry picked from commit 3b3e10d046)
2016-02-22 15:57:08 -08:00
Josh Gao
32a2b60c4e adb: allow wine's output for sysdeps_win32 strerror test.
Change-Id: Ia5d04a2347df1bcd8c7efcc1da9cec9725007a58
(cherry picked from commit 22554c9167)
2016-02-22 15:57:08 -08:00
Yabin Cui
65f7080c66 adb: setsid() for adb host server.
To create a daemon for adb host server, we should call setsid()
for the daemon process. However, previously we call setsid() for
the adb client process, which results in nothing but EPERM error.

Bug: 26982628
Change-Id: I2763ae3d5a243706927d7ef6af5095138c0ce2d8
(cherry picked from commit 6bf323b97a)
2016-02-22 15:57:08 -08:00
Josh Gao
9ad736a637 adb: make ctrl-c when spawning a daemon not kill the daemon.
Previously, using ctrl-c in a command that needs to spawn a daemon
because one isn't already available would kill the daemon along with the
foreground process.

Bug: http://b/26982628
Change-Id: I7fefc531c3e4895423e7b466322b5426d01dc9ef
(cherry picked from commit b72b3f8c92)
2016-02-22 15:57:08 -08:00
Josh Gao
db262ffa62 adb: fix mkdirs test.
The behavior of mkdirs was changed a while ago, without updating the
test.

Change-Id: I2aaa73818933b281e911c42a14e3c843d8bd972a
(cherry picked from commit 1172b2ec71)
2016-02-22 15:57:07 -08:00
Josh Gao
3a45f945c7 Merge "adb: don\'t append a slash to a path that already ends with one." am: aae1eb2c4f
am: 4b09d2f084

* commit '4b09d2f084dfe2df3314a10c59090be2c97b9a9e':
  adb: don't append a slash to a path that already ends with one.
2016-02-04 02:35:31 +00:00
Elliott Hughes
2b012f2059 Merge "adb: win32: fix start-server to properly display UTF-8 on the console" am: 1617dd4fe9
am: 89df186cda

* commit '89df186cdab8eb21c7610de9a8348b6f050543d7':
  adb: win32: fix start-server to properly display UTF-8 on the console
2016-02-04 02:35:25 +00:00
Josh Gao
d8e0108418 Merge "adb: report subprocess creation errors to the client." am: 7aa7a81eb1
am: 046bf3b212

* commit '046bf3b212e9a01c3f2671c208ae3bfc8fdcd62b':
  adb: report subprocess creation errors to the client.
2016-02-04 02:35:12 +00:00
Josh Gao
6832ddbc98 Merge "adb: fix mistaken uses of SendFail in file_sync_service.cpp." am: 2d2185ee09
am: f2610942ef

* commit 'f2610942efca1857c377df4f427ffaa3eefe65e8':
  adb: fix mistaken uses of SendFail in file_sync_service.cpp.
2016-02-04 02:35:06 +00:00
Josh Gao
aae1eb2c4f Merge "adb: don't append a slash to a path that already ends with one." 2016-02-04 00:36:32 +00:00
Spencer Low
53a0a99fe8 adb: win32: fix start-server to properly display UTF-8 on the console
fwrite() is a macro that maps to adb_fwrite(), which can write UTF-8 to
the console. Use it to write the output that comes from the subprocess
adb server.

To do this, dup the stdout/stderr file descriptor and make a duplicate
FILE* stream, in binary mode (since we're reading raw bytes from the
subprocess), and unbuffered.

Change-Id: I480761bae0bd576dc9e03fa4d31266f4e49635ed
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
2016-02-03 16:24:37 -08:00
Josh Gao
323899b6d3 adb: don't append a slash to a path that already ends with one.
Bug: http://b/26964908
Change-Id: I1fbd752fd97f5414a306b46f7bfce3373362f8b3
2016-02-03 16:24:13 -08:00