|
|
|
@ -81,7 +81,7 @@ show_adb_installation_msg() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
static void
|
|
|
|
show_adb_err_msg(enum process_result err, const char *const argv[]) {
|
|
|
|
show_adb_err_msg(enum sc_process_result err, const char *const argv[]) {
|
|
|
|
#define MAX_COMMAND_STRING_LEN 1024
|
|
|
|
#define MAX_COMMAND_STRING_LEN 1024
|
|
|
|
char *buf = malloc(MAX_COMMAND_STRING_LEN);
|
|
|
|
char *buf = malloc(MAX_COMMAND_STRING_LEN);
|
|
|
|
if (!buf) {
|
|
|
|
if (!buf) {
|
|
|
|
@ -90,18 +90,18 @@ show_adb_err_msg(enum process_result err, const char *const argv[]) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
switch (err) {
|
|
|
|
switch (err) {
|
|
|
|
case PROCESS_ERROR_GENERIC:
|
|
|
|
case SC_PROCESS_ERROR_GENERIC:
|
|
|
|
argv_to_string(argv, buf, MAX_COMMAND_STRING_LEN);
|
|
|
|
argv_to_string(argv, buf, MAX_COMMAND_STRING_LEN);
|
|
|
|
LOGE("Failed to execute: %s", buf);
|
|
|
|
LOGE("Failed to execute: %s", buf);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case PROCESS_ERROR_MISSING_BINARY:
|
|
|
|
case SC_PROCESS_ERROR_MISSING_BINARY:
|
|
|
|
argv_to_string(argv, buf, MAX_COMMAND_STRING_LEN);
|
|
|
|
argv_to_string(argv, buf, MAX_COMMAND_STRING_LEN);
|
|
|
|
LOGE("Command not found: %s", buf);
|
|
|
|
LOGE("Command not found: %s", buf);
|
|
|
|
LOGE("(make 'adb' accessible from your PATH or define its full"
|
|
|
|
LOGE("(make 'adb' accessible from your PATH or define its full"
|
|
|
|
"path in the ADB environment variable)");
|
|
|
|
"path in the ADB environment variable)");
|
|
|
|
show_adb_installation_msg();
|
|
|
|
show_adb_installation_msg();
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case PROCESS_SUCCESS:
|
|
|
|
case SC_PROCESS_SUCCESS:
|
|
|
|
// do nothing
|
|
|
|
// do nothing
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -109,16 +109,15 @@ show_adb_err_msg(enum process_result err, const char *const argv[]) {
|
|
|
|
free(buf);
|
|
|
|
free(buf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
process_t
|
|
|
|
sc_pid
|
|
|
|
adb_execute_redirect(const char *serial, const char *const adb_cmd[],
|
|
|
|
adb_execute_p(const char *serial, const char *const adb_cmd[],
|
|
|
|
size_t len, pipe_t *pipe_stdin, pipe_t *pipe_stdout,
|
|
|
|
size_t len, sc_pipe *pin, sc_pipe *pout, sc_pipe *perr) {
|
|
|
|
pipe_t *pipe_stderr) {
|
|
|
|
|
|
|
|
int i;
|
|
|
|
int i;
|
|
|
|
process_t process;
|
|
|
|
sc_pid pid;
|
|
|
|
|
|
|
|
|
|
|
|
const char **argv = malloc((len + 4) * sizeof(*argv));
|
|
|
|
const char **argv = malloc((len + 4) * sizeof(*argv));
|
|
|
|
if (!argv) {
|
|
|
|
if (!argv) {
|
|
|
|
return PROCESS_NONE;
|
|
|
|
return SC_PROCESS_NONE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
argv[0] = get_adb_command();
|
|
|
|
argv[0] = get_adb_command();
|
|
|
|
@ -132,24 +131,23 @@ adb_execute_redirect(const char *serial, const char *const adb_cmd[],
|
|
|
|
|
|
|
|
|
|
|
|
memcpy(&argv[i], adb_cmd, len * sizeof(const char *));
|
|
|
|
memcpy(&argv[i], adb_cmd, len * sizeof(const char *));
|
|
|
|
argv[len + i] = NULL;
|
|
|
|
argv[len + i] = NULL;
|
|
|
|
enum process_result r =
|
|
|
|
enum sc_process_result r =
|
|
|
|
process_execute_redirect(argv, &process, pipe_stdin, pipe_stdout,
|
|
|
|
sc_process_execute_p(argv, &pid, pin, pout, perr);
|
|
|
|
pipe_stderr);
|
|
|
|
if (r != SC_PROCESS_SUCCESS) {
|
|
|
|
if (r != PROCESS_SUCCESS) {
|
|
|
|
|
|
|
|
show_adb_err_msg(r, argv);
|
|
|
|
show_adb_err_msg(r, argv);
|
|
|
|
process = PROCESS_NONE;
|
|
|
|
pid = SC_PROCESS_NONE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
free(argv);
|
|
|
|
free(argv);
|
|
|
|
return process;
|
|
|
|
return pid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
process_t
|
|
|
|
sc_pid
|
|
|
|
adb_execute(const char *serial, const char *const adb_cmd[], size_t len) {
|
|
|
|
adb_execute(const char *serial, const char *const adb_cmd[], size_t len) {
|
|
|
|
return adb_execute_redirect(serial, adb_cmd, len, NULL, NULL, NULL);
|
|
|
|
return adb_execute_p(serial, adb_cmd, len, NULL, NULL, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
process_t
|
|
|
|
sc_pid
|
|
|
|
adb_forward(const char *serial, uint16_t local_port,
|
|
|
|
adb_forward(const char *serial, uint16_t local_port,
|
|
|
|
const char *device_socket_name) {
|
|
|
|
const char *device_socket_name) {
|
|
|
|
char local[4 + 5 + 1]; // tcp:PORT
|
|
|
|
char local[4 + 5 + 1]; // tcp:PORT
|
|
|
|
@ -160,7 +158,7 @@ adb_forward(const char *serial, uint16_t local_port,
|
|
|
|
return adb_execute(serial, adb_cmd, ARRAY_LEN(adb_cmd));
|
|
|
|
return adb_execute(serial, adb_cmd, ARRAY_LEN(adb_cmd));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
process_t
|
|
|
|
sc_pid
|
|
|
|
adb_forward_remove(const char *serial, uint16_t local_port) {
|
|
|
|
adb_forward_remove(const char *serial, uint16_t local_port) {
|
|
|
|
char local[4 + 5 + 1]; // tcp:PORT
|
|
|
|
char local[4 + 5 + 1]; // tcp:PORT
|
|
|
|
sprintf(local, "tcp:%" PRIu16, local_port);
|
|
|
|
sprintf(local, "tcp:%" PRIu16, local_port);
|
|
|
|
@ -168,7 +166,7 @@ adb_forward_remove(const char *serial, uint16_t local_port) {
|
|
|
|
return adb_execute(serial, adb_cmd, ARRAY_LEN(adb_cmd));
|
|
|
|
return adb_execute(serial, adb_cmd, ARRAY_LEN(adb_cmd));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
process_t
|
|
|
|
sc_pid
|
|
|
|
adb_reverse(const char *serial, const char *device_socket_name,
|
|
|
|
adb_reverse(const char *serial, const char *device_socket_name,
|
|
|
|
uint16_t local_port) {
|
|
|
|
uint16_t local_port) {
|
|
|
|
char local[4 + 5 + 1]; // tcp:PORT
|
|
|
|
char local[4 + 5 + 1]; // tcp:PORT
|
|
|
|
@ -179,7 +177,7 @@ adb_reverse(const char *serial, const char *device_socket_name,
|
|
|
|
return adb_execute(serial, adb_cmd, ARRAY_LEN(adb_cmd));
|
|
|
|
return adb_execute(serial, adb_cmd, ARRAY_LEN(adb_cmd));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
process_t
|
|
|
|
sc_pid
|
|
|
|
adb_reverse_remove(const char *serial, const char *device_socket_name) {
|
|
|
|
adb_reverse_remove(const char *serial, const char *device_socket_name) {
|
|
|
|
char remote[108 + 14 + 1]; // localabstract:NAME
|
|
|
|
char remote[108 + 14 + 1]; // localabstract:NAME
|
|
|
|
snprintf(remote, sizeof(remote), "localabstract:%s", device_socket_name);
|
|
|
|
snprintf(remote, sizeof(remote), "localabstract:%s", device_socket_name);
|
|
|
|
@ -187,66 +185,65 @@ adb_reverse_remove(const char *serial, const char *device_socket_name) {
|
|
|
|
return adb_execute(serial, adb_cmd, ARRAY_LEN(adb_cmd));
|
|
|
|
return adb_execute(serial, adb_cmd, ARRAY_LEN(adb_cmd));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
process_t
|
|
|
|
sc_pid
|
|
|
|
adb_push(const char *serial, const char *local, const char *remote) {
|
|
|
|
adb_push(const char *serial, const char *local, const char *remote) {
|
|
|
|
#ifdef __WINDOWS__
|
|
|
|
#ifdef __WINDOWS__
|
|
|
|
// Windows will parse the string, so the paths must be quoted
|
|
|
|
// Windows will parse the string, so the paths must be quoted
|
|
|
|
// (see sys/win/command.c)
|
|
|
|
// (see sys/win/command.c)
|
|
|
|
local = strquote(local);
|
|
|
|
local = strquote(local);
|
|
|
|
if (!local) {
|
|
|
|
if (!local) {
|
|
|
|
return PROCESS_NONE;
|
|
|
|
return SC_PROCESS_NONE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
remote = strquote(remote);
|
|
|
|
remote = strquote(remote);
|
|
|
|
if (!remote) {
|
|
|
|
if (!remote) {
|
|
|
|
free((void *) local);
|
|
|
|
free((void *) local);
|
|
|
|
return PROCESS_NONE;
|
|
|
|
return SC_PROCESS_NONE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
const char *const adb_cmd[] = {"push", local, remote};
|
|
|
|
const char *const adb_cmd[] = {"push", local, remote};
|
|
|
|
process_t proc = adb_execute(serial, adb_cmd, ARRAY_LEN(adb_cmd));
|
|
|
|
sc_pid pid = adb_execute(serial, adb_cmd, ARRAY_LEN(adb_cmd));
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef __WINDOWS__
|
|
|
|
#ifdef __WINDOWS__
|
|
|
|
free((void *) remote);
|
|
|
|
free((void *) remote);
|
|
|
|
free((void *) local);
|
|
|
|
free((void *) local);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
return proc;
|
|
|
|
return pid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
process_t
|
|
|
|
sc_pid
|
|
|
|
adb_install(const char *serial, const char *local) {
|
|
|
|
adb_install(const char *serial, const char *local) {
|
|
|
|
#ifdef __WINDOWS__
|
|
|
|
#ifdef __WINDOWS__
|
|
|
|
// Windows will parse the string, so the local name must be quoted
|
|
|
|
// Windows will parse the string, so the local name must be quoted
|
|
|
|
// (see sys/win/command.c)
|
|
|
|
// (see sys/win/command.c)
|
|
|
|
local = strquote(local);
|
|
|
|
local = strquote(local);
|
|
|
|
if (!local) {
|
|
|
|
if (!local) {
|
|
|
|
return PROCESS_NONE;
|
|
|
|
return SC_PROCESS_NONE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
const char *const adb_cmd[] = {"install", "-r", local};
|
|
|
|
const char *const adb_cmd[] = {"install", "-r", local};
|
|
|
|
process_t proc = adb_execute(serial, adb_cmd, ARRAY_LEN(adb_cmd));
|
|
|
|
sc_pid pid = adb_execute(serial, adb_cmd, ARRAY_LEN(adb_cmd));
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef __WINDOWS__
|
|
|
|
#ifdef __WINDOWS__
|
|
|
|
free((void *) local);
|
|
|
|
free((void *) local);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
return proc;
|
|
|
|
return pid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static ssize_t
|
|
|
|
static ssize_t
|
|
|
|
adb_execute_for_output(const char *serial, const char *const adb_cmd[],
|
|
|
|
adb_execute_for_output(const char *serial, const char *const adb_cmd[],
|
|
|
|
size_t adb_cmd_len, char *buf, size_t buf_len,
|
|
|
|
size_t adb_cmd_len, char *buf, size_t buf_len,
|
|
|
|
const char *name) {
|
|
|
|
const char *name) {
|
|
|
|
pipe_t pipe_stdout;
|
|
|
|
sc_pipe pout;
|
|
|
|
process_t proc = adb_execute_redirect(serial, adb_cmd, adb_cmd_len, NULL,
|
|
|
|
sc_pid pid = adb_execute_p(serial, adb_cmd, adb_cmd_len, NULL, &pout, NULL);
|
|
|
|
&pipe_stdout, NULL);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ssize_t r = read_pipe_all(pipe_stdout, buf, buf_len);
|
|
|
|
ssize_t r = sc_pipe_read_all(pout, buf, buf_len);
|
|
|
|
close_pipe(pipe_stdout);
|
|
|
|
sc_pipe_close(pout);
|
|
|
|
|
|
|
|
|
|
|
|
if (!process_check_success(proc, name, true)) {
|
|
|
|
if (!sc_process_check_success(pid, name, true)) {
|
|
|
|
return -1;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|