Commit graph

28 commits

Author SHA1 Message Date
Romain Vimont
396e4bd925 Add missing LOG_OOM() on malloc failure 2022-07-19 12:15:06 +02:00
Romain Vimont
b1d8c72780 Rename function to simplify
For consistency with sc_adb_parse_device(), do not include "from_output"
in the function name.
2022-06-09 15:02:42 +02:00
Romain Vimont
c3d45c8397 Consider emulators as TCP/IP devices
Emulators were wrongly considered as USB devices, so they were selected
using -d instead of -e (which was inconsistent with the adb behavior).

Refs #3005 <https://github.com/Genymobile/scrcpy/issues/3005>
Refs #3137 <https://github.com/Genymobile/scrcpy/issues/3137>
2022-03-22 21:08:08 +01:00
Romain Vimont
e56f2ac7a9 Log an error on unexpected device state
Refs #3129 <https://github.com/Genymobile/scrcpy/issues/3129>
2022-03-20 14:56:52 +01:00
Romain Vimont
e2e76c5d48 Increase adb devices -l max output size
For simplicity, the parsing of `adb devices -l` output is performed in a
single pass on the whole output.

This output was limited to 4096 bytes. Since there are about 100 chars
per device line, this limited the number of connected devices to ~40.

Increase to 65536 bytes to avoid a limitation in practice.

PR #3035 <https://github.com/Genymobile/scrcpy/pull/3035>
2022-02-21 00:03:45 +01:00
Romain Vimont
4b8cb042c4 Use vector for listing ADB devices
This avoids the hardcoded maximum number of ADB devices detected (16).

Refs #3029 <https://github.com/Genymobile/scrcpy/pull/3029>
PR #3035 <https://github.com/Genymobile/scrcpy/pull/3035>

Co-authored-by: Daniel Ansorregui <d.ansorregui@samsung.com>
2022-02-20 23:59:35 +01:00
Romain Vimont
25296ae167 Kill adb daemon in OTG mode on Windows
On Windows, it is not possible to open a USB device from several
process, so HID events may only work if no adb daemon is running.

PR #3011 <https://github.com/Genymobile/scrcpy/pull/3011>
2022-02-20 17:39:39 +01:00
Romain Vimont
3bb24b3926 Make intr optional for adb commands
All adb commands are executed with an "interruptor", so that they can be
interrupted on Ctrl+C.

Make this interruptor optional, so that we could call "adb kill-server"
in OTG mode. This command always returns almost immediately anyway.

Ideally, we should make all blocking calls interruptible (including
libusb calls, by using the asynchronous API), but it's a lot of work,
and in practice it works well enough.

PR #3011 <https://github.com/Genymobile/scrcpy/pull/3011>
2022-02-20 17:39:36 +01:00
Romain Vimont
c4ab65eb79 Remove useless '\n' in log 2022-02-18 21:18:36 +01:00
Romain Vimont
582161607e Add option to select USB or TCP/IP devices
If several devices are connected (as listed by `adb devices`), it was
necessary to provide the explicit serial via -s/--serial.

If only one device is connected via USB (respectively, via TCP/IP), it
might be convenient to select it automatically. For this purpose, two
new options are introduced:
 - -d/--select-usb: select the single device connected over USB
 - -e/--select-tcpip: select the single device connected over TCP/IP

PR #3005 <https://github.com/Genymobile/scrcpy/pull/3005>
2022-02-09 10:00:25 +01:00
Romain Vimont
146f65d7b2 Introduce adb device selector
Currently, a device is selected either from a specific serial, or if it
is the only one connected.

In order to support selecting the only device connected via USB or via
TCP/IP separately, introduce a new selection structure.

PR #3005 <https://github.com/Genymobile/scrcpy/pull/3005>
2022-02-09 10:00:25 +01:00
Romain Vimont
5ed13ef477 Execute adb start-server
This does nothing if the adb daemon is already started, but allows to
print any output/errors to the console.

Otherwise, the daemon starting would occur during `adb devices`, which
does not output to the console because the result is parsed.

PR #3005 <https://github.com/Genymobile/scrcpy/pull/3005>
2022-02-09 10:00:14 +01:00
Romain Vimont
9c545e8c29 Remove sc_adb_get_serialno()
The device serial is now retrieved from `adb devices -l`, `adb
get-serialno` is not called anymore.

PR #3005 <https://github.com/Genymobile/scrcpy/pull/3005>
2022-02-09 09:56:26 +01:00
Romain Vimont
0a619dc9ef Allow selecting a device from IP without port
Since the previous commit, if a serial is given via -s/--serial (either
a real USB serial or an IP:port), a device is selected if its serial
matches exactly.

In addition, if the user pass an IP without a port, then select any
device with this IP, regardless of the port (so that "192.168.1.1"
matches any "192.168.1.1:port"). This is also the default behavior of
adb.

PR #3005 <https://github.com/Genymobile/scrcpy/pull/3005>
2022-02-09 09:56:26 +01:00
Romain Vimont
4692d13179 Expose simple API to select a single adb device
Select an adb device from the output of `adb device -l`.

PR #3005 <https://github.com/Genymobile/scrcpy/pull/3005>
2022-02-09 09:56:26 +01:00
Romain Vimont
02d46b2262 Expose function to test if a serial is TCP/IP
In practice, it just tests if the serial contains a ':', which is
sufficient to distinguish ip:port from a real USB serial.

PR #3005 <https://github.com/Genymobile/scrcpy/pull/3005>
2022-02-09 09:56:25 +01:00
Romain Vimont
6d41c53b61 Fix adb connect parsing
The function assumed that the raw output of "adb connect" was a
NUL-terminated string, but it is not the case.

It this output did not end with a space or a new line character, then
sc_str_truncate() would write '\0' over the last character. Even worse,
if the output was empty, then sc_str_truncate() would write
out-of-bounds.

Avoid the error-prone sc_str_truncate() util function.
2022-02-06 14:31:32 +01:00
Romain Vimont
8d540e83c7 Fix adb get-serialno parsing
The function assumed that the raw output of "adb get-serialno" was a
NUL-terminated string, but it is not the case.

It this output did not end with a space or a new line character, then
sc_str_truncate() would write '\0' over the last character. Even worse,
if the output was empty, then sc_str_truncate() would write
out-of-bounds.

Avoid the error-prone sc_str_truncate() util function.
2022-02-06 14:30:19 +01:00
Romain Vimont
2ea12f73db Fix adb getprop parsing
The function assumed that the raw output of "adb getprop" was a
NUL-terminated string, but it is not the case.

It this output did not end with a space or a new line character, then
sc_str_truncate() would write '\0' over the last character. Even worse,
if the output was empty, then sc_str_truncate() would write
out-of-bounds.

Avoid the error-prone sc_str_truncate() util function.
2022-02-06 14:30:13 +01:00
Romain Vimont
5d6bd8f9cd Fix adb device ip parsing
The parser assumed that its input was a NUL-terminated string, but it
was not the case: it is just the raw output of "adb devices ip route".

In practice, it was harmless, since the output always ended with '\n'
(which was replaced by '\0' on truncation), but it was incorrect
nonetheless.

Always write a '\0' at the end of the buffer, and explicitly parse as a
NUL-terminated string. For that purpose, avoid the error-prone
sc_str_truncate() util function.
2022-02-06 14:30:07 +01:00
Romain Vimont
386cf7d7ac Build adb argv statically
Now that providing a serial is mandatory for adb commands where it is
relevant, the whole argv array may be built statically, without
allocations at runtime.
2022-02-05 10:56:58 +01:00
Romain Vimont
5e2bfccab4 Expose adb executable path publicly
This will allow the caller to build the argv array directly.
2022-02-05 10:56:58 +01:00
Romain Vimont
ba30ca5c1e Rename adb_command to adb_executable
Semantically, a "command" refers to the whole command line argv (adb and
its arguments).
2022-02-05 10:56:58 +01:00
Romain Vimont
028e7afe32 Assert non-NULL serial
If no serial is passed, then the command would work if there is exactly
one device connected, but will fail with multiple devices.

To avoid such cases, ensure that a serial is always provided.
2022-02-05 10:56:58 +01:00
Romain Vimont
6ca9825c0f Assert "adb disconnect" is called with an argument
Calling "adb disconnect" without argument would disconnect every TCP/IP
device. We must make sure scrcpy never does that.
2022-02-05 10:56:21 +01:00
Romain Vimont
bd3c93ae3d Remove platform-tools installation suggestion
On Windows, adb is provided in the release archive. Most missing adb
issues come from users setting the ADB environment variable to an
incorrect value (on all platforms).

Suggesting to install platform-tools to solve the problem will just make
things worse (there will be one more adb in yet another location).
2022-02-04 08:39:10 +01:00
Romain Vimont
9e3902f30c Use sc_ prefix for adb 2022-02-04 08:39:10 +01:00
Romain Vimont
7810ca61b0 Move ADB code to adb/ 2022-02-04 08:39:10 +01:00
Renamed from app/src/adb.c (Browse further)