From 6d0e61cdcf852b636f733a6a228722b243e28b71 Mon Sep 17 00:00:00 2001 From: Yu-Chen Lin Date: Sun, 10 Nov 2019 20:23:58 +0800 Subject: [PATCH] Send client version as first parameter and check it at server starts Signed-off-by: Yu-Chen Lin --- app/src/server.c | 1 + .../java/com/genymobile/scrcpy/Server.java | 27 +++++++++++++------ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/app/src/server.c b/app/src/server.c index de61001fc8..b40b065b71 100644 --- a/app/src/server.c +++ b/app/src/server.c @@ -131,6 +131,7 @@ execute_server(struct server *server, const struct server_params *params) { #endif "/", // unused "com.genymobile.scrcpy.Server", + SCRCPY_VERSION, max_size_string, bit_rate_string, server->tunnel_forward ? "true" : "false", diff --git a/server/src/main/java/com/genymobile/scrcpy/Server.java b/server/src/main/java/com/genymobile/scrcpy/Server.java index eba89bdb66..41df2803de 100644 --- a/server/src/main/java/com/genymobile/scrcpy/Server.java +++ b/server/src/main/java/com/genymobile/scrcpy/Server.java @@ -67,29 +67,40 @@ public void run() { @SuppressWarnings("checkstyle:MagicNumber") private static Options createOptions(String... args) { - if (args.length != 6) { - throw new IllegalArgumentException("Expecting 6 parameters"); + if (args.length < 1) { + throw new IllegalArgumentException("At least client version should be specified"); + } + + String clientVersion = args[0]; + + if (!clientVersion.equals(BuildConfig.VERSION_NAME)) { + throw new java.lang.UnsupportedOperationException( + "Difference version between client and server has not support yet"); + } + + if (args.length != 7) { + throw new IllegalArgumentException("Expecting 7 parameters"); } Options options = new Options(); - int maxSize = Integer.parseInt(args[0]) & ~7; // multiple of 8 + int maxSize = Integer.parseInt(args[1]) & ~7; // multiple of 8 options.setMaxSize(maxSize); - int bitRate = Integer.parseInt(args[1]); + int bitRate = Integer.parseInt(args[2]); options.setBitRate(bitRate); // use "adb forward" instead of "adb tunnel"? (so the server must listen) - boolean tunnelForward = Boolean.parseBoolean(args[2]); + boolean tunnelForward = Boolean.parseBoolean(args[3]); options.setTunnelForward(tunnelForward); - Rect crop = parseCrop(args[3]); + Rect crop = parseCrop(args[4]); options.setCrop(crop); - boolean sendFrameMeta = Boolean.parseBoolean(args[4]); + boolean sendFrameMeta = Boolean.parseBoolean(args[5]); options.setSendFrameMeta(sendFrameMeta); - boolean control = Boolean.parseBoolean(args[5]); + boolean control = Boolean.parseBoolean(args[6]); options.setControl(control); return options;