From fc97b00ac8f7efff2f67cc45d42eab0e7934be13 Mon Sep 17 00:00:00 2001 From: brunoais Date: Sat, 19 Jun 2021 12:46:35 +0100 Subject: [PATCH] Add intents capability and handling to the server --- .../java/com/genymobile/scrcpy/Intents.java | 36 +++++++++++++++++++ .../java/com/genymobile/scrcpy/Options.java | 12 +++++++ .../java/com/genymobile/scrcpy/Server.java | 9 ++++- 3 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 server/src/main/java/com/genymobile/scrcpy/Intents.java diff --git a/server/src/main/java/com/genymobile/scrcpy/Intents.java b/server/src/main/java/com/genymobile/scrcpy/Intents.java new file mode 100644 index 00000000..e128f434 --- /dev/null +++ b/server/src/main/java/com/genymobile/scrcpy/Intents.java @@ -0,0 +1,36 @@ +package com.genymobile.scrcpy; + +import java.io.IOException; +import java.util.*; + +enum Intents { + START(1), + STOP(30), + CLEANED(31), + ; + + public static final String SCRCPY_PREFIX = "com.genymobile.scrcpy."; + + int shift; + Intents(int shift) { + this.shift = shift; + } + + public static EnumSet fromBitSet(BitSet bits) { + EnumSet es = EnumSet.allOf(Intents.class); + + Iterator it = es.iterator(); + Intents intent; + while (it.hasNext()) { + intent = it.next(); + if (!bits.get(intent.shift - 1)) { + it.remove(); + } + } + return es; + } + + public static String scrcpyPrefix(String unprefixed){ + return SCRCPY_PREFIX + unprefixed; + } +} diff --git a/server/src/main/java/com/genymobile/scrcpy/Options.java b/server/src/main/java/com/genymobile/scrcpy/Options.java index cf11df0f..425a342e 100644 --- a/server/src/main/java/com/genymobile/scrcpy/Options.java +++ b/server/src/main/java/com/genymobile/scrcpy/Options.java @@ -2,6 +2,9 @@ package com.genymobile.scrcpy; import android.graphics.Rect; +import java.util.BitSet; +import java.util.EnumSet; + public class Options { private Ln.Level logLevel; private int maxSize; @@ -18,6 +21,7 @@ public class Options { private String codecOptions; private String encoderName; private boolean powerOffScreenOnClose; + private EnumSet broadcastIntents; public Ln.Level getLogLevel() { return logLevel; @@ -83,6 +87,10 @@ public class Options { this.sendFrameMeta = sendFrameMeta; } + public void setBroadcastIntents(EnumSet broadcastIntents) { + this.broadcastIntents = broadcastIntents; + } + public boolean getControl() { return control; } @@ -138,4 +146,8 @@ public class Options { public boolean getPowerOffScreenOnClose() { return this.powerOffScreenOnClose; } + + public EnumSet getBroadcastIntents() { + return broadcastIntents; + } } diff --git a/server/src/main/java/com/genymobile/scrcpy/Server.java b/server/src/main/java/com/genymobile/scrcpy/Server.java index fdd9db88..fe3294b0 100644 --- a/server/src/main/java/com/genymobile/scrcpy/Server.java +++ b/server/src/main/java/com/genymobile/scrcpy/Server.java @@ -1,5 +1,7 @@ package com.genymobile.scrcpy; +import android.content.Intent; +import android.net.Uri; import com.genymobile.scrcpy.wrappers.ContentProvider; import android.graphics.Rect; @@ -9,6 +11,8 @@ import android.os.BatteryManager; import android.os.Build; import java.io.IOException; +import java.util.BitSet; +import java.util.EnumSet; import java.util.List; import java.util.Locale; @@ -135,7 +139,7 @@ public final class Server { "The server version (" + BuildConfig.VERSION_NAME + ") does not match the client " + "(" + clientVersion + ")"); } - final int expectedParameters = 16; + final int expectedParameters = 17; if (args.length != expectedParameters) { throw new IllegalArgumentException("Expecting " + expectedParameters + " parameters"); } @@ -188,6 +192,9 @@ public final class Server { boolean powerOffScreenOnClose = Boolean.parseBoolean(args[15]); options.setPowerOffScreenOnClose(powerOffScreenOnClose); + EnumSet broadcastIntents = Intents.fromBitSet(BitSet.valueOf(new long[]{Long.parseLong(args[16])})); + options.setBroadcastIntents(broadcastIntents); + return options; }