Skip to content

Commit

Permalink
Improvements to stability during initial connection for aSPICE and Op…
Browse files Browse the repository at this point in the history
…aque.
  • Loading branch information
iiordanov committed Dec 28, 2024
1 parent e8c086b commit 815d8fa
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@

abstract public class RemoteConnection implements PointerInputHandler, KeyInputHandler, InputCarriable {
private final static String TAG = "RemoteConnection";
public static final int CLIPBOARD_INITIAL_DELAY = 0;
public static final int CLIPBOARD_CHECK_PERIOD = 500;

// Connection parameters
public Connection connection;
Expand Down Expand Up @@ -155,10 +157,9 @@ protected void initializeClipboardMonitor() {
if (clipboardMonitor != null) {
clipboardMonitorTimer = new Timer();
try {
clipboardMonitorTimer.schedule(clipboardMonitor, 0, 500);
clipboardMonitorTimer.schedule(clipboardMonitor, CLIPBOARD_INITIAL_DELAY, CLIPBOARD_CHECK_PERIOD);
} catch (NullPointerException e) {
e.printStackTrace();
Log.d(TAG, "Ignored NullPointerException while initializing clipboard monitor");
Log.d(TAG, "Ignored NullPointerException while initializing clipboard monitor: " + Log.getStackTraceString(e));
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions remoteClientLib/src/main/cpp/android/android-clipboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ void spice_clipboard_selection_request_handler(


void spice_clipboard_selection_grab(SpiceMainChannel* channel, const guchar* text, size_t size) {
__android_log_write(ANDROID_LOG_INFO, "android-spice",
"spice_clipboard_selection_grab");
clipboard->length = MIN(size, clipboard->available - 1);
strncpy(clipboard->buffer, (const char *)text, clipboard->length);
guint32 clipboard_types[] = { VD_AGENT_CLIPBOARD_UTF8_TEXT };
Expand Down
11 changes: 10 additions & 1 deletion remoteClientLib/src/main/cpp/android/android-io.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ Java_com_undatech_opaque_SpiceCommunicator_SpiceRequestResolution(JNIEnv* env, j
__android_log_write(ANDROID_LOG_INFO, "android-io", "SpiceRequestResolution");
SpiceDisplay* display = global_display;
SpiceDisplayPrivate *d = SPICE_DISPLAY_GET_PRIVATE(display);
g_return_if_fail(SPICE_IS_MAIN_CHANNEL(d->main));

spice_main_channel_update_display_enabled(d->main, get_display_id(display), TRUE, FALSE);
spice_main_channel_update_display(d->main, get_display_id(display), 0, 0, x, y, TRUE);
Expand Down Expand Up @@ -186,9 +187,17 @@ Java_com_undatech_opaque_SpiceCommunicator_SpiceClientCutText(JNIEnv *env, jobje
SpiceDisplay* display = global_display;
SpiceDisplayPrivate *d = SPICE_DISPLAY_GET_PRIVATE(display);
g_return_if_fail(SPICE_IS_MAIN_CHANNEL(d->main));

if (d == NULL || d->main == NULL) {
return;
}
size_t size = (*env)->GetStringUTFLength(env, text);
if (size == 0) {
return;
}
const guchar *convertedText = (const guchar*)(*env)->GetStringUTFChars(env, text, NULL);
if (convertedText == NULL) {
return;
}
spice_clipboard_selection_grab(d->main, convertedText, size);
g_free((gpointer)convertedText);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ public class SpiceCommunicator extends RfbConnectable {
final static int LWIN = 347;
final static int RWIN = 348;
private final static String TAG = "SpiceCommunicator";
public static final int INITIAL_REQUEST_RESOLUTION_DELAY = 2000;
public static final int CLIPBOARD_DELAY = 0;
private static SpiceCommunicator myself = null;

static {
Expand Down Expand Up @@ -401,9 +403,9 @@ public void requestUpdate(boolean incremental) {
}

public void writeClientCutText(String text) {
Log.i(TAG, "writeClientCutText");
Log.i(TAG, "writeClientCutText: clipboard");
if (isInNormalProtocol()) {
SpiceClientCutText(text);
handler.postDelayed(() -> SpiceClientCutText(text), CLIPBOARD_DELAY);
}
}

Expand Down Expand Up @@ -537,16 +539,13 @@ public void onSettingsChanged(int width, int height, int bpp) {

canvas.reallocateDrawable(width, height);

setIsInNormalProtocol(true);
handler.sendEmptyMessage(RemoteClientLibConstants.SPICE_CONNECT_SUCCESS);

if (isRequestingNewDisplayResolution) {
requestResolution(canvas.getDesiredWidth(), canvas.getDesiredHeight());
handler.postDelayed(new Runnable() {
public void run() {
requestResolution(canvas.getDesiredWidth(), canvas.getDesiredHeight());
}
}, 2000);
handler.postDelayed(() -> {
setIsInNormalProtocol(true);
requestResolution(canvas.getDesiredWidth(), canvas.getDesiredHeight());
}, INITIAL_REQUEST_RESOLUTION_DELAY);
}
usbDeviceManager.getUsbDevicePermissions();
}
Expand Down

0 comments on commit 815d8fa

Please sign in to comment.