Skip to content

Commit

Permalink
Use $ANDROID_SERIAL if no selector is specified
Browse files Browse the repository at this point in the history
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 <#3111>
  • Loading branch information
rom1v committed Mar 14, 2022
1 parent b1dbc30 commit 61f9f73
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/scrcpy.1
Original file line number Diff line number Diff line change
Expand Up @@ -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=<addr>) is specified.

.TP
.B SCRCPY_ICON_PATH
Path to the program icon.
Expand Down
13 changes: 13 additions & 0 deletions app/src/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -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=<addr>) is specified",
},
{
.name = "SCRCPY_ICON_PATH",
.text = "Path to the program icon",
Expand Down Expand Up @@ -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)"
Expand Down

0 comments on commit 61f9f73

Please sign in to comment.