Execute adb start-server

This does nothing if the adb daemon is already started, but allows to
print any output/errors to the console.

Otherwise, the daemon starting would occur during `adb devices`, which
does not output to the console because the result is parsed.

PR #3005 <https://github.com/Genymobile/scrcpy/pull/3005>
This commit is contained in:
Romain Vimont 2022-02-06 15:28:23 +01:00
parent 9c545e8c29
commit 5ed13ef477
3 changed files with 20 additions and 1 deletions

View file

@ -194,6 +194,14 @@ sc_adb_execute(const char *const argv[], unsigned flags) {
return sc_adb_execute_p(argv, flags, NULL); return sc_adb_execute_p(argv, flags, NULL);
} }
bool
sc_adb_start_server(struct sc_intr *intr, unsigned flags) {
const char *const argv[] = SC_ADB_COMMAND("start-server");
sc_pid pid = sc_adb_execute(argv, flags);
return process_check_success_intr(intr, pid, "adb start-server", flags);
}
bool bool
sc_adb_forward(struct sc_intr *intr, const char *serial, uint16_t local_port, sc_adb_forward(struct sc_intr *intr, const char *serial, uint16_t local_port,
const char *device_socket_name, unsigned flags) { const char *device_socket_name, unsigned flags) {

View file

@ -21,6 +21,9 @@ sc_adb_get_executable(void);
sc_pid sc_pid
sc_adb_execute(const char *const argv[], unsigned flags); sc_adb_execute(const char *const argv[], unsigned flags);
bool
sc_adb_start_server(struct sc_intr *intr, unsigned flags);
bool bool
sc_adb_forward(struct sc_intr *intr, const char *serial, uint16_t local_port, sc_adb_forward(struct sc_intr *intr, const char *serial, uint16_t local_port,
const char *device_socket_name, unsigned flags); const char *device_socket_name, unsigned flags);

View file

@ -665,6 +665,15 @@ run_server(void *data) {
const struct sc_server_params *params = &server->params; const struct sc_server_params *params = &server->params;
// Execute "adb start-server" before "adb devices" so that daemon starting
// output/errors is correctly printed in the console ("adb devices" output
// is parsed, so it is not output)
bool ok = sc_adb_start_server(&server->intr, 0);
if (!ok) {
LOGE("Could not start adb daemon");
goto error_connection_failed;
}
// params->tcpip_dst implies params->tcpip // params->tcpip_dst implies params->tcpip
assert(!params->tcpip_dst || params->tcpip); assert(!params->tcpip_dst || params->tcpip);
@ -677,7 +686,6 @@ run_server(void *data) {
// exist, and scrcpy will execute "adb connect"). // exist, and scrcpy will execute "adb connect").
bool need_initial_serial = !params->tcpip_dst; bool need_initial_serial = !params->tcpip_dst;
bool ok;
if (need_initial_serial) { if (need_initial_serial) {
struct sc_adb_device device; struct sc_adb_device device;
ok = sc_adb_select_device(&server->intr, params->req_serial, 0, ok = sc_adb_select_device(&server->intr, params->req_serial, 0,