mirror of
https://github.com/Genymobile/scrcpy.git
synced 2025-04-22 04:25:01 +00:00
Adapt clean up for installed APK
The cleanup process is slightly different when the server is installed rather than pushed.
This commit is contained in:
parent
c0e00c485b
commit
b4e714f77d
4 changed files with 37 additions and 10 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -35,6 +35,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
|
||||
|
@ -50,6 +52,7 @@ public final class CleanUp {
|
|||
}
|
||||
|
||||
protected Config(Parcel in) {
|
||||
installed = in.readInt() != 0;
|
||||
displayId = in.readInt();
|
||||
restoreStayOn = in.readInt();
|
||||
byte options = in.readByte();
|
||||
|
@ -60,6 +63,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;
|
||||
|
@ -114,9 +118,10 @@ public final class CleanUp {
|
|||
// not instantiable
|
||||
}
|
||||
|
||||
public static void configure(int displayId, int restoreStayOn, boolean disableShowTouches, boolean restoreNormalPowerMode, boolean powerOffScreen)
|
||||
throws IOException {
|
||||
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;
|
||||
|
@ -125,8 +130,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();
|
||||
}
|
||||
}
|
||||
|
@ -135,7 +141,8 @@ public final class CleanUp {
|
|||
String[] cmd = {"app_process", "/", CleanUp.class.getName(), config.toBase64()};
|
||||
|
||||
ProcessBuilder builder = new ProcessBuilder(cmd);
|
||||
builder.environment().put("CLASSPATH", SERVER_PATH);
|
||||
String serverPath = config.installed ? Device.getInstalledApkPath() : SERVER_PATH;
|
||||
builder.environment().put("CLASSPATH", serverPath);
|
||||
builder.start();
|
||||
}
|
||||
|
||||
|
@ -148,7 +155,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
|
||||
|
@ -159,8 +171,6 @@ public final class CleanUp {
|
|||
|
||||
Ln.i("Cleaning up");
|
||||
|
||||
Config config = Config.fromBase64(args[0]);
|
||||
|
||||
if (config.disableShowTouches || config.restoreStayOn != -1) {
|
||||
if (config.disableShowTouches) {
|
||||
Ln.i("Disabling \"show touches\"");
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,8 +51,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);
|
||||
}
|
||||
|
@ -251,6 +251,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);
|
||||
|
|
Loading…
Add table
Reference in a new issue