mirror of
https://github.com/Genymobile/scrcpy.git
synced 2025-08-03 14:49:29 +00:00
clean up
This commit is contained in:
parent
64b70724e0
commit
7b75a3c966
4 changed files with 35 additions and 8 deletions
|
@ -316,6 +316,10 @@ execute_server(struct sc_server *server,
|
||||||
// By default, power_on is true
|
// By default, power_on is true
|
||||||
ADD_PARAM("power_on=false");
|
ADD_PARAM("power_on=false");
|
||||||
}
|
}
|
||||||
|
if (params->install) {
|
||||||
|
// By default, installed is false
|
||||||
|
ADD_PARAM("installed=true");
|
||||||
|
}
|
||||||
|
|
||||||
#undef ADD_PARAM
|
#undef ADD_PARAM
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,8 @@ public final class CleanUp {
|
||||||
private static final int FLAG_RESTORE_NORMAL_POWER_MODE = 2;
|
private static final int FLAG_RESTORE_NORMAL_POWER_MODE = 2;
|
||||||
private static final int FLAG_POWER_OFF_SCREEN = 4;
|
private static final int FLAG_POWER_OFF_SCREEN = 4;
|
||||||
|
|
||||||
|
private boolean installed;
|
||||||
|
|
||||||
private int displayId;
|
private int displayId;
|
||||||
|
|
||||||
// Restore the value (between 0 and 7), -1 to not restore
|
// Restore the value (between 0 and 7), -1 to not restore
|
||||||
|
@ -52,6 +54,7 @@ public final class CleanUp {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Config(Parcel in) {
|
protected Config(Parcel in) {
|
||||||
|
installed = in.readInt() != 0;
|
||||||
displayId = in.readInt();
|
displayId = in.readInt();
|
||||||
restoreStayOn = in.readInt();
|
restoreStayOn = in.readInt();
|
||||||
byte options = in.readByte();
|
byte options = in.readByte();
|
||||||
|
@ -62,6 +65,7 @@ public final class CleanUp {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeToParcel(Parcel dest, int flags) {
|
public void writeToParcel(Parcel dest, int flags) {
|
||||||
|
dest.writeInt(installed ? 1 : 0);
|
||||||
dest.writeInt(displayId);
|
dest.writeInt(displayId);
|
||||||
dest.writeInt(restoreStayOn);
|
dest.writeInt(restoreStayOn);
|
||||||
byte options = 0;
|
byte options = 0;
|
||||||
|
@ -116,9 +120,10 @@ public final class CleanUp {
|
||||||
// not instantiable
|
// 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 {
|
throws IOException {
|
||||||
Config config = new Config();
|
Config config = new Config();
|
||||||
|
config.installed = installed;
|
||||||
config.displayId = displayId;
|
config.displayId = displayId;
|
||||||
config.disableShowTouches = disableShowTouches;
|
config.disableShowTouches = disableShowTouches;
|
||||||
config.restoreStayOn = restoreStayOn;
|
config.restoreStayOn = restoreStayOn;
|
||||||
|
@ -127,8 +132,9 @@ public final class CleanUp {
|
||||||
|
|
||||||
if (config.hasWork()) {
|
if (config.hasWork()) {
|
||||||
startProcess(config);
|
startProcess(config);
|
||||||
} else {
|
} else if (!installed) {
|
||||||
// There is no additional clean up to do when scrcpy dies
|
// There is no additional clean up to do when scrcpy dies.
|
||||||
|
// If the APK has been pushed to /data/local/tmp, remove it.
|
||||||
unlinkSelf();
|
unlinkSelf();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -136,6 +142,7 @@ public final class CleanUp {
|
||||||
private static void startProcess(Config config) throws IOException {
|
private static void startProcess(Config config) throws IOException {
|
||||||
String[] cmd = {"app_process", "/", CleanUp.class.getName(), config.toBase64()};
|
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);
|
ProcessBuilder builder = new ProcessBuilder(cmd);
|
||||||
builder.environment().put("CLASSPATH", SERVER_PATH);
|
builder.environment().put("CLASSPATH", SERVER_PATH);
|
||||||
builder.start();
|
builder.start();
|
||||||
|
@ -150,7 +157,12 @@ public final class CleanUp {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String... args) {
|
public static void main(String... args) {
|
||||||
|
Config config = Config.fromBase64(args[0]);
|
||||||
|
|
||||||
|
if (!config.installed) {
|
||||||
|
// If the APK has been pushed to /data/local/tmp, remove it.
|
||||||
unlinkSelf();
|
unlinkSelf();
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Wait for the server to die
|
// Wait for the server to die
|
||||||
|
@ -161,8 +173,6 @@ public final class CleanUp {
|
||||||
|
|
||||||
Ln.i("Cleaning up");
|
Ln.i("Cleaning up");
|
||||||
|
|
||||||
Config config = Config.fromBase64(args[0]);
|
|
||||||
|
|
||||||
if (config.disableShowTouches || config.restoreStayOn != -1) {
|
if (config.disableShowTouches || config.restoreStayOn != -1) {
|
||||||
ServiceManager serviceManager = new ServiceManager();
|
ServiceManager serviceManager = new ServiceManager();
|
||||||
Settings settings = new Settings(serviceManager);
|
Settings settings = new Settings(serviceManager);
|
||||||
|
|
|
@ -23,6 +23,7 @@ public class Options {
|
||||||
private boolean downsizeOnError = true;
|
private boolean downsizeOnError = true;
|
||||||
private boolean cleanup = true;
|
private boolean cleanup = true;
|
||||||
private boolean powerOn = true;
|
private boolean powerOn = true;
|
||||||
|
private boolean installed = false;
|
||||||
|
|
||||||
// Options not used by the scrcpy client, but useful to use scrcpy-server directly
|
// Options not used by the scrcpy client, but useful to use scrcpy-server directly
|
||||||
private boolean sendDeviceMeta = true; // send device name and size
|
private boolean sendDeviceMeta = true; // send device name and size
|
||||||
|
@ -196,4 +197,12 @@ public class Options {
|
||||||
public void setSendDummyByte(boolean sendDummyByte) {
|
public void setSendDummyByte(boolean sendDummyByte) {
|
||||||
this.sendDummyByte = sendDummyByte;
|
this.sendDummyByte = sendDummyByte;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean getInstalled() {
|
||||||
|
return installed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setInstalled(boolean installed) {
|
||||||
|
this.installed = installed;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,8 +52,8 @@ public final class Server {
|
||||||
|
|
||||||
if (options.getCleanup()) {
|
if (options.getCleanup()) {
|
||||||
try {
|
try {
|
||||||
CleanUp.configure(options.getDisplayId(), restoreStayOn, mustDisableShowTouchesOnCleanUp, restoreNormalPowerMode,
|
CleanUp.configure(options.getInstalled(), options.getDisplayId(), restoreStayOn, mustDisableShowTouchesOnCleanUp,
|
||||||
options.getPowerOffScreenOnClose());
|
restoreNormalPowerMode, options.getPowerOffScreenOnClose());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Ln.e("Could not configure cleanup", e);
|
Ln.e("Could not configure cleanup", e);
|
||||||
}
|
}
|
||||||
|
@ -252,6 +252,10 @@ public final class Server {
|
||||||
boolean powerOn = Boolean.parseBoolean(value);
|
boolean powerOn = Boolean.parseBoolean(value);
|
||||||
options.setPowerOn(powerOn);
|
options.setPowerOn(powerOn);
|
||||||
break;
|
break;
|
||||||
|
case "installed":
|
||||||
|
boolean installed = Boolean.parseBoolean(value);
|
||||||
|
options.setInstalled(installed);
|
||||||
|
break;
|
||||||
case "send_device_meta":
|
case "send_device_meta":
|
||||||
boolean sendDeviceMeta = Boolean.parseBoolean(value);
|
boolean sendDeviceMeta = Boolean.parseBoolean(value);
|
||||||
options.setSendDeviceMeta(sendDeviceMeta);
|
options.setSendDeviceMeta(sendDeviceMeta);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue