Use a different server path for each session
When scrcpy is run, a server is pushed to /data/local/tmp/scrcpy-server.jar. Running simultaneous scrcpy instances on the same device was not a problem, because the file was unlinked (removed) almost immediately once it started, avoiding any conflicts. In order to support executing new process using the scrcpy-server.jar at any time (to change the display power mode from a separate process), the server file must not be unlinked, so using different names are necessary to avoid conflicts. Reuse the scid mechanism already used for generating device socket names. Refs4315be1648Refs439a1fd4ed
This commit is contained in:
@@ -18,7 +18,6 @@
|
|||||||
#define SC_SERVER_FILENAME "scrcpy-server"
|
#define SC_SERVER_FILENAME "scrcpy-server"
|
||||||
|
|
||||||
#define SC_SERVER_PATH_DEFAULT PREFIX "/share/scrcpy/" SC_SERVER_FILENAME
|
#define SC_SERVER_PATH_DEFAULT PREFIX "/share/scrcpy/" SC_SERVER_FILENAME
|
||||||
#define SC_DEVICE_SERVER_PATH "/data/local/tmp/scrcpy-server.jar"
|
|
||||||
|
|
||||||
#define SC_ADB_PORT_DEFAULT 5555
|
#define SC_ADB_PORT_DEFAULT 5555
|
||||||
#define SC_SOCKET_NAME_PREFIX "scrcpy_"
|
#define SC_SOCKET_NAME_PREFIX "scrcpy_"
|
||||||
@@ -117,7 +116,7 @@ error:
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
push_server(struct sc_intr *intr, const char *serial) {
|
push_server(struct sc_intr *intr, uint32_t scid, const char *serial) {
|
||||||
char *server_path = get_server_path();
|
char *server_path = get_server_path();
|
||||||
if (!server_path) {
|
if (!server_path) {
|
||||||
return false;
|
return false;
|
||||||
@@ -127,7 +126,16 @@ push_server(struct sc_intr *intr, const char *serial) {
|
|||||||
free(server_path);
|
free(server_path);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
bool ok = sc_adb_push(intr, serial, server_path, SC_DEVICE_SERVER_PATH, 0);
|
|
||||||
|
char *device_server_path;
|
||||||
|
if (asprintf(&device_server_path, "/data/local/tmp/scrcpy-server-%08x.jar",
|
||||||
|
scid) == -1) {
|
||||||
|
LOG_OOM();
|
||||||
|
free(server_path);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
bool ok = sc_adb_push(intr, serial, server_path, device_server_path, 0);
|
||||||
|
free(device_server_path);
|
||||||
free(server_path);
|
free(server_path);
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
@@ -209,13 +217,20 @@ execute_server(struct sc_server *server,
|
|||||||
const char *serial = server->serial;
|
const char *serial = server->serial;
|
||||||
assert(serial);
|
assert(serial);
|
||||||
|
|
||||||
|
char *classpath;
|
||||||
|
if (asprintf(&classpath, "CLASSPATH=/data/local/tmp/scrcpy-server-%08x.jar",
|
||||||
|
params->scid) == -1) {
|
||||||
|
LOG_OOM();
|
||||||
|
return SC_PROCESS_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
const char *cmd[128];
|
const char *cmd[128];
|
||||||
unsigned count = 0;
|
unsigned count = 0;
|
||||||
cmd[count++] = sc_adb_get_executable();
|
cmd[count++] = sc_adb_get_executable();
|
||||||
cmd[count++] = "-s";
|
cmd[count++] = "-s";
|
||||||
cmd[count++] = serial;
|
cmd[count++] = serial;
|
||||||
cmd[count++] = "shell";
|
cmd[count++] = "shell";
|
||||||
cmd[count++] = "CLASSPATH=" SC_DEVICE_SERVER_PATH;
|
cmd[count++] = classpath;
|
||||||
cmd[count++] = "app_process";
|
cmd[count++] = "app_process";
|
||||||
|
|
||||||
#ifdef SERVER_DEBUGGER
|
#ifdef SERVER_DEBUGGER
|
||||||
@@ -388,6 +403,7 @@ end:
|
|||||||
for (unsigned i = dyn_idx; i < count; ++i) {
|
for (unsigned i = dyn_idx; i < count; ++i) {
|
||||||
free((char *) cmd[i]);
|
free((char *) cmd[i]);
|
||||||
}
|
}
|
||||||
|
free(classpath);
|
||||||
|
|
||||||
return pid;
|
return pid;
|
||||||
}
|
}
|
||||||
@@ -937,7 +953,7 @@ run_server(void *data) {
|
|||||||
assert(serial);
|
assert(serial);
|
||||||
LOGD("Device serial: %s", serial);
|
LOGD("Device serial: %s", serial);
|
||||||
|
|
||||||
ok = push_server(&server->intr, serial);
|
ok = push_server(&server->intr, params->scid, serial);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
goto error_connection_failed;
|
goto error_connection_failed;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user