Display and control your Android device
Use $ANDROID_SERIAL if no selector is specified
Romain Vimont4ce7af42c635
diff --git a/README.md b/README.mdindex c89b0c8d..614d1ed4 100644--- a/README.md+++ b/README.md@@ -448,6 +448,9 @@ scrcpy --serial 0123456789abcdefscrcpy -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:```bashdiff --git a/app/scrcpy.1 b/app/scrcpy.1index f1ee732d..eb164475 100644--- a/app/scrcpy.1+++ b/app/scrcpy.1@@ -477,6 +477,10 @@ Push file to device (see \fB\-\-push\-target\fR).B ADBPath 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_PATHPath to the program icon.diff --git a/app/src/cli.c b/app/src/cli.cindex bde5eb00..5dda86e5 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=<addr>) is specified",+ },{.name = "SCRCPY_ICON_PATH",.text = "Path to the program icon",diff --git a/app/src/server.c b/app/src/server.cindex c12b03d4..6b61924b 100644--- a/app/src/server.c+++ b/app/src/server.c@@ -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);