Skip to content

Display and control your Android device

Do not hardcode server path on the device

sam80180acb298883775
diff --git a/server/src/main/java/com/genymobile/scrcpy/CleanUp.java b/server/src/main/java/com/genymobile/scrcpy/CleanUp.java
index 0bcd1a54..b3a1aac1 100644
--- a/server/src/main/java/com/genymobile/scrcpy/CleanUp.java
+++ b/server/src/main/java/com/genymobile/scrcpy/CleanUp.java
@@ -14,8 +14,6 @@ import java.io.IOException;
*/
public final class CleanUp {
- public static final String SERVER_PATH = "/data/local/tmp/scrcpy-server.jar";
-
// A simple struct to be passed from the main process to the cleanup process
public static class Config implements Parcelable {
@@ -135,13 +133,13 @@ public final class CleanUp {
String[] cmd = {"app_process", "/", CleanUp.class.getName(), config.toBase64()};
ProcessBuilder builder = new ProcessBuilder(cmd);
- builder.environment().put("CLASSPATH", SERVER_PATH);
+ builder.environment().put("CLASSPATH", Server.SERVER_PATH);
builder.start();
}
public static void unlinkSelf() {
try {
- new File(SERVER_PATH).delete();
+ new File(Server.SERVER_PATH).delete();
} catch (Exception e) {
Ln.e("Could not unlink server", e);
}
diff --git a/server/src/main/java/com/genymobile/scrcpy/Server.java b/server/src/main/java/com/genymobile/scrcpy/Server.java
index 61d3497b..2a8387e0 100644
--- a/server/src/main/java/com/genymobile/scrcpy/Server.java
+++ b/server/src/main/java/com/genymobile/scrcpy/Server.java
@@ -3,12 +3,20 @@ package com.genymobile.scrcpy;
import android.os.BatteryManager;
import android.os.Build;
+import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public final class Server {
+ public static final String SERVER_PATH;
+ static {
+ String[] classPaths = System.getProperty("java.class.path").split(File.pathSeparator);
+ // By convention, scrcpy is always executed with the absolute path of scrcpy-server.jar as the first item in the classpath
+ SERVER_PATH = classPaths[0];
+ }
+
private static class Completion {
private int running;
private boolean fatalError;