FreeRDP
Loading...
Searching...
No Matches
LibFreeRDP.java
1/*
2 Android FreeRDP JNI Wrapper
3
4 Copyright 2013 Thincast Technologies GmbH, Author: Martin Fleisz
5
6 This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
7 If a copy of the MPL was not distributed with this file, You can obtain one at
8 http://mozilla.org/MPL/2.0/.
9*/
10
11package com.freerdp.freerdpcore.services;
12
13import android.content.Context;
14import android.graphics.Bitmap;
15import android.net.Uri;
16import android.util.Log;
17
18import androidx.collection.LongSparseArray;
19
20import com.freerdp.freerdpcore.application.GlobalApp;
21import com.freerdp.freerdpcore.application.SessionState;
22import com.freerdp.freerdpcore.domain.BookmarkBase;
23import com.freerdp.freerdpcore.presentation.ApplicationSettingsActivity;
24
25import java.util.ArrayList;
26import java.util.List;
27import java.util.Objects;
28import java.util.regex.Matcher;
29import java.util.regex.Pattern;
30
31public class LibFreeRDP
32{
33 private static final String TAG = "LibFreeRDP";
34 private static EventListener listener;
35 private static boolean mHasH264 = false;
36 private static boolean mHasCameraRedirection = false;
37
38 private static final LongSparseArray<Boolean> mInstanceState = new LongSparseArray<>();
39
40 // FREERDP_CLIENT_KBD_MOD in freerdp/client.h
41 public static final int KBD_MOD_LSHIFT = 0x01;
42 public static final int KBD_MOD_RSHIFT = 0x02;
43 public static final int KBD_MOD_LMENU = 0x04;
44 public static final int KBD_MOD_RMENU = 0x08;
45 public static final int KBD_MOD_LCONTROL = 0x10;
46 public static final int KBD_MOD_RCONTROL = 0x20;
47 public static final int KBD_MOD_LWIN = 0x40;
48 public static final int KBD_MOD_RWIN = 0x80;
49
50 public static final long VERIFY_CERT_FLAG_NONE = 0x00;
51 public static final long VERIFY_CERT_FLAG_LEGACY = 0x02;
52 public static final long VERIFY_CERT_FLAG_REDIRECT = 0x10;
53 public static final long VERIFY_CERT_FLAG_GATEWAY = 0x20;
54 public static final long VERIFY_CERT_FLAG_CHANGED = 0x40;
55 public static final long VERIFY_CERT_FLAG_MISMATCH = 0x80;
56 public static final long VERIFY_CERT_FLAG_MATCH_LEGACY_SHA1 = 0x100;
57 public static final long VERIFY_CERT_FLAG_FP_IS_PEM = 0x200;
58
59 // Keep in sync with android_freerdp.c.
60 public static final int EXPERIMENTAL_REMOTEAPP = 0;
61 public static final int EXPERIMENTAL_CAMERA = 1;
62
63 private static boolean tryLoad(String[] libraries)
64 {
65 boolean success = false;
66 final String LD_PATH = System.getProperty("java.library.path");
67 for (String lib : libraries)
68 {
69 try
70 {
71 Log.v(TAG, "Trying to load library " + lib + " from LD_PATH: " + LD_PATH);
72 System.loadLibrary(lib);
73 success = true;
74 }
75 catch (UnsatisfiedLinkError e)
76 {
77 Log.e(TAG, "Failed to load library " + lib + ": " + e);
78 success = false;
79 break;
80 }
81 }
82
83 return success;
84 }
85
86 private static boolean tryLoad(String library)
87 {
88 return tryLoad(new String[] { library });
89 }
90
91 static
92 {
93 try
94 {
95 System.loadLibrary("freerdp-android");
96
97 /* Load dependent libraries too to trigger JNI_OnLoad calls */
98 String version = freerdp_get_jni_version();
99 String[] versions = version.split("[\\.-]");
100 if (versions.length > 0)
101 {
102 System.loadLibrary("freerdp-client" + versions[0]);
103 System.loadLibrary("freerdp" + versions[0]);
104 System.loadLibrary("winpr" + versions[0]);
105 }
106 Pattern pattern = Pattern.compile("^(\\d+)\\.(\\d+)\\.(\\d+).*");
107 Matcher matcher = pattern.matcher(version);
108 if (!matcher.matches() || (matcher.groupCount() < 3))
109 throw new RuntimeException("APK broken: native library version " + version +
110 " does not meet requirements!");
111 int major = Integer.parseInt(Objects.requireNonNull(matcher.group(1)));
112 int minor = Integer.parseInt(Objects.requireNonNull(matcher.group(2)));
113 int patch = Integer.parseInt(Objects.requireNonNull(matcher.group(3)));
114
115 if (major > 2)
116 mHasH264 = freerdp_has_h264();
117 else if (minor > 5)
118 mHasH264 = freerdp_has_h264();
119 else if ((minor == 5) && (patch >= 1))
120 mHasH264 = freerdp_has_h264();
121 else
122 throw new RuntimeException("APK broken: native library version " + version +
123 " does not meet requirements!");
124 mHasCameraRedirection = freerdp_has_camera_redirection();
125 Log.i(TAG, "Successfully loaded native library. H264 is " +
126 (mHasH264 ? "supported" : "not available") + ", camera redirection is " +
127 (mHasCameraRedirection ? "supported" : "not available"));
128 }
129 catch (UnsatisfiedLinkError e)
130 {
131 Log.e(TAG, "Failed to load library: " + e);
132 throw e;
133 }
134 }
135
136 public static boolean hasH264Support()
137 {
138 return mHasH264;
139 }
140
141 public static boolean hasCameraRedirectionSupport()
142 {
143 return mHasCameraRedirection;
144 }
145
146 private static native boolean freerdp_has_h264();
147
148 private static native boolean freerdp_has_camera_redirection();
149
150 private static native String freerdp_get_jni_version();
151
152 private static native String freerdp_get_version();
153
154 private static native String freerdp_get_build_revision();
155
156 private static native String freerdp_get_build_config();
157
158 private static native long freerdp_new(Context context);
159
160 private static native void freerdp_free(long inst);
161
162 private static native boolean freerdp_parse_arguments(long inst, String[] args);
163
164 private static native boolean freerdp_connect(long inst);
165
166 private static native boolean freerdp_disconnect(long inst);
167
168 private static native void freerdp_set_foreground(long inst, boolean foreground);
169
170 private static native boolean freerdp_update_graphics(long inst, Bitmap bitmap, int x, int y,
171 int width, int height);
172
173 private static native boolean freerdp_send_cursor_event(long inst, int x, int y, int flags);
174
175 private static native boolean freerdp_send_key_event(long inst, int keycode, boolean down);
176
177 private static native boolean freerdp_send_unicodekey_event(long inst, int keycode,
178 boolean down);
179
180 private static native boolean freerdp_send_key_as_unicode_event(long inst, int keycode,
181 String text, int modmask,
182 boolean down);
183
184 private static native boolean freerdp_is_unicode_input_supported(long inst);
185
186 private static native boolean freerdp_send_clipboard_data(long inst, String data);
187
188 private static native boolean freerdp_send_clipboard_image_data(long inst, byte[] data,
189 String mimeType);
190
191 private static native boolean freerdp_send_monitor_layout(long inst, int width, int height);
192
193 private static native String freerdp_get_last_error_string(long inst);
194
195 public static void setEventListener(EventListener l)
196 {
197 listener = l;
198 }
199
200 public static long newInstance(Context context)
201 {
202 return freerdp_new(context);
203 }
204
205 public static void freeInstance(long inst)
206 {
207 synchronized (mInstanceState)
208 {
209 if (mInstanceState.get(inst, false))
210 {
211 freerdp_disconnect(inst);
212 }
213 while (mInstanceState.get(inst, false))
214 {
215 try
216 {
217 mInstanceState.wait();
218 }
219 catch (InterruptedException e)
220 {
221 throw new RuntimeException();
222 }
223 }
224 }
225 freerdp_free(inst);
226 }
227
228 public static boolean connect(long inst)
229 {
230 synchronized (mInstanceState)
231 {
232 if (mInstanceState.get(inst, false))
233 {
234 throw new RuntimeException("instance already connected");
235 }
236 }
237 return freerdp_connect(inst);
238 }
239
240 public static boolean disconnect(long inst)
241 {
242 synchronized (mInstanceState)
243 {
244 if (mInstanceState.get(inst, false))
245 {
246 return freerdp_disconnect(inst);
247 }
248 return true;
249 }
250 }
251
252 public static boolean cancelConnection(long inst)
253 {
254 return freerdp_disconnect(inst);
255 }
256
257 public static void setForeground(long inst, boolean foreground)
258 {
259 freerdp_set_foreground(inst, foreground);
260 }
261
262 private static String addFlag(String name, boolean enabled)
263 {
264 if (enabled)
265 {
266 return "+" + name;
267 }
268 return "-" + name;
269 }
270
271 public static boolean setConnectionInfo(Context context, long inst, BookmarkBase bookmark)
272 {
273 BookmarkBase.ScreenSettings screenSettings = bookmark.getActiveScreenSettings();
274 BookmarkBase.AdvancedSettings advanced = bookmark.getAdvancedSettings();
275 BookmarkBase.DebugSettings debug = bookmark.getDebugSettings();
276
277 String arg;
278 ArrayList<String> args = new ArrayList<>();
279
280 args.add(TAG);
281 args.add("/gdi:sw");
282
283 final String clientName = ApplicationSettingsActivity.getClientName(context);
284 if (!clientName.isEmpty())
285 {
286 args.add("/client-hostname:" + clientName);
287 }
288 String certName = "";
289 if (bookmark.getType() != BookmarkBase.TYPE_MANUAL)
290 {
291 return false;
292 }
293
294 int port = bookmark.getPort();
295 String hostname = bookmark.getHostname();
296
297 args.add("/v:" + hostname);
298 args.add("/port:" + port);
299
300 final int level = advanced.getTlsSecLevel();
301 List<String> tls = new ArrayList<>();
302
303 if (level >= 0)
304 {
305 tls.add("seclevel:" + level);
306 }
307
308 final int tlsMinLevel = advanced.getTlsMinLevel();
309 if (tlsMinLevel >= 0)
310 {
311 tls.add("enforce:" + tlsMinLevel);
312 }
313
314 if (!tls.isEmpty())
315 {
316 StringBuilder sb = new StringBuilder();
317 for (String s : tls)
318 {
319 if (sb.length() > 0)
320 {
321 sb.append(',');
322 }
323 sb.append(s);
324 }
325 args.add("/tls:" + sb);
326 }
327
328 arg = bookmark.getUsername();
329 if (!arg.isEmpty())
330 {
331 args.add("/u:" + arg);
332 }
333 arg = bookmark.getDomain();
334 if (!arg.isEmpty())
335 {
336 args.add("/d:" + arg);
337 }
338 arg = bookmark.getPassword();
339 if (!arg.isEmpty())
340 {
341 args.add("/p:" + arg);
342 }
343
344 args.add(String.format(java.util.Locale.US, "/size:%dx%d", screenSettings.getWidth(),
345 screenSettings.getHeight()));
346 args.add("/bpp:" + screenSettings.getColors());
347
348 if (screenSettings.isCustomScale())
349 {
350 args.add("/scale-desktop:" + screenSettings.getScaleDesktop());
351 args.add("/scale-device:" + screenSettings.getScaleDevice());
352 }
353 else
354 {
355 args.add("/scale:" + screenSettings.getScalePreset());
356 }
357
358 if (advanced.getConsoleMode())
359 {
360 args.add("/admin");
361 }
362
363 if (advanced.getVmConnectMode())
364 {
365 String guid = advanced.getVmConnectGuid();
366 if (!guid.isEmpty())
367 args.add("/vmconnect:" + guid);
368 else
369 args.add("/vmconnect");
370 }
371
372 switch (advanced.getSecurity())
373 {
374 case 3: // NLA
375 args.add("/sec:nla");
376 break;
377 case 2: // TLS
378 args.add("/sec:tls");
379 break;
380 case 1: // RDP
381 args.add("/sec:rdp");
382 break;
383 default:
384 break;
385 }
386
387 if (!certName.isEmpty())
388 {
389 args.add("/cert-name:" + certName);
390 }
391
392 args.add("/network:auto");
393
394 BookmarkBase.PerformanceFlags flags = bookmark.getActivePerformanceFlags();
395 if (flags.getRemoteFX())
396 {
397 args.add("/rfx");
398 }
399
400 if (flags.getGfx())
401 {
402 if (flags.getH264() && mHasH264)
403 {
404 args.add("/gfx:AVC444,AVC420,RFX,progressive");
405 }
406 else
407 {
408 args.add("/gfx");
409 }
410 }
411
412 args.add(addFlag("wallpaper", flags.getWallpaper()));
413 args.add(addFlag("window-drag", flags.getFullWindowDrag()));
414 args.add(addFlag("menu-anims", flags.getMenuAnimations()));
415 args.add(addFlag("themes", flags.getTheming()));
416 args.add(addFlag("fonts", flags.getFontSmoothing()));
417 args.add(addFlag("aero", flags.getDesktopComposition()));
418
419 if (!advanced.getRemoteProgram().isEmpty())
420 {
421 args.add("/app:program:" + advanced.getRemoteProgram());
422 if (!advanced.getWorkDir().isEmpty())
423 args.add("/app:workdir:" + advanced.getWorkDir());
424 }
425 else
426 {
427 if (!advanced.getAlternateShell().isEmpty())
428 args.add("/shell:" + advanced.getAlternateShell());
429 if (!advanced.getWorkDir().isEmpty())
430 args.add("/shell-dir:" + advanced.getWorkDir());
431 }
432
433 args.add(addFlag("async-channels", debug.getAsyncChannel()));
434 args.add(addFlag("async-update", debug.getAsyncUpdate()));
435
436 if (advanced.getRedirectSDCard())
437 {
438 String path = android.os.Environment.getExternalStorageDirectory().getPath();
439 args.add("/drive:sdcard," + path);
440 }
441
442 String info = advanced.getLoadBalanceInfo();
443 if (!info.isEmpty())
444 {
445 args.add("/load-balance-info:" + info);
446 }
447 args.add("/clipboard");
448 args.add("/disp");
449
450 if (advanced.getRedirectPrinter())
451 args.add("/printer:aFreeRDP Print,Microsoft Print to PDF,default");
452
453 // Gateway enabled?
454 if (bookmark.getType() == BookmarkBase.TYPE_MANUAL && bookmark.getEnableGatewaySettings())
455 {
456 BookmarkBase.GatewaySettings gateway = bookmark.getGatewaySettings();
457
458 StringBuilder carg = new StringBuilder();
459 carg.append(String.format(java.util.Locale.US, "/gateway:g:%s:%d",
460 gateway.getHostname(), gateway.getPort()));
461
462 arg = gateway.getUsername();
463 if (!arg.isEmpty())
464 {
465 carg.append(",u:" + arg);
466 }
467 arg = gateway.getDomain();
468 if (!arg.isEmpty())
469 {
470 carg.append(",d:" + arg);
471 }
472 arg = gateway.getPassword();
473 if (!arg.isEmpty())
474 {
475 carg.append(",p:" + arg);
476 }
477 args.add(carg.toString());
478 }
479
480 /* 0 ... local
481 1 ... remote
482 2 ... disable */
483 args.add("/audio-mode:" + advanced.getRedirectSound());
484 if (advanced.getRedirectSound() == 0)
485 {
486 args.add("/sound");
487 }
488
489 if (advanced.getRedirectMicrophone())
490 {
491 args.add("/microphone");
492 }
493
494 if (advanced.getRedirectCamera() && mHasCameraRedirection)
495 {
496 args.add("/dvc:rdpecam");
497 }
498
499 if (ApplicationSettingsActivity.getAutoReconnect(context))
500 {
501 args.add("/auto-reconnect");
502 }
503
504 args.add("/kbd:unicode:on");
505 args.add("/cert:ignore");
506 args.add("/log-level:" + debug.getDebugLevel());
507 String[] arrayArgs = args.toArray(new String[0]);
508 return freerdp_parse_arguments(inst, arrayArgs);
509 }
510
511 public static boolean setConnectionInfo(Context context, long inst, Uri openUri)
512 {
513 ArrayList<String> args = new ArrayList<>();
514
515 // Parse URI from query string. Same key overwrite previous one
516 // freerdp://user@ip:port/connect?sound=&rfx=&p=password&clipboard=%2b&themes=-
517
518 // Now we only support Software GDI
519 args.add(TAG);
520 args.add("/gdi:sw");
521
522 final String clientName = ApplicationSettingsActivity.getClientName(context);
523 if (!clientName.isEmpty())
524 {
525 args.add("/client-hostname:" + clientName);
526 }
527
528 // Parse hostname and port. Set to 'v' argument
529 String hostname = openUri.getHost();
530 int port = openUri.getPort();
531 if (hostname != null)
532 {
533 hostname = hostname + ((port == -1) ? "" : (":" + port));
534 args.add("/v:" + hostname);
535 }
536
537 String user = openUri.getUserInfo();
538 if (user != null)
539 {
540 args.add("/u:" + user);
541 }
542
543 for (String key : openUri.getQueryParameterNames())
544 {
545 String value = openUri.getQueryParameter(key);
546
547 if (value.isEmpty())
548 {
549 // Query: key=
550 // To freerdp argument: /key
551 args.add("/" + key);
552 }
553 else if (value.equals("-") || value.equals("+"))
554 {
555 // Query: key=- or key=+
556 // To freerdp argument: -key or +key
557 args.add(value + key);
558 }
559 else
560 {
561 // Query: key=value
562 // To freerdp argument: /key:value
563 if (key.equals("drive") && value.equals("sdcard"))
564 {
565 // Special for sdcard redirect
566 String path = android.os.Environment.getExternalStorageDirectory().getPath();
567 value = "sdcard," + path;
568 }
569
570 args.add("/" + key + ":" + value);
571 }
572 }
573
574 String[] arrayArgs = args.toArray(new String[0]);
575 return freerdp_parse_arguments(inst, arrayArgs);
576 }
577
578 public static boolean updateGraphics(long inst, Bitmap bitmap, int x, int y, int width,
579 int height)
580 {
581 return freerdp_update_graphics(inst, bitmap, x, y, width, height);
582 }
583
584 public static boolean sendCursorEvent(long inst, int x, int y, int flags)
585 {
586 return freerdp_send_cursor_event(inst, x, y, flags);
587 }
588
589 public static boolean sendKeyEvent(long inst, int keycode, boolean down)
590 {
591 return freerdp_send_key_event(inst, keycode, down);
592 }
593
594 public static boolean sendUnicodeKeyEvent(long inst, int keycode, boolean down)
595 {
596 return freerdp_send_unicodekey_event(inst, keycode, down);
597 }
598
599 public static boolean sendKeyAsUnicodeEvent(long inst, int keycode, int unicode, int modmask,
600 boolean down)
601 {
602 // The character as UTF-16. 0, a lone surrogate or anything past U+10FFFF goes as an empty
603 // string, and the library then sends the key's scancode.
604 String text = "";
605 if (unicode > 0 && Character.isValidCodePoint(unicode) &&
606 Character.getType(unicode) != Character.SURROGATE)
607 text = new String(Character.toChars(unicode));
608 return freerdp_send_key_as_unicode_event(inst, keycode, text, modmask, down);
609 }
610
611 public static boolean isUnicodeInputSupported(long inst)
612 {
613 return freerdp_is_unicode_input_supported(inst);
614 }
615
616 public static boolean sendClipboardData(long inst, String data)
617 {
618 return freerdp_send_clipboard_data(inst, data);
619 }
620
621 public static boolean sendClipboardImageData(long inst, byte[] data, String mimeType)
622 {
623 return freerdp_send_clipboard_image_data(inst, data, mimeType);
624 }
625
626 public static boolean sendMonitorLayout(long inst, int width, int height)
627 {
628 return freerdp_send_monitor_layout(inst, width, height);
629 }
630
631 private static void OnConnectionSuccess(long inst)
632 {
633 if (listener != null)
634 listener.OnConnectionSuccess(inst);
635 synchronized (mInstanceState)
636 {
637 mInstanceState.append(inst, true);
638 mInstanceState.notifyAll();
639 }
640 }
641
642 private static void OnConnectionFailure(long inst)
643 {
644 if (listener != null)
645 listener.OnConnectionFailure(inst);
646 synchronized (mInstanceState)
647 {
648 mInstanceState.remove(inst);
649 mInstanceState.notifyAll();
650 }
651 }
652
653 private static void OnPreConnect(long inst)
654 {
655 if (listener != null)
656 listener.OnPreConnect(inst);
657 }
658
659 private static void OnDisconnecting(long inst)
660 {
661 if (listener != null)
662 listener.OnDisconnecting(inst);
663 }
664
665 private static void OnDisconnected(long inst)
666 {
667 if (listener != null)
668 listener.OnDisconnected(inst);
669 synchronized (mInstanceState)
670 {
671 mInstanceState.remove(inst);
672 mInstanceState.notifyAll();
673 }
674 }
675
676 private static void OnSettingsChanged(long inst, int width, int height, int bpp)
677 {
678 SessionState s = GlobalApp.getSession(inst);
679 if (s == null)
680 return;
681 UIEventListener uiEventListener = s.getUIEventListener();
682 if (uiEventListener != null)
683 uiEventListener.OnSettingsChanged(width, height, bpp);
684 }
685
686 private static boolean OnAuthenticate(long inst, StringBuilder username, StringBuilder domain,
687 StringBuilder password)
688 {
689 SessionState s = GlobalApp.getSession(inst);
690 if (s == null)
691 return false;
692 UIEventListener uiEventListener = s.getUIEventListener();
693 if (uiEventListener != null)
694 return uiEventListener.OnAuthenticate(username, domain, password);
695 return false;
696 }
697
698 private static boolean OnGatewayAuthenticate(long inst, StringBuilder username,
699 StringBuilder domain, StringBuilder password)
700 {
701 SessionState s = GlobalApp.getSession(inst);
702 if (s == null)
703 return false;
704 UIEventListener uiEventListener = s.getUIEventListener();
705 if (uiEventListener != null)
706 return uiEventListener.OnGatewayAuthenticate(username, domain, password);
707 return false;
708 }
709
710 private static int OnVerifyCertificateEx(long inst, String host, long port, String commonName,
711 String subject, String issuer, String fingerprint,
712 long flags)
713 {
714 SessionState s = GlobalApp.getSession(inst);
715 if (s == null)
716 return 0;
717 UIEventListener uiEventListener = s.getUIEventListener();
718 if (uiEventListener != null)
719 return uiEventListener.OnVerifiyCertificateEx(host, port, commonName, subject, issuer,
720 fingerprint, flags);
721 return 0;
722 }
723
724 private static int OnVerifyChangedCertificateEx(long inst, String host, long port,
725 String commonName, String subject,
726 String issuer, String fingerprint,
727 String oldSubject, String oldIssuer,
728 String oldFingerprint, long flags)
729 {
730 SessionState s = GlobalApp.getSession(inst);
731 if (s == null)
732 return 0;
733 UIEventListener uiEventListener = s.getUIEventListener();
734 if (uiEventListener != null)
735 return uiEventListener.OnVerifyChangedCertificateEx(host, port, commonName, subject,
736 issuer, fingerprint, oldSubject,
737 oldIssuer, oldFingerprint, flags);
738 return 0;
739 }
740
741 private static boolean OnExperimentalFeature(long inst, int feature)
742 {
743 SessionState s = GlobalApp.getSession(inst);
744 if (s == null)
745 return true;
746 UIEventListener uiEventListener = s.getUIEventListener();
747 if (uiEventListener == null)
748 return true;
749 return uiEventListener.OnExperimentalFeature(feature);
750 }
751
752 private static void OnGraphicsUpdate(long inst, int x, int y, int width, int height)
753 {
754 SessionState s = GlobalApp.getSession(inst);
755 if (s == null)
756 return;
757 UIEventListener uiEventListener = s.getUIEventListener();
758 if (uiEventListener != null)
759 uiEventListener.OnGraphicsUpdate(x, y, width, height);
760 }
761
762 private static void OnGraphicsResize(long inst, int width, int height, int bpp)
763 {
764 SessionState s = GlobalApp.getSession(inst);
765 if (s == null)
766 return;
767 UIEventListener uiEventListener = s.getUIEventListener();
768 if (uiEventListener != null)
769 uiEventListener.OnGraphicsResize(width, height, bpp);
770 }
771
772 private static void OnRemoteClipboardChanged(long inst, String data)
773 {
774 SessionState s = GlobalApp.getSession(inst);
775 if (s == null)
776 return;
777 UIEventListener uiEventListener = s.getUIEventListener();
778 if (uiEventListener != null)
779 uiEventListener.OnRemoteClipboardChanged(data);
780 }
781
782 private static void OnRemoteClipboardImageChanged(long inst, byte[] data)
783 {
784 SessionState s = GlobalApp.getSession(inst);
785 if (s == null)
786 return;
787 UIEventListener uiEventListener = s.getUIEventListener();
788 if (uiEventListener != null)
789 uiEventListener.OnRemoteClipboardImageChanged(data);
790 }
791
792 private static void OnPointerSet(long inst, int[] pixels, int width, int height, int hotX,
793 int hotY)
794 {
795 SessionState s = GlobalApp.getSession(inst);
796 if (s == null)
797 return;
798 UIEventListener uiEventListener = s.getUIEventListener();
799 if (uiEventListener != null)
800 uiEventListener.OnPointerSet(pixels, width, height, hotX, hotY);
801 }
802
803 private static void OnPointerSetNull(long inst)
804 {
805 SessionState s = GlobalApp.getSession(inst);
806 if (s == null)
807 return;
808 UIEventListener uiEventListener = s.getUIEventListener();
809 if (uiEventListener != null)
810 uiEventListener.OnPointerSetNull();
811 }
812
813 private static void OnReconnecting(long inst)
814 {
815 SessionState s = GlobalApp.getSession(inst);
816 if (s == null)
817 return;
818 UIEventListener uiEventListener = s.getUIEventListener();
819 if (uiEventListener != null)
820 uiEventListener.OnReconnecting();
821 }
822
823 private static void OnPointerSetDefault(long inst)
824 {
825 SessionState s = GlobalApp.getSession(inst);
826 if (s == null)
827 return;
828 UIEventListener uiEventListener = s.getUIEventListener();
829 if (uiEventListener != null)
830 uiEventListener.OnPointerSetDefault();
831 }
832
833 private static void OnRailWindowUpdate(long inst, long windowId, int width, int height,
834 int[] pixels)
835 {
836 SessionState s = GlobalApp.getSession(inst);
837 if (s == null)
838 return;
839 UIEventListener uiEventListener = s.getUIEventListener();
840 if (uiEventListener != null)
841 uiEventListener.OnRailWindowUpdate(windowId, width, height, pixels);
842 }
843
844 private static void OnRailWindowMove(long inst, long windowId, int x, int y, int w, int h)
845 {
846 SessionState s = GlobalApp.getSession(inst);
847 if (s == null)
848 return;
849 UIEventListener uiEventListener = s.getUIEventListener();
850 if (uiEventListener != null)
851 uiEventListener.OnRailWindowMove(windowId, x, y, w, h);
852 }
853
854 private static void OnRailWindowHide(long inst, long windowId)
855 {
856 SessionState s = GlobalApp.getSession(inst);
857 if (s == null)
858 return;
859 UIEventListener uiEventListener = s.getUIEventListener();
860 if (uiEventListener != null)
861 uiEventListener.OnRailWindowHide(windowId);
862 }
863
864 private static void OnRailWindowDestroy(long inst, long windowId)
865 {
866 SessionState s = GlobalApp.getSession(inst);
867 if (s == null)
868 return;
869 UIEventListener uiEventListener = s.getUIEventListener();
870 if (uiEventListener != null)
871 uiEventListener.OnRailWindowDestroy(windowId);
872 }
873
874 private static void OnRailSessionEnd(long inst)
875 {
876 SessionState s = GlobalApp.getSession(inst);
877 if (s == null)
878 return;
879 UIEventListener uiEventListener = s.getUIEventListener();
880 if (uiEventListener != null)
881 uiEventListener.OnRailSessionEnd();
882 }
883
884 private static void OnRailMonitoredDesktop(long inst, long[] windowIds, long activeWindowId)
885 {
886 SessionState s = GlobalApp.getSession(inst);
887 if (s == null)
888 return;
889 UIEventListener uiEventListener = s.getUIEventListener();
890 if (uiEventListener != null)
891 uiEventListener.OnRailMonitoredDesktop(windowIds, activeWindowId);
892 }
893
894 public static String getVersion()
895 {
896 return freerdp_get_version();
897 }
898
899 public interface EventListener
900 {
901 void OnPreConnect(long instance);
902
903 void OnConnectionSuccess(long instance);
904
905 void OnConnectionFailure(long instance);
906
907 void OnDisconnecting(long instance);
908
909 void OnDisconnected(long instance);
910 }
911
912 public interface UIEventListener
913 {
914 void OnSettingsChanged(int width, int height, int bpp);
915
916 void OnReconnecting();
917
918 boolean OnAuthenticate(StringBuilder username, StringBuilder domain,
919 StringBuilder password);
920
921 boolean OnGatewayAuthenticate(StringBuilder username, StringBuilder domain,
922 StringBuilder password);
923
924 int OnVerifiyCertificateEx(String host, long port, String commonName, String subject, String issuer,
925 String fingerprint, long flags);
926
927 int OnVerifyChangedCertificateEx(String host, long port, String commonName, String subject, String issuer,
928 String fingerprint, String oldSubject, String oldIssuer,
929 String oldFingerprint, long flags);
930
931 boolean OnExperimentalFeature(int feature);
932
933 void OnGraphicsUpdate(int x, int y, int width, int height);
934
935 void OnGraphicsResize(int width, int height, int bpp);
936
937 void OnRemoteClipboardChanged(String data);
938
939 void OnRemoteClipboardImageChanged(byte[] data);
940
941 void OnPointerSet(int[] pixels, int width, int height, int hotX, int hotY);
942
943 void OnPointerSetNull();
944
945 void OnPointerSetDefault();
946
947 void OnRailWindowUpdate(long windowId, int width, int height, int[] pixels);
948
949 void OnRailWindowMove(long windowId, int x, int y, int w, int h);
950
951 void OnRailWindowHide(long windowId);
952
953 void OnRailWindowDestroy(long windowId);
954
955 void OnRailSessionEnd();
956
957 void OnRailMonitoredDesktop(long[] windowIds, long activeWindowId);
958 }
959}