From eae1c7e5d6ea3985d6a3d75fbe9084beec77477b Mon Sep 17 00:00:00 2001 From: brunoais Date: Sat, 19 Jun 2021 12:47:59 +0100 Subject: [PATCH] Add CLEANED intent to the server --- .../java/com/genymobile/scrcpy/CleanUp.java | 28 +++++++++++++++++-- .../java/com/genymobile/scrcpy/Server.java | 3 +- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/server/src/main/java/com/genymobile/scrcpy/CleanUp.java b/server/src/main/java/com/genymobile/scrcpy/CleanUp.java index a463e713..57248d71 100644 --- a/server/src/main/java/com/genymobile/scrcpy/CleanUp.java +++ b/server/src/main/java/com/genymobile/scrcpy/CleanUp.java @@ -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); } } diff --git a/server/src/main/java/com/genymobile/scrcpy/Server.java b/server/src/main/java/com/genymobile/scrcpy/Server.java index 2040c5b5..9ab35fe1 100644 --- a/server/src/main/java/com/genymobile/scrcpy/Server.java +++ b/server/src/main/java/com/genymobile/scrcpy/Server.java @@ -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();