Skip to content

Commit

Permalink
Restore power mode to normal on cleanup
Browse files Browse the repository at this point in the history
This avoids to let the device screen turned off (as enabled by Ctrl+o or
--turn-screen-off).

PR #1576 <#1576>
Fixes #1572 <#1572>
  • Loading branch information
brunoais authored and rom1v committed Jul 9, 2020
1 parent a973757 commit 30714ab
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
17 changes: 12 additions & 5 deletions server/src/main/java/com/genymobile/scrcpy/CleanUp.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,19 @@ private CleanUp() {
// not instantiable
}

public static void configure(boolean disableShowTouches, int restoreStayOn) throws IOException {
boolean needProcess = disableShowTouches || restoreStayOn != -1;
public static void configure(boolean disableShowTouches, int restoreStayOn, boolean restoreNormalPowerMode) throws IOException {
boolean needProcess = disableShowTouches || restoreStayOn != -1 || restoreNormalPowerMode;
if (needProcess) {
startProcess(disableShowTouches, restoreStayOn);
startProcess(disableShowTouches, restoreStayOn, restoreNormalPowerMode);
} else {
// There is no additional clean up to do when scrcpy dies
unlinkSelf();
}
}

private static void startProcess(boolean disableShowTouches, int restoreStayOn) throws IOException {
String[] cmd = {"app_process", "/", CleanUp.class.getName(), String.valueOf(disableShowTouches), String.valueOf(restoreStayOn)};
private static void startProcess(boolean disableShowTouches, int restoreStayOn, boolean restoreNormalPowerMode) throws IOException {
String[] cmd = {"app_process", "/", CleanUp.class.getName(), String.valueOf(disableShowTouches), String.valueOf(
restoreStayOn), String.valueOf(restoreNormalPowerMode)};

ProcessBuilder builder = new ProcessBuilder(cmd);
builder.environment().put("CLASSPATH", SERVER_PATH);
Expand Down Expand Up @@ -59,6 +60,7 @@ public static void main(String... args) {

boolean disableShowTouches = Boolean.parseBoolean(args[0]);
int restoreStayOn = Integer.parseInt(args[1]);
boolean restoreNormalPowerMode = Boolean.parseBoolean(args[2]);

if (disableShowTouches || restoreStayOn != -1) {
ServiceManager serviceManager = new ServiceManager();
Expand All @@ -73,5 +75,10 @@ public static void main(String... args) {
}
}
}

if (restoreNormalPowerMode) {
Ln.i("Restoring normal power mode");
Device.setScreenPowerMode(Device.POWER_MODE_NORMAL);
}
}
}
2 changes: 1 addition & 1 deletion server/src/main/java/com/genymobile/scrcpy/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private static void scrcpy(Options options) throws IOException {
}
}

CleanUp.configure(mustDisableShowTouchesOnCleanUp, restoreStayOn);
CleanUp.configure(mustDisableShowTouchesOnCleanUp, restoreStayOn, true);

boolean tunnelForward = options.isTunnelForward();

Expand Down

0 comments on commit 30714ab

Please sign in to comment.