mirror of
https://github.com/Genymobile/scrcpy.git
synced 2025-07-18 23:11:49 +00:00
Add CLEANED intent to the server
This commit is contained in:
parent
f29baa77f4
commit
eae1c7e5d6
2 changed files with 28 additions and 3 deletions
|
@ -1,5 +1,7 @@
|
||||||
package com.genymobile.scrcpy;
|
package com.genymobile.scrcpy;
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.net.Uri;
|
||||||
import com.genymobile.scrcpy.wrappers.ContentProvider;
|
import com.genymobile.scrcpy.wrappers.ContentProvider;
|
||||||
import com.genymobile.scrcpy.wrappers.ServiceManager;
|
import com.genymobile.scrcpy.wrappers.ServiceManager;
|
||||||
|
|
||||||
|
@ -37,6 +39,7 @@ public final class CleanUp {
|
||||||
private static final int FLAG_DISABLE_SHOW_TOUCHES = 1 << 0;
|
private static final int FLAG_DISABLE_SHOW_TOUCHES = 1 << 0;
|
||||||
private static final int FLAG_RESTORE_NORMAL_POWER_MODE = 1 << 1;
|
private static final int FLAG_RESTORE_NORMAL_POWER_MODE = 1 << 1;
|
||||||
private static final int FLAG_POWER_OFF_SCREEN = 1 << 2;
|
private static final int FLAG_POWER_OFF_SCREEN = 1 << 2;
|
||||||
|
private static final int FLAG_BROADCAST_CLEANED = 1 << 3;
|
||||||
|
|
||||||
private int displayId;
|
private int displayId;
|
||||||
|
|
||||||
|
@ -47,6 +50,7 @@ public final class CleanUp {
|
||||||
private boolean disableShowTouches;
|
private boolean disableShowTouches;
|
||||||
private boolean restoreNormalPowerMode;
|
private boolean restoreNormalPowerMode;
|
||||||
private boolean powerOffScreen;
|
private boolean powerOffScreen;
|
||||||
|
private boolean broadcastCleaned;
|
||||||
|
|
||||||
public Config() {
|
public Config() {
|
||||||
// Default constructor, the fields are initialized by CleanUp.configure()
|
// Default constructor, the fields are initialized by CleanUp.configure()
|
||||||
|
@ -59,6 +63,7 @@ public final class CleanUp {
|
||||||
disableShowTouches = (options & FLAG_DISABLE_SHOW_TOUCHES) != 0;
|
disableShowTouches = (options & FLAG_DISABLE_SHOW_TOUCHES) != 0;
|
||||||
restoreNormalPowerMode = (options & FLAG_RESTORE_NORMAL_POWER_MODE) != 0;
|
restoreNormalPowerMode = (options & FLAG_RESTORE_NORMAL_POWER_MODE) != 0;
|
||||||
powerOffScreen = (options & FLAG_POWER_OFF_SCREEN) != 0;
|
powerOffScreen = (options & FLAG_POWER_OFF_SCREEN) != 0;
|
||||||
|
broadcastCleaned = (options & FLAG_BROADCAST_CLEANED) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -75,11 +80,14 @@ public final class CleanUp {
|
||||||
if (powerOffScreen) {
|
if (powerOffScreen) {
|
||||||
options |= FLAG_POWER_OFF_SCREEN;
|
options |= FLAG_POWER_OFF_SCREEN;
|
||||||
}
|
}
|
||||||
|
if (broadcastCleaned) {
|
||||||
|
options |= FLAG_BROADCAST_CLEANED;
|
||||||
|
}
|
||||||
dest.writeByte(options);
|
dest.writeByte(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean hasWork() {
|
private boolean hasWork() {
|
||||||
return disableShowTouches || restoreStayOn != -1 || restoreNormalPowerMode || powerOffScreen;
|
return disableShowTouches || restoreStayOn != -1 || restoreNormalPowerMode || powerOffScreen || broadcastCleaned;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -117,7 +125,8 @@ 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(int displayId, int restoreStayOn, boolean disableShowTouches, boolean restoreNormalPowerMode,
|
||||||
|
boolean powerOffScreen, boolean broadcastCleaned)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
Config config = new Config();
|
Config config = new Config();
|
||||||
config.displayId = displayId;
|
config.displayId = displayId;
|
||||||
|
@ -125,6 +134,7 @@ public final class CleanUp {
|
||||||
config.restoreStayOn = restoreStayOn;
|
config.restoreStayOn = restoreStayOn;
|
||||||
config.restoreNormalPowerMode = restoreNormalPowerMode;
|
config.restoreNormalPowerMode = restoreNormalPowerMode;
|
||||||
config.powerOffScreen = powerOffScreen;
|
config.powerOffScreen = powerOffScreen;
|
||||||
|
config.broadcastCleaned = broadcastCleaned;
|
||||||
|
|
||||||
if (config.hasWork()) {
|
if (config.hasWork()) {
|
||||||
startProcess(config);
|
startProcess(config);
|
||||||
|
@ -187,5 +197,19 @@ public final class CleanUp {
|
||||||
Device.setScreenPowerMode(Device.POWER_MODE_NORMAL);
|
Device.setScreenPowerMode(Device.POWER_MODE_NORMAL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(config.broadcastCleaned){
|
||||||
|
Ln.i("Announce cleaned");
|
||||||
|
announceScrcpyCleaned();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void announceScrcpyCleaned() {
|
||||||
|
|
||||||
|
Intent cleaned = new Intent(Intents.scrcpyPrefix("CLEANED"));
|
||||||
|
cleaned.setData(Uri.parse("scrcpy-status:cleaned"));
|
||||||
|
cleaned.putExtra(Intents.scrcpyPrefix("STARTUP"), false);
|
||||||
|
cleaned.putExtra(Intents.scrcpyPrefix("SHUTDOWN"), true);
|
||||||
|
Device.sendBroadcast(cleaned);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,7 +54,8 @@ public final class Server {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CleanUp.configure(options.getDisplayId(), restoreStayOn, mustDisableShowTouchesOnCleanUp, true, options.getPowerOffScreenOnClose());
|
CleanUp.configure(options.getDisplayId(), restoreStayOn, mustDisableShowTouchesOnCleanUp, true, options.getPowerOffScreenOnClose(),
|
||||||
|
options.getBroadcastIntents().contains(Intents.CLEANED));
|
||||||
|
|
||||||
boolean tunnelForward = options.isTunnelForward();
|
boolean tunnelForward = options.isTunnelForward();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue