diff --git a/app/src/command.c b/app/src/command.c index b5bb957270..b8340ecc27 100644 --- a/app/src/command.c +++ b/app/src/command.c @@ -135,11 +135,6 @@ process_t adb_install(const char *serial, const char *local) { return proc; } -process_t adb_remove_path(const char *serial, const char *path) { - const char *const adb_cmd[] = {"shell", "rm", path}; - return adb_execute(serial, adb_cmd, ARRAY_LEN(adb_cmd)); -} - SDL_bool process_check_success(process_t proc, const char *name) { if (proc == PROCESS_NONE) { LOGE("Could not execute \"%s\"", name); diff --git a/app/src/command.h b/app/src/command.h index 3e0fcca699..98b3a88124 100644 --- a/app/src/command.h +++ b/app/src/command.h @@ -49,7 +49,6 @@ process_t adb_reverse(const char *serial, const char *device_socket_name, uint16 process_t adb_reverse_remove(const char *serial, const char *device_socket_name); process_t adb_push(const char *serial, const char *local, const char *remote); process_t adb_install(const char *serial, const char *local); -process_t adb_remove_path(const char *serial, const char *path); // convenience function to wait for a successful process execution // automatically log process errors with the provided process name diff --git a/app/src/server.c b/app/src/server.c index 31bf64de9c..7835e7162e 100644 --- a/app/src/server.c +++ b/app/src/server.c @@ -34,11 +34,6 @@ static SDL_bool push_server(const char *serial) { return process_check_success(process, "adb push"); } -static SDL_bool remove_server(const char *serial) { - process_t process = adb_remove_path(serial, DEVICE_SERVER_PATH); - return process_check_success(process, "adb shell rm"); -} - static SDL_bool enable_tunnel_reverse(const char *serial, Uint16 local_port) { process_t process = adb_reverse(serial, SOCKET_NAME, local_port); return process_check_success(process, "adb reverse"); @@ -167,8 +162,6 @@ SDL_bool server_start(struct server *server, const char *serial, return SDL_FALSE; } - server->server_copied_to_device = SDL_TRUE; - if (!enable_tunnel(server)) { SDL_free((void *) server->serial); return SDL_FALSE; @@ -229,10 +222,6 @@ socket_t server_connect_to(struct server *server) { close_socket(&server->server_socket); } - // the server is started, we can clean up the jar from the temporary folder - remove_server(server->serial); // ignore failure - server->server_copied_to_device = SDL_FALSE; - // we don't need the adb tunnel anymore disable_tunnel(server); // ignore failure server->tunnel_enabled = SDL_FALSE; @@ -254,10 +243,6 @@ void server_stop(struct server *server) { // ignore failure disable_tunnel(server); } - - if (server->server_copied_to_device) { - remove_server(server->serial); // ignore failure - } } void server_destroy(struct server *server) { diff --git a/app/src/server.h b/app/src/server.h index 19594c03e6..b9835e1382 100644 --- a/app/src/server.h +++ b/app/src/server.h @@ -13,7 +13,6 @@ struct server { SDL_bool tunnel_enabled; SDL_bool tunnel_forward; // use "adb forward" instead of "adb reverse" SDL_bool send_frame_meta; // request frame PTS to be able to record properly - SDL_bool server_copied_to_device; }; #define SERVER_INITIALIZER { \ @@ -25,7 +24,6 @@ struct server { .tunnel_enabled = SDL_FALSE, \ .tunnel_forward = SDL_FALSE, \ .send_frame_meta = SDL_FALSE, \ - .server_copied_to_device = SDL_FALSE, \ } // init default values diff --git a/server/src/main/java/com/genymobile/scrcpy/Server.java b/server/src/main/java/com/genymobile/scrcpy/Server.java index 0dabb69fa3..fb2ba461ec 100644 --- a/server/src/main/java/com/genymobile/scrcpy/Server.java +++ b/server/src/main/java/com/genymobile/scrcpy/Server.java @@ -2,11 +2,14 @@ import android.graphics.Rect; +import java.io.File; import java.io.IOException; import java.util.Arrays; public final class Server { + private static final String SERVER_PATH = "/data/local/tmp/scrcpy-server.jar"; + private Server() { // not instantiable } @@ -86,6 +89,14 @@ private static Rect parseCrop(String crop) { return new Rect(x, y, x + width, y + height); } + private static void unlinkSelf() { + try { + new File(SERVER_PATH).delete(); + } catch (Exception e) { + Ln.e("Cannot unlink server", e); + } + } + public static void main(String... args) throws Exception { Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { @Override @@ -94,6 +105,7 @@ public void uncaughtException(Thread t, Throwable e) { } }); + unlinkSelf(); Options options = createOptions(args); scrcpy(options); }