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>
PR #3113 <#3113>
  • Loading branch information
rom1v committed Mar 15, 2022
1 parent b1dbc30 commit 4ce7af4
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,9 @@ scrcpy --serial 0123456789abcdef
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:

```bash
Expand Down
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
5 changes: 5 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
10 changes: 9 additions & 1 deletion app/src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,15 @@ run_server(void *data) {
} else if (params->select_tcpip) {
selector.type = SC_ADB_DEVICE_SELECT_TCPIP;
} 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;
ok = sc_adb_select_device(&server->intr, &selector, 0, &device);
Expand Down

0 comments on commit 4ce7af4

Please sign in to comment.