Use new user-friendly adb API

Replace the adb_exec_*() calls by the new adb functions to simplify.
This commit is contained in:
Romain Vimont 2021-11-18 22:11:19 +01:00
parent b7559744a7
commit ce225f019a
3 changed files with 12 additions and 50 deletions

View file

@ -12,30 +12,24 @@
static bool
enable_tunnel_reverse(struct sc_intr *intr, const char *serial,
uint16_t local_port) {
sc_pid pid = adb_exec_reverse(serial, SC_SOCKET_NAME, local_port);
return sc_process_check_success_intr(intr, pid, "adb reverse", true);
return adb_reverse(intr, serial, SC_SOCKET_NAME, local_port);
}
static bool
disable_tunnel_reverse(struct sc_intr *intr, const char *serial) {
sc_pid pid = adb_exec_reverse_remove(serial, SC_SOCKET_NAME);
return sc_process_check_success_intr(intr, pid, "adb reverse --remove",
true);
return adb_reverse_remove(intr, serial, SC_SOCKET_NAME);
}
static bool
enable_tunnel_forward(struct sc_intr *intr, const char *serial,
uint16_t local_port) {
sc_pid pid = adb_exec_forward(serial, local_port, SC_SOCKET_NAME);
return sc_process_check_success_intr(intr, pid, "adb forward", true);
return adb_forward(intr, serial, local_port, SC_SOCKET_NAME);
}
static bool
disable_tunnel_forward(struct sc_intr *intr, const char *serial,
uint16_t local_port) {
sc_pid pid = adb_exec_forward_remove(serial, local_port);
return sc_process_check_success_intr(intr, pid, "adb forward --remove",
true);
return adb_forward_remove(intr, serial, local_port);
}
static bool

View file

@ -126,33 +126,24 @@ run_file_handler(void *data) {
(void) non_empty;
sc_mutex_unlock(&file_handler->mutex);
sc_pid pid;
if (req.action == ACTION_INSTALL_APK) {
LOGI("Installing %s...", req.file);
pid = adb_exec_install(serial, req.file);
} else {
LOGI("Pushing %s...", req.file);
pid = adb_exec_push(serial, req.file, push_target);
}
if (req.action == ACTION_INSTALL_APK) {
if (sc_process_check_success_intr(intr, pid, "adb install",
false)) {
bool ok = adb_install(intr, serial, req.file);
if (ok) {
LOGI("%s successfully installed", req.file);
} else {
LOGE("Failed to install %s", req.file);
}
} else {
if (sc_process_check_success_intr(intr, pid, "adb push", false)) {
LOGI("Pushing %s...", req.file);
bool ok = adb_push(intr, serial, req.file, push_target);
if (ok) {
LOGI("%s successfully pushed to %s", req.file, push_target);
} else {
LOGE("Failed to push %s to %s", req.file, push_target);
}
}
// Close the process (it is necessarily already terminated)
sc_process_close(pid);
file_handler_request_destroy(&req);
}
return 0;

View file

@ -112,9 +112,9 @@ push_server(struct sc_intr *intr, const char *serial) {
free(server_path);
return false;
}
sc_pid pid = adb_exec_push(serial, server_path, SC_DEVICE_SERVER_PATH);
bool ok = adb_push(intr, serial, server_path, SC_DEVICE_SERVER_PATH);
free(server_path);
return sc_process_check_success_intr(intr, pid, "adb push", true);
return ok;
}
static const char *
@ -422,29 +422,6 @@ sc_server_on_terminated(void *userdata) {
LOGD("Server terminated");
}
static char *
sc_server_get_serialno(struct sc_intr *intr) {
sc_pipe pout;
sc_pid pid = adb_exec_get_serialno(&pout);
if (pid == SC_PROCESS_NONE) {
return false;
}
char buf[128];
ssize_t r = sc_pipe_read_all_intr(intr, pid, pout, buf, sizeof(buf));
sc_pipe_close(pout);
bool ok =
sc_process_check_success_intr(intr, pid, "adb get-serialno", true);
if (!ok) {
return NULL;
}
sc_str_truncate(buf, r, " \r\n");
return strdup(buf);
}
static bool
sc_server_fill_serial(struct sc_server *server) {
// Retrieve the actual device immediately if not provided, so that all
@ -453,7 +430,7 @@ sc_server_fill_serial(struct sc_server *server) {
// device/emulator" error)
if (!server->params.serial) {
// The serial is owned by sc_server_params, and will be freed on destroy
server->params.serial = sc_server_get_serialno(&server->intr);
server->params.serial = adb_get_serialno(&server->intr);
if (!server->params.serial) {
LOGE("Could not get device serial");
return false;