Add CLEANED intent to the server

This commit is contained in:
brunoais 2021-06-19 12:47:59 +01:00
parent f29baa77f4
commit eae1c7e5d6
2 changed files with 28 additions and 3 deletions

View file

@ -1,5 +1,7 @@
package com.genymobile.scrcpy;
import android.content.Intent;
import android.net.Uri;
import com.genymobile.scrcpy.wrappers.ContentProvider;
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_RESTORE_NORMAL_POWER_MODE = 1 << 1;
private static final int FLAG_POWER_OFF_SCREEN = 1 << 2;
private static final int FLAG_BROADCAST_CLEANED = 1 << 3;
private int displayId;
@ -47,6 +50,7 @@ public final class CleanUp {
private boolean disableShowTouches;
private boolean restoreNormalPowerMode;
private boolean powerOffScreen;
private boolean broadcastCleaned;
public Config() {
// Default constructor, the fields are initialized by CleanUp.configure()
@ -59,6 +63,7 @@ public final class CleanUp {
disableShowTouches = (options & FLAG_DISABLE_SHOW_TOUCHES) != 0;
restoreNormalPowerMode = (options & FLAG_RESTORE_NORMAL_POWER_MODE) != 0;
powerOffScreen = (options & FLAG_POWER_OFF_SCREEN) != 0;
broadcastCleaned = (options & FLAG_BROADCAST_CLEANED) != 0;
}
@Override
@ -75,11 +80,14 @@ public final class CleanUp {
if (powerOffScreen) {
options |= FLAG_POWER_OFF_SCREEN;
}
if (broadcastCleaned) {
options |= FLAG_BROADCAST_CLEANED;
}
dest.writeByte(options);
}
private boolean hasWork() {
return disableShowTouches || restoreStayOn != -1 || restoreNormalPowerMode || powerOffScreen;
return disableShowTouches || restoreStayOn != -1 || restoreNormalPowerMode || powerOffScreen || broadcastCleaned;
}
@Override
@ -117,7 +125,8 @@ public final class CleanUp {
// 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 {
Config config = new Config();
config.displayId = displayId;
@ -125,6 +134,7 @@ public final class CleanUp {
config.restoreStayOn = restoreStayOn;
config.restoreNormalPowerMode = restoreNormalPowerMode;
config.powerOffScreen = powerOffScreen;
config.broadcastCleaned = broadcastCleaned;
if (config.hasWork()) {
startProcess(config);
@ -187,5 +197,19 @@ public final class CleanUp {
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);
}
}

View file

@ -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();