Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
c3d45c8397 | |||
e56f2ac7a9 | |||
4ce7af42c6 | |||
b1dbc30072 |
@ -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
|
||||
|
@ -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.
|
||||
|
@ -473,9 +473,12 @@ sc_adb_accept_device(const struct sc_adb_device *device,
|
||||
}
|
||||
return !strcmp(selector->serial, device->serial);
|
||||
case SC_ADB_DEVICE_SELECT_USB:
|
||||
return !sc_adb_is_serial_tcpip(device->serial);
|
||||
return sc_adb_device_get_type(device->serial) ==
|
||||
SC_ADB_DEVICE_TYPE_USB;
|
||||
case SC_ADB_DEVICE_SELECT_TCPIP:
|
||||
return sc_adb_is_serial_tcpip(device->serial);
|
||||
// Both emulators and TCP/IP devices are selected via -e
|
||||
return sc_adb_device_get_type(device->serial) !=
|
||||
SC_ADB_DEVICE_TYPE_USB;
|
||||
default:
|
||||
assert(!"Missing SC_ADB_DEVICE_SELECT_* handling");
|
||||
break;
|
||||
@ -509,8 +512,10 @@ sc_adb_devices_log(enum sc_log_level level, struct sc_adb_device *devices,
|
||||
for (size_t i = 0; i < count; ++i) {
|
||||
struct sc_adb_device *d = &devices[i];
|
||||
const char *selection = d->selected ? "-->" : " ";
|
||||
const char *type = sc_adb_is_serial_tcpip(d->serial) ? "(tcpip)"
|
||||
: " (usb)";
|
||||
bool is_usb =
|
||||
sc_adb_device_get_type(d->serial) == SC_ADB_DEVICE_TYPE_USB;
|
||||
const char *type = is_usb ? " (usb)"
|
||||
: "(tcpip)";
|
||||
LOG(level, " %s %s %-20s %16s %s",
|
||||
selection, type, d->serial, d->state, d->model ? d->model : "");
|
||||
}
|
||||
@ -531,6 +536,8 @@ sc_adb_device_check_state(struct sc_adb_device *device,
|
||||
LOGE("A popup should open on the device to request authorization.");
|
||||
LOGE("Check the FAQ: "
|
||||
"<https://github.com/Genymobile/scrcpy/blob/master/FAQ.md>");
|
||||
} else {
|
||||
LOGE("Device could not be connected (state=%s)", state);
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -705,8 +712,3 @@ sc_adb_get_device_ip(struct sc_intr *intr, const char *serial, unsigned flags) {
|
||||
|
||||
return sc_adb_parse_device_ip_from_output(buf);
|
||||
}
|
||||
|
||||
bool
|
||||
sc_adb_is_serial_tcpip(const char *serial) {
|
||||
return strchr(serial, ':');
|
||||
}
|
||||
|
@ -114,13 +114,4 @@ sc_adb_getprop(struct sc_intr *intr, const char *serial, const char *prop,
|
||||
char *
|
||||
sc_adb_get_device_ip(struct sc_intr *intr, const char *serial, unsigned flags);
|
||||
|
||||
/**
|
||||
* Indicate if the serial represents an IP address
|
||||
*
|
||||
* In practice, it just returns true if and only if it contains a ':', which is
|
||||
* sufficient to distinguish an ip:port from a real USB serial.
|
||||
*/
|
||||
bool
|
||||
sc_adb_is_serial_tcpip(const char *serial);
|
||||
|
||||
#endif
|
||||
|
@ -25,3 +25,18 @@ sc_adb_devices_destroy(struct sc_vec_adb_devices *devices) {
|
||||
sc_vector_destroy(devices);
|
||||
}
|
||||
|
||||
enum sc_adb_device_type
|
||||
sc_adb_device_get_type(const char *serial) {
|
||||
// Starts with "emulator-"
|
||||
if (!strncmp(serial, "emulator-", sizeof("emulator-") - 1)) {
|
||||
return SC_ADB_DEVICE_TYPE_EMULATOR;
|
||||
}
|
||||
|
||||
// If the serial contains a ':', then it is a TCP/IP device (it is
|
||||
// sufficient to distinguish an ip:port from a real USB serial)
|
||||
if (strchr(serial, ':')) {
|
||||
return SC_ADB_DEVICE_TYPE_TCPIP;
|
||||
}
|
||||
|
||||
return SC_ADB_DEVICE_TYPE_USB;
|
||||
}
|
||||
|
@ -15,6 +15,12 @@ struct sc_adb_device {
|
||||
bool selected;
|
||||
};
|
||||
|
||||
enum sc_adb_device_type {
|
||||
SC_ADB_DEVICE_TYPE_USB,
|
||||
SC_ADB_DEVICE_TYPE_TCPIP,
|
||||
SC_ADB_DEVICE_TYPE_EMULATOR,
|
||||
};
|
||||
|
||||
struct sc_vec_adb_devices SC_VECTOR(struct sc_adb_device);
|
||||
|
||||
void
|
||||
@ -35,4 +41,10 @@ sc_adb_device_move(struct sc_adb_device *dst, struct sc_adb_device *src);
|
||||
void
|
||||
sc_adb_devices_destroy(struct sc_vec_adb_devices *devices);
|
||||
|
||||
/**
|
||||
* Deduce the device type from the serial
|
||||
*/
|
||||
enum sc_adb_device_type
|
||||
sc_adb_device_get_type(const char *serial);
|
||||
|
||||
#endif
|
||||
|
@ -80,6 +80,11 @@ struct sc_envvar {
|
||||
const char *text;
|
||||
};
|
||||
|
||||
struct sc_exit_status {
|
||||
unsigned value;
|
||||
const char *text;
|
||||
};
|
||||
|
||||
struct sc_getopt_adapter {
|
||||
char *optstring;
|
||||
struct option *longopts;
|
||||
@ -655,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",
|
||||
@ -662,7 +672,22 @@ static const struct sc_envvar envvars[] = {
|
||||
{
|
||||
.name = "SCRCPY_SERVER_PATH",
|
||||
.text = "Path to the server binary",
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
static const struct sc_exit_status exit_statuses[] = {
|
||||
{
|
||||
.value = 0,
|
||||
.text = "Normal program termination",
|
||||
},
|
||||
{
|
||||
.value = 1,
|
||||
.text = "Start failure",
|
||||
},
|
||||
{
|
||||
.value = 2,
|
||||
.text = "Device disconnected while running",
|
||||
},
|
||||
};
|
||||
|
||||
static char *
|
||||
@ -901,6 +926,25 @@ print_envvar(const struct sc_envvar *envvar, unsigned cols) {
|
||||
free(text);
|
||||
}
|
||||
|
||||
static void
|
||||
print_exit_status(const struct sc_exit_status *status, unsigned cols) {
|
||||
assert(cols > 8); // sc_str_wrap_lines() requires indent < columns
|
||||
assert(status->text);
|
||||
|
||||
// The text starts at 9: 4 ident spaces, 3 chars for numeric value, 2 spaces
|
||||
char *text = sc_str_wrap_lines(status->text, cols, 9);
|
||||
if (!text) {
|
||||
printf("<ERROR>\n");
|
||||
return;
|
||||
}
|
||||
|
||||
assert(strlen(text) >= 9); // Contains at least the initial identation
|
||||
|
||||
// text + 9 to remove the initial indentation
|
||||
printf(" %3d %s\n", status->value, text + 9);
|
||||
free(text);
|
||||
}
|
||||
|
||||
void
|
||||
scrcpy_print_usage(const char *arg0) {
|
||||
#define SC_TERM_COLS_DEFAULT 80
|
||||
@ -939,6 +983,11 @@ scrcpy_print_usage(const char *arg0) {
|
||||
for (size_t i = 0; i < ARRAY_LEN(envvars); ++i) {
|
||||
print_envvar(&envvars[i], cols);
|
||||
}
|
||||
|
||||
printf("\nExit status:\n\n");
|
||||
for (size_t i = 0; i < ARRAY_LEN(exit_statuses); ++i) {
|
||||
print_exit_status(&exit_statuses[i], cols);
|
||||
}
|
||||
}
|
||||
|
||||
static bool
|
||||
|
@ -649,7 +649,8 @@ sc_server_configure_tcpip_known_address(struct sc_server *server,
|
||||
static bool
|
||||
sc_server_configure_tcpip_unknown_address(struct sc_server *server,
|
||||
const char *serial) {
|
||||
bool is_already_tcpip = sc_adb_is_serial_tcpip(serial);
|
||||
bool is_already_tcpip =
|
||||
sc_adb_device_get_type(serial) == SC_ADB_DEVICE_TYPE_TCPIP;
|
||||
if (is_already_tcpip) {
|
||||
// Nothing to do
|
||||
LOGI("Device already connected via TCP/IP: %s", serial);
|
||||
@ -707,7 +708,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);
|
||||
|
Reference in New Issue
Block a user