diff --git a/app/src/server.c b/app/src/server.c index d1c98a75..777da9a8 100644 --- a/app/src/server.c +++ b/app/src/server.c @@ -316,6 +316,10 @@ execute_server(struct sc_server *server, // By default, power_on is true ADD_PARAM("power_on=false"); } + if (params->install) { + // By default, installed is false + ADD_PARAM("installed=true"); + } #undef ADD_PARAM diff --git a/server/src/main/java/com/genymobile/scrcpy/CleanUp.java b/server/src/main/java/com/genymobile/scrcpy/CleanUp.java index 3ea26470..f9e9cded 100644 --- a/server/src/main/java/com/genymobile/scrcpy/CleanUp.java +++ b/server/src/main/java/com/genymobile/scrcpy/CleanUp.java @@ -37,6 +37,8 @@ public final class CleanUp { private static final int FLAG_RESTORE_NORMAL_POWER_MODE = 2; private static final int FLAG_POWER_OFF_SCREEN = 4; + private boolean installed; + private int displayId; // Restore the value (between 0 and 7), -1 to not restore @@ -52,6 +54,7 @@ public final class CleanUp { } protected Config(Parcel in) { + installed = in.readInt() != 0; displayId = in.readInt(); restoreStayOn = in.readInt(); byte options = in.readByte(); @@ -62,6 +65,7 @@ public final class CleanUp { @Override public void writeToParcel(Parcel dest, int flags) { + dest.writeInt(installed ? 1 : 0); dest.writeInt(displayId); dest.writeInt(restoreStayOn); byte options = 0; @@ -116,9 +120,10 @@ public final class CleanUp { // not instantiable } - public static void configure(int displayId, int restoreStayOn, boolean disableShowTouches, boolean restoreNormalPowerMode, boolean powerOffScreen) + public static void configure(boolean installed, int displayId, int restoreStayOn, boolean disableShowTouches, boolean restoreNormalPowerMode, boolean powerOffScreen) throws IOException { Config config = new Config(); + config.installed = installed; config.displayId = displayId; config.disableShowTouches = disableShowTouches; config.restoreStayOn = restoreStayOn; @@ -127,8 +132,9 @@ public final class CleanUp { if (config.hasWork()) { startProcess(config); - } else { - // There is no additional clean up to do when scrcpy dies + } else if (!installed) { + // There is no additional clean up to do when scrcpy dies. + // If the APK has been pushed to /data/local/tmp, remove it. unlinkSelf(); } } @@ -136,6 +142,7 @@ public final class CleanUp { private static void startProcess(Config config) throws IOException { String[] cmd = {"app_process", "/", CleanUp.class.getName(), config.toBase64()}; + // TODO if scrcpy is "installed", then we must find the install path! ProcessBuilder builder = new ProcessBuilder(cmd); builder.environment().put("CLASSPATH", SERVER_PATH); builder.start(); @@ -150,7 +157,12 @@ public final class CleanUp { } public static void main(String... args) { - unlinkSelf(); + Config config = Config.fromBase64(args[0]); + + if (!config.installed) { + // If the APK has been pushed to /data/local/tmp, remove it. + unlinkSelf(); + } try { // Wait for the server to die @@ -161,8 +173,6 @@ public final class CleanUp { Ln.i("Cleaning up"); - Config config = Config.fromBase64(args[0]); - if (config.disableShowTouches || config.restoreStayOn != -1) { ServiceManager serviceManager = new ServiceManager(); Settings settings = new Settings(serviceManager); diff --git a/server/src/main/java/com/genymobile/scrcpy/Options.java b/server/src/main/java/com/genymobile/scrcpy/Options.java index d1607c20..1bb1c381 100644 --- a/server/src/main/java/com/genymobile/scrcpy/Options.java +++ b/server/src/main/java/com/genymobile/scrcpy/Options.java @@ -23,6 +23,7 @@ public class Options { private boolean downsizeOnError = true; private boolean cleanup = true; private boolean powerOn = true; + private boolean installed = false; // Options not used by the scrcpy client, but useful to use scrcpy-server directly private boolean sendDeviceMeta = true; // send device name and size @@ -196,4 +197,12 @@ public class Options { public void setSendDummyByte(boolean sendDummyByte) { this.sendDummyByte = sendDummyByte; } + + public boolean getInstalled() { + return installed; + } + + public void setInstalled(boolean installed) { + this.installed = installed; + } } diff --git a/server/src/main/java/com/genymobile/scrcpy/Server.java b/server/src/main/java/com/genymobile/scrcpy/Server.java index 1df91552..2dc468a1 100644 --- a/server/src/main/java/com/genymobile/scrcpy/Server.java +++ b/server/src/main/java/com/genymobile/scrcpy/Server.java @@ -52,8 +52,8 @@ public final class Server { if (options.getCleanup()) { try { - CleanUp.configure(options.getDisplayId(), restoreStayOn, mustDisableShowTouchesOnCleanUp, restoreNormalPowerMode, - options.getPowerOffScreenOnClose()); + CleanUp.configure(options.getInstalled(), options.getDisplayId(), restoreStayOn, mustDisableShowTouchesOnCleanUp, + restoreNormalPowerMode, options.getPowerOffScreenOnClose()); } catch (IOException e) { Ln.e("Could not configure cleanup", e); } @@ -252,6 +252,10 @@ public final class Server { boolean powerOn = Boolean.parseBoolean(value); options.setPowerOn(powerOn); break; + case "installed": + boolean installed = Boolean.parseBoolean(value); + options.setInstalled(installed); + break; case "send_device_meta": boolean sendDeviceMeta = Boolean.parseBoolean(value); options.setSendDeviceMeta(sendDeviceMeta);