Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1572/turn on screen when exit #1576

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 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 scheduleScreenOn) throws IOException {
boolean needProcess = disableShowTouches || restoreStayOn != -1 || scheduleScreenOn;
if (needProcess) {
startProcess(disableShowTouches, restoreStayOn);
startProcess(disableShowTouches, restoreStayOn, scheduleScreenOn);
} 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 scheduleScreenOn) throws IOException {
String[] cmd = {"app_process", "/", CleanUp.class.getName(), String.valueOf(disableShowTouches),
String.valueOf(restoreStayOn), String.valueOf(scheduleScreenOn)};

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

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

if (disableShowTouches || restoreStayOn != -1) {
if (disableShowTouches || restoreStayOn != -1 || scheduleScreenOn) {
ServiceManager serviceManager = new ServiceManager();
try (ContentProvider settings = serviceManager.getActivityManager().createSettingsProvider()) {
if (disableShowTouches) {
Expand All @@ -72,6 +74,10 @@ public static void main(String... args) {
settings.putValue(ContentProvider.TABLE_GLOBAL, "stay_on_while_plugged_in", String.valueOf(restoreStayOn));
}
}
if (scheduleScreenOn) {
Ln.i("Restoring \"displayPowerMode\"");
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