Commit graph

940 commits

Author SHA1 Message Date
Spencer Low
d396dc93a7 adb: win32: fix daemon acknowledgement
The daemon failed to startup because main.cpp was changed from calling
WriteFile() to android::base::WriteStringToFd(), the later which calls
write() in the C Runtime which by default has stdout in textmode which
does \n to \r\n translation.

The quick fix is to change stdout's mode from text to binary since right
after it is reopened to redirect to the daemon log file anyway.

Change-Id: I322fc9eae5d6abbf63f3d5917b0beb2171b5a15c
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
2015-05-11 15:57:43 -07:00
Elliott Hughes
9aa4fda4e6 Failure to find an oem partition should not be a remount failure.
Many devices don't have an /oem partition, so find_mount should be
expected to fail, but shouldn't cause the overall remount to fail.

Also clean up all the error handling and reporting, and remove the
dead int* globals.

Bug: http://b/21024141
Change-Id: Ie31021b03c9cab8e972269d7d1ffe383cd30ee9e
2015-05-11 13:28:22 -07:00
Dan Albert
c89e0ccd40 Revert "Revert "Split adb_main.cpp into client and daemon.""
This reverts commit 218dbccefa.

Change-Id: I74088db34983dc99e316a07c6ddc294340e0eb71
2015-05-08 17:33:21 -07:00
Dan Albert
218dbccefa Revert "Split adb_main.cpp into client and daemon."
This reverts commit cf07494ac2.
2015-05-08 16:08:57 -07:00
Dan Albert
3e1cb6d98d Revert "Probably fix the Mac build."
This reverts commit 49513cbcc7.
2015-05-08 16:08:53 -07:00
Dan Albert
49513cbcc7 Probably fix the Mac build.
This was throwing an unused variable warning for kWorkaroundBug6558362
on Darwin.

Change-Id: I1cbf381708e9884180a37f3246af36795d07dfc2
2015-05-08 12:45:15 -07:00
Elliott Hughes
ee5ce0d14f Merge "Fix "adb remount" for devices without an oem partition." 2015-05-08 17:49:11 +00:00
Dan Albert
cf07494ac2 Split adb_main.cpp into client and daemon.
The name "client" is somewhat misleading as it also contains the host
side adb server, but it's a part of the client binary.

Change-Id: I128b7bab213e330eb21b5010cd1fec5f7a62c8af
2015-05-08 10:20:26 -07:00
Elliott Hughes
f85f111620 Merge "Try to include the SHA in a ddmslib-compatible way." 2015-05-08 16:02:04 +00:00
Elliott Hughes
5677c23e8d Fix "adb remount" for devices without an oem partition.
On a device without an oem partition, we now have an /oem directory
anyway. This causes find_mount to fail, and that was returning nullptr
from a std::string-returning function. Boom!

Also clean up the bits of code I had to trace through between "adb remount"
on the host to the crash on the device as I debugged this.

The only other meaningful change is the error checking in
adb_connect_command --- adb_connect can also return -2.

Bug: http://b/20916855
Change-Id: I4c3b7858e13f3a3a8bbc7d30b3c0ee470bead587
2015-05-08 08:43:10 -07:00
Elliott Hughes
f3bbfa6a21 Try to include the SHA in a ddmslib-compatible way.
Bug: http://b/20918202
Change-Id: I0c1a48459372b0d28aaf9d09d82540e44b438c9c
2015-05-07 21:56:31 -07:00
Elliott Hughes
aee80fb67b Add some missing 'const's.
Change-Id: I5bd26d4366e10fc8c6bc255b7ddb174a7a8b82a5
2015-05-07 21:38:41 -07:00
Spencer Low
142ec75cf8 adb: win32: fix adb emu command
The adb emu command was never working because the socket connection to
the emulator was closed without reading all of the data that the
emulator sent. On Windows, this caused the emulator's recv() call to
error-out, so it never got the command that was sent.

Before settling on this fix, I also experimented changing the arguments
to the socket shutdown() call and that didn't seem to help. I also tried
removing the call to shutdown() and that didn't help. So that should
rule out shutdown() as the problem. One experiment that helped was
delaying before calling adb_close(), but that is of course fragile and
doesn't address the real issue, which is not closing the socket until
the commands have been read.

https://code.google.com/p/android/issues/detail?id=21021

Change-Id: I8fa4d740a2faa2c9922ec50792e16564a94f6eed
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
2015-05-06 18:54:08 -07:00
Dan Albert
d99d902abd 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
2015-05-06 16:48:52 -07:00
Elliott Hughes
3edd54b3a8 Add some missing 'static's.
Change-Id: Id76bb1e954e8fa36a11a38b5445c87f4a64af799
2015-05-05 18:26:10 -07:00
Dan Albert
1ba1d7c1ee Include the git sha in the adb version.
Also add --version to adbd to display the same thing.

Change-Id: I47dfbad16c892c42ea938aedd085ba77492791ba
2015-05-05 18:04:37 -07:00
Dan Albert
3f05fb5d97 Merge "Disable adb tests for Windows." 2015-05-05 22:11:01 +00:00
Dan Albert
a7a67c3079 Disable adb tests for Windows.
The tests will need some massaging before they're ready to go for
Windows, so just disable them to unblock people trying to mm in adb.

Change-Id: I67f2cd3af1a2444dea9cbb61c0553989442ba44b
2015-05-05 14:50:09 -07:00
Elliott Hughes
2e4a2eeaf3 _beginthread returns uintptr_t.
64-bit Windows is a thing, and we'll have to support it some day...

Change-Id: Ib9e2da1a5625e95a0ffadfee8501825dfd4f9594
2015-05-05 14:34:41 -07:00
Elliott Hughes
9b0f354fa2 Simplify adb_thread_create.
Change-Id: I36d6021ef8fbc23e8bcd4ddbe1dac0eba467cc70
2015-05-05 13:41:21 -07:00
Elliott Hughes
3bd73c12c0 Give enum types CamelCase names for clarity.
Change-Id: I1c89f1cc155ee839f372fb14d972a288183b8bcd
2015-05-05 13:10:43 -07:00
Elliott Hughes
32687beaf2 Remove non-functional "adb persist".
It isn't documented, it doesn't work, and it was only hacked into
"adb shell" anyway. (It's not a bad idea, though, but if we do it
we should do it properly.)

Change-Id: I930a5c6dd1d2850bfdf131f2e989ae04100f7db9
2015-05-05 12:50:26 -07:00
Elliott Hughes
f25752dcfa Merge "Implement the ssh(1) escaping rules." 2015-05-05 19:42:50 +00:00
Elliott Hughes
2b10111d25 Implement the ssh(1) escaping rules.
The first rule of ssh(1) escaping is that there is no escaping.

This doesn't undo any of my recent security fixes because they're all
calling escape_arg themselves.

This fixes "adb shell rm /data/dalvik-cache/arm/*".

Also remove do_cmd which caused concern during code review.

Bug: http://b/20564385
Change-Id: I4588fd949d51e2a50cff47ea171ed2d75f402d0d
2015-05-05 11:17:03 -07:00
Elliott Hughes
2e57163f53 Make test_track_devices.cpp output easier to read.
Change-Id: I2d85cdbe591a6ee9763e742805f281cb26d7b122
2015-05-04 15:51:50 -07:00
Elliott Hughes
ab52c181fa Add WriteFdFmt and clean up more code.
Also say *which* device wasn't found.

Bug: http://b/20666660
Change-Id: I50e234ad89e39ae0a8995083c0b642c61275c5a3
2015-05-01 17:36:46 -07:00
Elliott Hughes
e67f1f87d9 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
2015-05-01 15:55:37 -07:00
Elliott Hughes
6452a89aa8 More fixed-length buffer removal.
Bug: http://b/20666660
Change-Id: I0c738e9fed2defed48a9cf2d0a4f7b99c08dcf3d
2015-04-30 11:25:05 -07:00
Elliott Hughes
3ce9575af7 Add missing 'else' to fix all devices showing up as "host".
Bug: http://b/20705355
Change-Id: I4f7830278f0c2bc87d95d148d85455b8da894645
2015-04-29 22:37:25 -07:00
Elliott Hughes
1b600a902c Fix Win32 build.
Change-Id: Icf2c8df99b4b88bbf85a4097731733c5795fba44
2015-04-29 12:36:06 -07:00
Elliott Hughes
078f0fcf4c Move __adb_error to std::string, and improve various errors.
Also remove an sprintf. Also fix various bits of code that were
reporting stale adb_error values when they meant strerror.

Bug: http://b/20666660
Change-Id: Ibeb48b7bc21bb0ec30ba47889d1d671ee480e1b7
2015-04-29 11:28:37 -07:00
Elliott Hughes
8d5fa6da44 Remove strtok from adb.
Also fix android::base::Split to behave like Java, Python, and google3.

Change-Id: Ifbffd4e92950a79e7aea5d153c95fe0980648417
2015-04-27 19:42:20 -07:00
Elliott Hughes
9309ecbcec Support the full length of USB serial numbers.
Two bugs: we couldn't report the serial number correctly if it was long
enough, and it wasn't possible to connect to a device whose serial number
was long enough to overflow a different fixed-length buffer.

Bug: http://b/20317730
Change-Id: Ic9cf3c847066449ac78069bd1718184935098ac7
2015-04-27 14:52:17 -07:00
Elliott Hughes
ce6363bbbc Improve logging of USBDEVFS_CLAIMINTERFACE failures.
Bug: https://code.google.com/p/android/issues/detail?id=170054
Change-Id: I9b11eb019093e3322da0a8e70d6e17de4c25ab75
2015-04-25 14:44:23 -07:00
Elliott Hughes
876881b22a Merge "Add missing null checks after allocations." 2015-04-22 20:05:46 +00:00
Elliott Hughes
dc3b459ff9 Add missing null checks after allocations.
Bug: http://b/20317729
Change-Id: I62bb761d48ee59a1f4ddd0cdd0632432305ca2ca
2015-04-21 19:43:22 -07:00
Elliott Hughes
1555147bc4 Plumb more of the error reporting through.
This doesn't fix the bug, but it does flatten the bug to the well-known
and long-standing "adb shell" doesn't return exit statuses, so when we
fix that, this one will fix itself.

Bug: http://b/20423886
Change-Id: I48351e46f05dd3f2f6e57f0df1d851333458d0ef
2015-04-21 17:58:55 -07:00
Elliott Hughes
8e6edc0d89 Add a couple more adb shell regression tests.
Bug: http://b/15479704
Change-Id: Id3e7f0df101ad61db509df313c13210a8bd8b124
2015-04-21 16:25:54 -07:00
Badhri Jagan Sridharan
82b0f7ba92 Merge "adb: set sys.usb.ffs.ready to signal usb pullup" 2015-04-21 19:58:46 +00:00
Badhri Jagan Sridharan
5f97370bab adb: set sys.usb.ffs.ready to signal usb pullup
This change sets sys.usb.ffs.ready to 1 to
trigger configfs based enumeration.

Change-Id: I222495fc667cce59675579069d164b0b484f3653
2015-04-21 12:44:31 -07:00
Elliott Hughes
0053bb3f1a Add a test for shell escaping.
Until I fixed this, we would fail this example:

  $ adb shell sh -c 'echo hello; echo world'
  hello
  /system/bin/sh:  echo world: not found

Bug: http://b/19734868
Change-Id: I11a437cd0c0362303028f23fbaa103611b75707e
2015-04-21 12:15:31 -07:00
Elliott Hughes
d236d071b9 Fix "adb sync" for devices without vendor and oem.
Bug: http://b/20440110
Change-Id: I2481992198890f5ca50412c2b7ca361101961413
2015-04-21 10:17:07 -07:00
Elliott Hughes
e434ad1dd7 Merge "Always explain why bind(2) failed." 2015-04-21 16:52:21 +00:00
Elliott Hughes
14b65736c5 Merge "Use ' quoting to escape arguments." 2015-04-21 16:47:43 +00:00
Colin Cross
dc1e482b20 Fix windows adb build
libc++ is not available on windows yet, but it already defaults to
static libstdc++.

Change-Id: I85a766ead84f71fe1f2f59be6ac739b0b833b6db
2015-04-20 12:43:02 -07:00
Colin Cross
b2b06de5fc Merge "statically link adb and fastboot against libc++" 2015-04-20 18:05:29 +00:00
Elliott Hughes
7b506090e1 Always explain why bind(2) failed.
This has confused several people lately.

Bug: http://b/20219978
Change-Id: I2537ceb83bff0b3166c230c728d4389a983db858
2015-04-20 08:09:20 -07:00
Elliott Hughes
53daee6a2b Fix the Windows adb build.
It looks like we can't use clang on Windows yet because libc++ isn't ready.
So move back to GCC for the Windows host clang. Work around the mingw
printf format string problems that made us want to switch to clang in the
first place, and #include "sysdeps.h" in adb_utils.cpp to work around the
absence of lstat(2) on Windows.

Change-Id: Icd0797a8c0c2d1d326bdd704ba6bcafcbaeb742f
2015-04-19 13:17:01 -07:00
Elliott Hughes
5498adefb0 Use ' quoting to escape arguments.
The specific motivating case is "text;ls;1.apk", but rather than continue
adding individual characters to the list of characters to be escaped, let's
just switch to quote all arguments with ', which only leaves ' itself to be
escaped.

Bug: 20323053
Bug: 19734868
Change-Id: I8bd71db9373bc2d1169fc11e46c889da6638550a
2015-04-17 20:55:04 -07:00
Elliott Hughes
6c34bbaa68 Use escape_arg in "adb backup".
This doesn't fix the injection vulnerability, but it makes "adb backup"
no worse than the other commands, and lets me fix them all at once.

Bug: 20323053
Change-Id: I39843c065d9d738b6b7943b2ffd660e4a031cc36
2015-04-17 20:30:09 -07:00