Display and control your Android device
Rename max length constant for text injection
Romain Vimont270d0bf639fb
diff --git a/app/src/control_msg.c b/app/src/control_msg.cindex 45113139..252a3425 100644--- a/app/src/control_msg.c+++ b/app/src/control_msg.c@@ -45,8 +45,9 @@ control_msg_serialize(const struct control_msg *msg, unsigned char *buf) {buffer_write32be(&buf[6], msg->inject_keycode.metastate);return 10;case CONTROL_MSG_TYPE_INJECT_TEXT: {- size_t len = write_string(msg->inject_text.text,- CONTROL_MSG_TEXT_MAX_LENGTH, &buf[1]);+ size_t len =+ write_string(msg->inject_text.text,+ CONTROL_MSG_INJECT_TEXT_MAX_LENGTH, &buf[1]);return 1 + len;}case CONTROL_MSG_TYPE_INJECT_TOUCH_EVENT:diff --git a/app/src/control_msg.h b/app/src/control_msg.hindex 49a159a6..e132fc6b 100644--- a/app/src/control_msg.h+++ b/app/src/control_msg.h@@ -10,7 +10,7 @@#include "android/keycodes.h"#include "common.h"-#define CONTROL_MSG_TEXT_MAX_LENGTH 300+#define CONTROL_MSG_INJECT_TEXT_MAX_LENGTH 300#define CONTROL_MSG_CLIPBOARD_TEXT_MAX_LENGTH 4093#define CONTROL_MSG_SERIALIZED_MAX_SIZE \(3 + CONTROL_MSG_CLIPBOARD_TEXT_MAX_LENGTH)diff --git a/app/tests/test_control_msg_serialize.c b/app/tests/test_control_msg_serialize.cindex d6f556f3..4dc79018 100644--- a/app/tests/test_control_msg_serialize.c+++ b/app/tests/test_control_msg_serialize.c@@ -49,20 +49,20 @@ static void test_serialize_inject_text(void) {static void test_serialize_inject_text_long(void) {struct control_msg msg;msg.type = CONTROL_MSG_TYPE_INJECT_TEXT;- char text[CONTROL_MSG_TEXT_MAX_LENGTH + 1];+ char text[CONTROL_MSG_INJECT_TEXT_MAX_LENGTH + 1];memset(text, 'a', sizeof(text));- text[CONTROL_MSG_TEXT_MAX_LENGTH] = '\0';+ text[CONTROL_MSG_INJECT_TEXT_MAX_LENGTH] = '\0';msg.inject_text.text = text;unsigned char buf[CONTROL_MSG_SERIALIZED_MAX_SIZE];int size = control_msg_serialize(&msg, buf);- assert(size == 3 + CONTROL_MSG_TEXT_MAX_LENGTH);+ assert(size == 3 + CONTROL_MSG_INJECT_TEXT_MAX_LENGTH);- unsigned char expected[3 + CONTROL_MSG_TEXT_MAX_LENGTH];+ unsigned char expected[3 + CONTROL_MSG_INJECT_TEXT_MAX_LENGTH];expected[0] = CONTROL_MSG_TYPE_INJECT_TEXT;expected[1] = 0x01;expected[2] = 0x2c; // text length (16 bits)- memset(&expected[3], 'a', CONTROL_MSG_TEXT_MAX_LENGTH);+ memset(&expected[3], 'a', CONTROL_MSG_INJECT_TEXT_MAX_LENGTH);assert(!memcmp(buf, expected, sizeof(expected)));}diff --git a/server/src/main/java/com/genymobile/scrcpy/ControlMessageReader.java b/server/src/main/java/com/genymobile/scrcpy/ControlMessageReader.javaindex 29172c08..1c081058 100644--- a/server/src/main/java/com/genymobile/scrcpy/ControlMessageReader.java+++ b/server/src/main/java/com/genymobile/scrcpy/ControlMessageReader.java@@ -13,8 +13,8 @@ public class ControlMessageReader {static final int INJECT_SCROLL_EVENT_PAYLOAD_LENGTH = 20;static final int SET_SCREEN_POWER_MODE_PAYLOAD_LENGTH = 1;- public static final int TEXT_MAX_LENGTH = 300;public static final int CLIPBOARD_TEXT_MAX_LENGTH = 4093;+ public static final int INJECT_TEXT_MAX_LENGTH = 300;private static final int RAW_BUFFER_SIZE = 1024;private final byte[] rawBuffer = new byte[RAW_BUFFER_SIZE];diff --git a/server/src/test/java/com/genymobile/scrcpy/ControlMessageReaderTest.java b/server/src/test/java/com/genymobile/scrcpy/ControlMessageReaderTest.javaindex 1905942b..202126a5 100644--- a/server/src/test/java/com/genymobile/scrcpy/ControlMessageReaderTest.java+++ b/server/src/test/java/com/genymobile/scrcpy/ControlMessageReaderTest.java@@ -66,7 +66,7 @@ public class ControlMessageReaderTest {ByteArrayOutputStream bos = new ByteArrayOutputStream();DataOutputStream dos = new DataOutputStream(bos);dos.writeByte(ControlMessage.TYPE_INJECT_TEXT);- byte[] text = new byte[ControlMessageReader.TEXT_MAX_LENGTH];+ byte[] text = new byte[ControlMessageReader.INJECT_TEXT_MAX_LENGTH];Arrays.fill(text, (byte) 'a');dos.writeShort(text.length);dos.write(text);