2018-01-22 10:22:31 +00:00
|
|
|
#include "command.h"
|
|
|
|
|
|
|
|
#include <SDL2/SDL_log.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
2018-01-23 14:46:34 +00:00
|
|
|
#define SOCKET_NAME "scrcpy"
|
|
|
|
|
|
|
|
process_t push_server(const char *serial) {
|
2018-01-29 16:06:44 +00:00
|
|
|
const char *apk_path = getenv("SCRCPY_APK");
|
|
|
|
if (!apk_path) {
|
|
|
|
apk_path = "scrcpy.apk";
|
2018-01-23 14:46:34 +00:00
|
|
|
}
|
2018-01-29 16:06:44 +00:00
|
|
|
return adb_push(serial, apk_path, "/data/local/tmp/");
|
2018-01-23 14:46:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
process_t enable_tunnel(const char *serial, Uint16 local_port) {
|
|
|
|
return adb_reverse(serial, SOCKET_NAME, local_port);
|
|
|
|
}
|
|
|
|
|
|
|
|
process_t disable_tunnel(const char *serial) {
|
|
|
|
return adb_reverse_remove(serial, SOCKET_NAME);
|
|
|
|
}
|
|
|
|
|
2018-01-29 14:40:33 +00:00
|
|
|
process_t start_server(const char *serial, Uint16 maximum_size) {
|
|
|
|
char maximum_size_string[6];
|
|
|
|
sprintf(maximum_size_string, "%d", maximum_size);
|
2018-01-22 10:22:31 +00:00
|
|
|
const char *const cmd[] = {
|
|
|
|
"shell",
|
2018-01-29 16:06:44 +00:00
|
|
|
"CLASSPATH=/data/local/tmp/scrcpy.apk",
|
2018-01-22 10:22:31 +00:00
|
|
|
"app_process",
|
2018-01-29 16:06:44 +00:00
|
|
|
"/", // unused
|
2018-01-29 14:40:33 +00:00
|
|
|
"com.genymobile.scrcpy.ScrCpyServer",
|
|
|
|
maximum_size_string,
|
2018-01-22 10:22:31 +00:00
|
|
|
};
|
|
|
|
return adb_execute(serial, cmd, sizeof(cmd) / sizeof(cmd[0]));
|
|
|
|
}
|
|
|
|
|
|
|
|
void stop_server(process_t server) {
|
|
|
|
if (!cmd_terminate(server)) {
|
|
|
|
SDL_LogError(SDL_LOG_CATEGORY_SYSTEM, "Could not terminate server: %s", strerror(errno));
|
|
|
|
}
|
|
|
|
}
|