Use $ANDROID_SERIAL if no selector is specified

Like adb, read the ANDROID_SERIAL environment variable to select a
device by serial if no explicit selection (-s, -d, -e or --tcpip=<addr>)
is provided via the command line.

Fixes #3111 <https://github.com/Genymobile/scrcpy/issues/3111>
PR #3113 <https://github.com/Genymobile/scrcpy/pull/3113>
This commit is contained in:
Romain Vimont 2022-03-14 12:29:33 +01:00
parent b1dbc30072
commit 4ce7af42c6
4 changed files with 21 additions and 1 deletions

View file

@ -448,6 +448,9 @@ scrcpy --serial 0123456789abcdef
scrcpy -s 0123456789abcdef # short version scrcpy -s 0123456789abcdef # short version
``` ```
The serial may also be provided via the environment variable `ANDROID_SERIAL`
(also used by `adb`).
If the device is connected over TCP/IP: If the device is connected over TCP/IP:
```bash ```bash

View file

@ -477,6 +477,10 @@ Push file to device (see \fB\-\-push\-target\fR)
.B ADB .B ADB
Path to adb. Path to adb.
.TP
.B ANDROID_SERIAL
Device serial to use if no selector (-s, -d, -e or --tcpip=<addr>) is specified.
.TP .TP
.B SCRCPY_ICON_PATH .B SCRCPY_ICON_PATH
Path to the program icon. Path to the program icon.

View file

@ -660,6 +660,11 @@ static const struct sc_envvar envvars[] = {
.name = "ADB", .name = "ADB",
.text = "Path to adb executable", .text = "Path to adb executable",
}, },
{
.name = "ANDROID_SERIAL",
.text = "Device serial to use if no selector (-s, -d, -e or "
"--tcpip=<addr>) is specified",
},
{ {
.name = "SCRCPY_ICON_PATH", .name = "SCRCPY_ICON_PATH",
.text = "Path to the program icon", .text = "Path to the program icon",

View file

@ -707,7 +707,15 @@ run_server(void *data) {
} else if (params->select_tcpip) { } else if (params->select_tcpip) {
selector.type = SC_ADB_DEVICE_SELECT_TCPIP; selector.type = SC_ADB_DEVICE_SELECT_TCPIP;
} else { } else {
selector.type = SC_ADB_DEVICE_SELECT_ALL; // No explicit selection, check $ANDROID_SERIAL
const char *env_serial = getenv("ANDROID_SERIAL");
if (env_serial) {
LOGI("Using ANDROID_SERIAL: %s", env_serial);
selector.type = SC_ADB_DEVICE_SELECT_SERIAL;
selector.serial = env_serial;
} else {
selector.type = SC_ADB_DEVICE_SELECT_ALL;
}
} }
struct sc_adb_device device; struct sc_adb_device device;
ok = sc_adb_select_device(&server->intr, &selector, 0, &device); ok = sc_adb_select_device(&server->intr, &selector, 0, &device);