Skip to content

Commit adb0f6d

Browse files
committed
Android: VNCConn: add UTF-8 cuttext sending
Closes #252
1 parent 26004a1 commit adb0f6d

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

android/app/src/main/cpp/vncconn.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,20 @@ JNIEXPORT jboolean JNICALL Java_com_coboltforge_dontmind_multivnc_VNCConn_rfbSen
695695
return JNI_FALSE;
696696
}
697697

698+
JNIEXPORT jboolean JNICALL Java_com_coboltforge_dontmind_multivnc_VNCConn_rfbSendClientCutTextUTF8(JNIEnv *env, jobject obj, jstring jText) {
699+
rfbClient *cl = getRfbClient(env, obj);
700+
if (cl) {
701+
const char *cText = (*env)->GetStringUTFChars(env, jText, NULL);
702+
if (!cText)
703+
return JNI_FALSE;
704+
jboolean status = SendClientCutTextUTF8(cl, (char *) cText, (int) strlen(cText));
705+
(*env)->ReleaseStringUTFChars(env, jText, cText);
706+
return status;
707+
}
708+
else
709+
return JNI_FALSE;
710+
}
711+
698712
JNIEXPORT jboolean JNICALL Java_com_coboltforge_dontmind_multivnc_VNCConn_rfbIsEncrypted(JNIEnv *env, jobject obj) {
699713
rfbClient *cl = getRfbClient(env, obj);
700714
if (cl)

android/app/src/main/java/com/coboltforge/dontmind/multivnc/VNCConn.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -376,11 +376,21 @@ private boolean sendKeyEvent(OutputEvent.KeyboardEvent evt) {
376376

377377

378378
private boolean sendCutText(String text) {
379+
boolean status = false;
379380
if (rfbClient != 0) {
380-
if (Utils.DEBUG()) Log.d(TAG, "sending cuttext " + text);
381-
return rfbSendClientCutText(StandardCharsets.ISO_8859_1.encode(text).array());
381+
// first, try sending UTF-8
382+
if(rfbSendClientCutTextUTF8(text)) {
383+
if (Utils.DEBUG()) Log.d(TAG, "Sent UTF-8 cuttext: '" + text + "' successfully");
384+
status = true;
385+
} else {
386+
// server does not support Extended Clipboard, try Latin-1.
387+
// encode() docs say: "This method always replaces malformed-input and unmappable-character
388+
// sequences with this charset's default replacement string."
389+
status = rfbSendClientCutText(StandardCharsets.ISO_8859_1.encode(text).array());
390+
if (Utils.DEBUG()) Log.d(TAG, "Sent ISO-8859-1 cuttext: '" + text + "'" + (status ? "successfully" : "unsuccessfully"));
391+
}
382392
}
383-
return false;
393+
return status;
384394
}
385395

386396

@@ -404,6 +414,7 @@ private native boolean rfbInit(String host, int port, int repeaterId, int bytesP
404414
private native boolean rfbSendKeyEvent(long keysym, boolean down);
405415
private native boolean rfbSendPointerEvent(int x, int y, int buttonMask);
406416
private native boolean rfbSendClientCutText(byte[] bytes);
417+
private native boolean rfbSendClientCutTextUTF8(String text);
407418
private native boolean rfbIsEncrypted();
408419

409420

0 commit comments

Comments
 (0)