Display and control your Android device
Make the server unlink itself
Romain Vimont39c5e7160567
diff --git a/app/src/command.c b/app/src/command.cindex b5bb9572..b8340ecc 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.hindex 3e0fcca6..98b3a881 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, uint16process_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 namediff --git a/app/src/server.c b/app/src/server.cindex 31bf64de..7835e716 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 anymoredisable_tunnel(server); // ignore failureserver->tunnel_enabled = SDL_FALSE;@@ -254,10 +243,6 @@ void server_stop(struct server *server) {// ignore failuredisable_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.hindex 19594c03..b9835e13 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 valuesdiff --git a/server/src/main/java/com/genymobile/scrcpy/Server.java b/server/src/main/java/com/genymobile/scrcpy/Server.javaindex 0dabb69f..fb2ba461 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 @@ package com.genymobile.scrcpy;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 @@ public final class Server {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 final class Server {}});+ unlinkSelf();Options options = createOptions(args);scrcpy(options);}