From 61f9f737ab686a69571b875c106841e6ff4a9ca7 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Mon, 14 Mar 2022 12:29:33 +0100 Subject: [PATCH] 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=) is provided via the command line. Fixes #3111 --- app/scrcpy.1 | 4 ++++ app/src/cli.c | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/app/scrcpy.1 b/app/scrcpy.1 index f1ee732d0a..eb16447502 100644 --- a/app/scrcpy.1 +++ b/app/scrcpy.1 @@ -477,6 +477,10 @@ Push file to device (see \fB\-\-push\-target\fR) .B ADB Path to adb. +.TP +.B ANDROID_SERIAL +Device serial to use if no selector (-s, -d, -e or --tcpip=) is specified. + .TP .B SCRCPY_ICON_PATH Path to the program icon. diff --git a/app/src/cli.c b/app/src/cli.c index bde5eb007f..1f61e4bf4c 100644 --- a/app/src/cli.c +++ b/app/src/cli.c @@ -660,6 +660,11 @@ static const struct sc_envvar envvars[] = { .name = "ADB", .text = "Path to adb executable", }, + { + .name = "ANDROID_SERIAL", + .text = "Device serial to use if no selector (-s, -d, -e or " + "--tcpip=) is specified", + }, { .name = "SCRCPY_ICON_PATH", .text = "Path to the program icon", @@ -1651,6 +1656,14 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[], return false; } + if (selectors == 0) { + const char *env_serial = getenv("ANDROID_SERIAL"); + if (env_serial) { + LOGI("Using ANDROID_SERIAL: %s", env_serial); + opts->serial = env_serial; + } + } + #ifdef HAVE_V4L2 if (!opts->display && !opts->record_filename && !opts->v4l2_device) { LOGE("-N/--no-display requires either screen recording (-r/--record)"