FreeRDP
Loading...
Searching...
No Matches
BookmarkBase.java
1/*
2 Defines base attributes of a bookmark object
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.domain;
12
13import android.content.SharedPreferences;
14import android.os.Parcel;
15import android.os.Parcelable;
16
17import androidx.annotation.NonNull;
18
19import java.util.Locale;
20import java.util.Objects;
21
22public class BookmarkBase implements Parcelable, Cloneable
23{
24 private static final String keyLabel = "bookmark.label";
25 private static final String keyUsername = "bookmark.username";
26 private static final String keyPassword = "bookmark.password";
27 private static final String keyDomain = "bookmark.domain";
28
29 private static final String keyColors = "bookmark.colors";
30 private static final String keyResolution = "bookmark.resolution";
31 private static final String keyWidth = "bookmark.width";
32 private static final String keyScaleMode = "bookmark.scale_mode";
33 private static final String keyScaleDesktop = "bookmark.scale_desktop";
34 private static final String keyScaleDevice = "bookmark.scale_device";
35 private static final String keyHeight = "bookmark.height";
36
37 private static final String keyRFX = "bookmark.perf_remotefx";
38 private static final String keyGFX = "bookmark.perf_gfx";
39 private static final String keyH264 = "bookmark.perf_gfx_h264";
40 private static final String keyFlagWallpaper = "bookmark.perf_wallpaper";
41 private static final String keyFlagFonts = "bookmark.perf_font_smoothing";
42 private static final String keyFlagComposition = "bookmark.perf_desktop_composition";
43 private static final String keyFlagWindowDrag = "bookmark.perf_window_dragging";
44 private static final String keyFlagMenuAnim = "bookmark.perf_menu_animation";
45 private static final String keyFlagTheming = "bookmark.perf_themes";
46
47 private static final String keyTlsSecLevel = "bookmark.tlsSecLevel";
48 private static final String keyTlsMinLevel = "bookmark.tlsMinLevel";
49 private static final String keyLoadBalanceInfo = "bookmark.loadBalanceInfo";
50 private static final String keyRedirectSDCard = "bookmark.redirect_sdcard";
51 private static final String keySound = "bookmark.redirect_sound";
52 private static final String keyMicrophone = "bookmark.redirect_microphone";
53 private static final String keyPrinter = "bookmark.redirect_printer";
54 private static final String keySecurity = "bookmark.security";
55 private static final String keyRemoteApp = "bookmark.remote_program";
56 private static final String keyWorkDir = "bookmark.work_dir";
57 private static final String keyConsoleMode = "bookmark.console_mode";
58 private static final String keyVmConnectMode = "bookmark.vmconnect_mode";
59 private static final String keyVmConnectGuid = "bookmark.vmconnect_guid";
60
61 private static final String keyAsyncChannel = "bookmark.async_channel";
62 private static final String keyAsyncUpdate = "bookmark.async_update";
63 private static final String keyDebugLevel = "bookmark.debug_level";
64
65 private static final String keyHostname = "bookmark.hostname";
66 private static final String keyPort = "bookmark.port";
67 private static final String keyGatewayEnabled = "bookmark.enable_gateway_settings";
68 private static final String keyGatewayHostname = "bookmark.gateway_hostname";
69 private static final String keyGatewayPort = "bookmark.gateway_port";
70 private static final String keyGatewyUser = "bookmark.gateway_username";
71 private static final String keyGatewayPassword = "bookmark.gateway_password";
72 private static final String keyGatewayDomain = "bookmark.gateway_domain";
73
74 public static final int TYPE_INVALID = -1;
75 public static final int TYPE_MANUAL = 1;
76 public static final int TYPE_QUICKCONNECT = 2;
77 public static final int TYPE_CUSTOM_BASE = 1000;
78 public static final Parcelable.Creator<BookmarkBase> CREATOR =
79 new Parcelable.Creator<BookmarkBase>() {
80 public BookmarkBase createFromParcel(Parcel in)
81 {
82 return new BookmarkBase(in);
83 }
84
85 @Override public BookmarkBase[] newArray(int size)
86 {
87 return new BookmarkBase[size];
88 }
89 };
90 protected int type = TYPE_MANUAL;
91 private long id = -1;
92
93 @NonNull private String label = "";
94
95 @NonNull private String username = "";
96
97 @NonNull private String password = "";
98
99 @NonNull private String domain = "";
100
101 @NonNull private ScreenSettings screenSettings = new ScreenSettings();
102
103 @NonNull private PerformanceFlags performanceFlags = new PerformanceFlags();
104
105 @NonNull private AdvancedSettings advancedSettings = new AdvancedSettings();
106
107 @NonNull private DebugSettings debugSettings = new DebugSettings();
108
109 @NonNull private String hostname = "";
110 private int port = 3389;
111 private boolean enableGatewaySettings = false;
112
113 @NonNull private GatewaySettings gatewaySettings = new GatewaySettings();
114 private boolean directConnect = false;
115
116 public BookmarkBase(Parcel parcel)
117 {
118 type = parcel.readInt();
119 id = parcel.readLong();
120 label = Objects.requireNonNull(parcel.readString());
121 username = Objects.requireNonNull(parcel.readString());
122 password = Objects.requireNonNull(parcel.readString());
123 domain = Objects.requireNonNull(parcel.readString());
124
125 screenSettings =
126 Objects.requireNonNull(parcel.readParcelable(ScreenSettings.class.getClassLoader()));
127 performanceFlags =
128 Objects.requireNonNull(parcel.readParcelable(PerformanceFlags.class.getClassLoader()));
129 advancedSettings =
130 Objects.requireNonNull(parcel.readParcelable(AdvancedSettings.class.getClassLoader()));
131 debugSettings =
132 Objects.requireNonNull(parcel.readParcelable(DebugSettings.class.getClassLoader()));
133 hostname = Objects.requireNonNull(parcel.readString());
134 port = parcel.readInt();
135 enableGatewaySettings = (parcel.readInt() == 1);
136 gatewaySettings =
137 Objects.requireNonNull(parcel.readParcelable(GatewaySettings.class.getClassLoader()));
138 directConnect = (parcel.readInt() == 1);
139 }
140
141 public BookmarkBase()
142 {
143 }
144
145 public int getType()
146 {
147 return type;
148 }
149
150 public void setType(int type)
151 {
152 this.type = type;
153 }
154
155 public long getId()
156 {
157 return id;
158 }
159
160 public void setId(long id)
161 {
162 this.id = id;
163 }
164
165 @NonNull public String getLabel()
166 {
167 return label;
168 }
169
170 public void setLabel(@NonNull String label)
171 {
172 this.label = label;
173 }
174
175 @NonNull public String getUsername()
176 {
177 return username;
178 }
179
180 public void setUsername(@NonNull String username)
181 {
182 this.username = username;
183 }
184
185 @NonNull public String getPassword()
186 {
187 return password;
188 }
189
190 public void setPassword(@NonNull String password)
191 {
192 this.password = password;
193 }
194
195 @NonNull public String getDomain()
196 {
197 return domain;
198 }
199
200 public void setDomain(@NonNull String domain)
201 {
202 this.domain = domain;
203 }
204
205 @NonNull public ScreenSettings getScreenSettings()
206 {
207 return screenSettings;
208 }
209
210 @NonNull public PerformanceFlags getPerformanceFlags()
211 {
212 return performanceFlags;
213 }
214
215 @NonNull public AdvancedSettings getAdvancedSettings()
216 {
217 return advancedSettings;
218 }
219
220 @NonNull public DebugSettings getDebugSettings()
221 {
222 return debugSettings;
223 }
224
225 @NonNull public String getHostname()
226 {
227 return hostname;
228 }
229
230 public void setHostname(@NonNull String hostname)
231 {
232 this.hostname = hostname;
233 }
234
235 public int getPort()
236 {
237 return port;
238 }
239
240 public void setPort(int port)
241 {
242 this.port = port;
243 }
244
245 public boolean getEnableGatewaySettings()
246 {
247 return enableGatewaySettings;
248 }
249
250 public void setEnableGatewaySettings(boolean enableGatewaySettings)
251 {
252 this.enableGatewaySettings = enableGatewaySettings;
253 }
254
255 @NonNull public GatewaySettings getGatewaySettings()
256 {
257 return gatewaySettings;
258 }
259
260 public boolean isDirectConnect()
261 {
262 return directConnect;
263 }
264
265 public void setDirectConnect(boolean directConnect)
266 {
267 this.directConnect = directConnect;
268 }
269
270 @NonNull public ScreenSettings getActiveScreenSettings()
271 {
272 return screenSettings;
273 }
274
275 @NonNull public PerformanceFlags getActivePerformanceFlags()
276 {
277 return performanceFlags;
278 }
279
280 @Override public int describeContents()
281 {
282 return 0;
283 }
284
285 @Override public void writeToParcel(Parcel out, int flags)
286 {
287 out.writeInt(type);
288 out.writeLong(id);
289 out.writeString(label);
290 out.writeString(username);
291 out.writeString(password);
292 out.writeString(domain);
293
294 out.writeParcelable(screenSettings, flags);
295 out.writeParcelable(performanceFlags, flags);
296 out.writeParcelable(advancedSettings, flags);
297 out.writeParcelable(debugSettings, flags);
298 out.writeString(hostname);
299 out.writeInt(port);
300 out.writeBoolean(enableGatewaySettings);
301 out.writeParcelable(gatewaySettings, flags);
302 out.writeBoolean(directConnect);
303 }
304
305 // write to shared preferences
306 public void writeToSharedPreferences(@NonNull SharedPreferences sharedPrefs)
307 {
308 Locale locale = Locale.ENGLISH;
309
310 SharedPreferences.Editor editor = sharedPrefs.edit();
311 editor.clear();
312 editor.putString(keyLabel, label);
313 editor.putString(keyUsername, username);
314 editor.putString(keyPassword, password);
315 editor.putString(keyDomain, domain);
316
317 editor.putInt(keyColors, screenSettings.getColors());
318 editor.putString(keyResolution, screenSettings.getResolutionString().toLowerCase(locale));
319 editor.putInt(keyWidth, screenSettings.getWidth());
320 editor.putInt(keyHeight, screenSettings.getHeight());
321 editor.putString(keyScaleMode, screenSettings.getScaleMode());
322 editor.putInt(keyScaleDesktop, screenSettings.getScaleDesktop());
323 editor.putInt(keyScaleDevice, screenSettings.getScaleDevice());
324
325 editor.putBoolean(keyRFX, performanceFlags.getRemoteFX());
326 editor.putBoolean(keyGFX, performanceFlags.getGfx());
327 editor.putBoolean(keyH264, performanceFlags.getH264());
328 editor.putBoolean(keyFlagWallpaper, performanceFlags.getWallpaper());
329 editor.putBoolean(keyFlagFonts, performanceFlags.getFontSmoothing());
330 editor.putBoolean(keyFlagComposition, performanceFlags.getDesktopComposition());
331 editor.putBoolean(keyFlagWindowDrag, performanceFlags.getFullWindowDrag());
332 editor.putBoolean(keyFlagMenuAnim, performanceFlags.getMenuAnimations());
333 editor.putBoolean(keyFlagTheming, performanceFlags.getTheming());
334
335 editor.putInt(keyTlsSecLevel, advancedSettings.tlsSecLevel);
336 editor.putInt(keyTlsMinLevel, advancedSettings.tlsMinLevel);
337
338 editor.putString(keyLoadBalanceInfo, advancedSettings.getLoadBalanceInfo());
339 editor.putBoolean(keyRedirectSDCard, advancedSettings.getRedirectSDCard());
340 editor.putInt(keySound, advancedSettings.getRedirectSound());
341 editor.putBoolean(keyMicrophone, advancedSettings.getRedirectMicrophone());
342 editor.putBoolean(keyPrinter, advancedSettings.getRedirectPrinter());
343 editor.putInt(keySecurity, advancedSettings.getSecurity());
344 editor.putString(keyRemoteApp, advancedSettings.getRemoteProgram());
345 editor.putString(keyWorkDir, advancedSettings.getWorkDir());
346 editor.putBoolean(keyConsoleMode, advancedSettings.getConsoleMode());
347 editor.putBoolean(keyVmConnectMode, advancedSettings.getVmConnectMode());
348 editor.putString(keyVmConnectGuid, advancedSettings.getVmConnectGuid());
349
350 editor.putBoolean(keyAsyncChannel, debugSettings.getAsyncChannel());
351 editor.putBoolean(keyAsyncUpdate, debugSettings.getAsyncUpdate());
352 editor.putString(keyDebugLevel, debugSettings.getDebugLevel());
353
354 editor.putString(keyHostname, hostname);
355 editor.putInt(keyPort, port);
356 editor.putBoolean(keyGatewayEnabled, enableGatewaySettings);
357 editor.putString(keyGatewayHostname, gatewaySettings.getHostname());
358 editor.putInt(keyGatewayPort, gatewaySettings.getPort());
359 editor.putString(keyGatewyUser, gatewaySettings.getUsername());
360 editor.putString(keyGatewayPassword, gatewaySettings.getPassword());
361 editor.putString(keyGatewayDomain, gatewaySettings.getDomain());
362
363 editor.apply();
364 }
365
366 // read from shared preferences
367 public void readFromSharedPreferences(@NonNull SharedPreferences sharedPrefs)
368 {
369 label = sharedPrefs.getString(keyLabel, "");
370 username = sharedPrefs.getString(keyUsername, "");
371 password = sharedPrefs.getString(keyPassword, "");
372 domain = sharedPrefs.getString(keyDomain, "");
373
374 screenSettings.setColors(sharedPrefs.getInt(keyColors, 32));
375 screenSettings.setResolution(sharedPrefs.getString(keyResolution, "automatic"),
376 sharedPrefs.getInt(keyWidth, 800),
377 sharedPrefs.getInt(keyHeight, 600));
378 screenSettings.setScale(sharedPrefs.getString(keyScaleMode, "100"),
379 sharedPrefs.getInt(keyScaleDesktop, 100),
380 sharedPrefs.getInt(keyScaleDevice, 100));
381
382 performanceFlags.setRemoteFX(sharedPrefs.getBoolean(keyRFX, false));
383 performanceFlags.setGfx(sharedPrefs.getBoolean(keyGFX, true));
384 performanceFlags.setH264(sharedPrefs.getBoolean(keyH264, true));
385 performanceFlags.setWallpaper(sharedPrefs.getBoolean(keyFlagWallpaper, false));
386 performanceFlags.setFontSmoothing(sharedPrefs.getBoolean(keyFlagFonts, false));
387 performanceFlags.setDesktopComposition(sharedPrefs.getBoolean(keyFlagComposition, false));
388 performanceFlags.setFullWindowDrag(sharedPrefs.getBoolean(keyFlagWindowDrag, false));
389 performanceFlags.setMenuAnimations(sharedPrefs.getBoolean(keyFlagMenuAnim, false));
390 performanceFlags.setTheming(sharedPrefs.getBoolean(keyFlagTheming, false));
391
392 advancedSettings.setTlsSecLevel(sharedPrefs.getInt(keyTlsSecLevel, -1));
393 advancedSettings.setTlsMinLevel(sharedPrefs.getInt(keyTlsMinLevel, -1));
394
395 advancedSettings.setLoadBalanceInfo(sharedPrefs.getString(keyLoadBalanceInfo, ""));
396 advancedSettings.setRedirectSDCard(sharedPrefs.getBoolean(keyRedirectSDCard, false));
397 advancedSettings.setRedirectSound(sharedPrefs.getInt(keySound, 0));
398 advancedSettings.setRedirectMicrophone(sharedPrefs.getBoolean(keyMicrophone, false));
399 advancedSettings.setRedirectPrinter(sharedPrefs.getBoolean(keyPrinter, false));
400 advancedSettings.setSecurity(sharedPrefs.getInt(keySecurity, 0));
401 advancedSettings.setRemoteProgram(sharedPrefs.getString(keyRemoteApp, ""));
402 advancedSettings.setWorkDir(sharedPrefs.getString(keyWorkDir, ""));
403 advancedSettings.setConsoleMode(sharedPrefs.getBoolean(keyConsoleMode, false));
404 advancedSettings.setVmConnectMode(sharedPrefs.getBoolean(keyVmConnectMode, false));
405 advancedSettings.setVmConnectGuid(sharedPrefs.getString(keyVmConnectGuid, ""));
406
407 debugSettings.setAsyncChannel(sharedPrefs.getBoolean(keyAsyncChannel, true));
408 debugSettings.setAsyncUpdate(sharedPrefs.getBoolean(keyAsyncUpdate, true));
409 debugSettings.setDebugLevel(sharedPrefs.getString(keyDebugLevel, "INFO"));
410
411 hostname = sharedPrefs.getString(keyHostname, "");
412 port = sharedPrefs.getInt(keyPort, 3389);
413 enableGatewaySettings = sharedPrefs.getBoolean(keyGatewayEnabled, false);
414 gatewaySettings.setHostname(sharedPrefs.getString(keyGatewayHostname, ""));
415 gatewaySettings.setPort(sharedPrefs.getInt(keyGatewayPort, 443));
416 gatewaySettings.setUsername(sharedPrefs.getString(keyGatewyUser, ""));
417 gatewaySettings.setPassword(sharedPrefs.getString(keyGatewayPassword, ""));
418 gatewaySettings.setDomain(sharedPrefs.getString(keyGatewayDomain, ""));
419 }
420
421 @Override public Object clone() throws CloneNotSupportedException
422 {
423 return super.clone();
424 }
425
426 // performance flags
427 public static class PerformanceFlags implements Parcelable
428 {
429 public static final Parcelable.Creator<PerformanceFlags> CREATOR =
430 new Parcelable.Creator<PerformanceFlags>() {
431 @NonNull public PerformanceFlags createFromParcel(Parcel in)
432 {
433 return new PerformanceFlags(in);
434 }
435
436 @NonNull @Override public PerformanceFlags[] newArray(int size)
437 {
438 return new PerformanceFlags[size];
439 }
440 };
441 private boolean remotefx = true;
442 private boolean gfx = true;
443 private boolean h264 = true;
444 private boolean wallpaper = true;
445 private boolean theming = true;
446 private boolean fullWindowDrag = true;
447 private boolean menuAnimations = true;
448 private boolean fontSmoothing = true;
449 private boolean desktopComposition = true;
450
451 public PerformanceFlags()
452 {
453 }
454
455 public PerformanceFlags(Parcel parcel)
456 {
457 remotefx = parcel.readBoolean();
458 gfx = parcel.readBoolean();
459 h264 = parcel.readBoolean();
460 wallpaper = parcel.readBoolean();
461 theming = parcel.readBoolean();
462 fullWindowDrag = parcel.readBoolean();
463 menuAnimations = parcel.readBoolean();
464 fontSmoothing = parcel.readBoolean();
465 desktopComposition = parcel.readBoolean();
466 }
467
468 public boolean getRemoteFX()
469 {
470 return remotefx;
471 }
472
473 public void setRemoteFX(boolean remotefx)
474 {
475 this.remotefx = remotefx;
476 }
477
478 public boolean getGfx()
479 {
480 return gfx;
481 }
482
483 public void setGfx(boolean gfx)
484 {
485 this.gfx = gfx;
486 }
487
488 public boolean getH264()
489 {
490 return h264;
491 }
492
493 public void setH264(boolean h264)
494 {
495 this.h264 = h264;
496 }
497
498 public boolean getWallpaper()
499 {
500 return wallpaper;
501 }
502
503 public void setWallpaper(boolean wallpaper)
504 {
505 this.wallpaper = wallpaper;
506 }
507
508 public boolean getTheming()
509 {
510 return theming;
511 }
512
513 public void setTheming(boolean theming)
514 {
515 this.theming = theming;
516 }
517
518 public boolean getFullWindowDrag()
519 {
520 return fullWindowDrag;
521 }
522
523 public void setFullWindowDrag(boolean fullWindowDrag)
524 {
525 this.fullWindowDrag = fullWindowDrag;
526 }
527
528 public boolean getMenuAnimations()
529 {
530 return menuAnimations;
531 }
532
533 public void setMenuAnimations(boolean menuAnimations)
534 {
535 this.menuAnimations = menuAnimations;
536 }
537
538 public boolean getFontSmoothing()
539 {
540 return fontSmoothing;
541 }
542
543 public void setFontSmoothing(boolean fontSmoothing)
544 {
545 this.fontSmoothing = fontSmoothing;
546 }
547
548 public boolean getDesktopComposition()
549 {
550 return desktopComposition;
551 }
552
553 public void setDesktopComposition(boolean desktopComposition)
554 {
555 this.desktopComposition = desktopComposition;
556 }
557
558 @Override public int describeContents()
559 {
560 return 0;
561 }
562
563 @Override public void writeToParcel(@NonNull Parcel out, int flags)
564 {
565 out.writeBoolean(remotefx);
566 out.writeBoolean(gfx);
567 out.writeBoolean(h264);
568 out.writeBoolean(wallpaper);
569 out.writeBoolean(theming);
570 out.writeBoolean(fullWindowDrag);
571 out.writeBoolean(menuAnimations);
572 out.writeBoolean(fontSmoothing);
573 out.writeBoolean(desktopComposition);
574 }
575 }
576
577 // Screen Settings class
578 public static class ScreenSettings implements Parcelable
579 {
580 public static final int FITSCREEN = -2;
581 public static final int AUTOMATIC = -1;
582 public static final int CUSTOM = 0;
583 public static final int PREDEFINED = 1;
584 public static final Parcelable.Creator<ScreenSettings> CREATOR =
585 new Parcelable.Creator<ScreenSettings>() {
586 @NonNull public ScreenSettings createFromParcel(Parcel in)
587 {
588 return new ScreenSettings(in);
589 }
590
591 @NonNull @Override public ScreenSettings[] newArray(int size)
592 {
593 return new ScreenSettings[size];
594 }
595 };
596 private int resolution = AUTOMATIC;
597 private int colors = 32;
598 private int width = 0;
599 private int height = 0;
600 private String scaleMode = "100";
601 private int scaleDesktop = 100;
602 private int scaleDevice = 100;
603
604 public ScreenSettings()
605 {
606 }
607
608 public ScreenSettings(Parcel parcel)
609 {
610 resolution = parcel.readInt();
611 colors = parcel.readInt();
612 width = parcel.readInt();
613 height = parcel.readInt();
614 scaleMode = parcel.readString();
615 scaleDesktop = parcel.readInt();
616 scaleDevice = parcel.readInt();
617 }
618
619 private void validate()
620 {
621 switch (colors)
622 {
623 case 32:
624 case 24:
625 case 16:
626 case 15:
627 case 8:
628 break;
629 default:
630 colors = 32;
631 break;
632 }
633
634 if ((width <= 0) || (width > 65536))
635 {
636 width = 1024;
637 }
638
639 if ((height <= 0) || (height > 65536))
640 {
641 height = 768;
642 }
643
644 switch (resolution)
645 {
646 case FITSCREEN:
647 case AUTOMATIC:
648 case CUSTOM:
649 case PREDEFINED:
650 break;
651 default:
652 resolution = AUTOMATIC;
653 break;
654 }
655 }
656
657 public void setResolution(@NonNull String resolution, int width, int height)
658 {
659 if (resolution.contains("x"))
660 {
661 String[] dimensions = resolution.split("x");
662 this.width = Integer.parseInt(dimensions[0]);
663 this.height = Integer.parseInt(dimensions[1]);
664 this.resolution = PREDEFINED;
665 }
666 else if (resolution.equalsIgnoreCase("custom"))
667 {
668 this.width = width;
669 this.height = height;
670 this.resolution = CUSTOM;
671 }
672 else if (resolution.equalsIgnoreCase("fitscreen"))
673 {
674 this.width = this.height = 0;
675 this.resolution = FITSCREEN;
676 }
677 else
678 {
679 this.width = this.height = 0;
680 this.resolution = AUTOMATIC;
681 }
682 }
683
684 public int getResolution()
685 {
686 return resolution;
687 }
688
689 public void setResolution(int resolution)
690 {
691 this.resolution = resolution;
692
693 if (resolution == AUTOMATIC || resolution == FITSCREEN)
694 {
695 width = 0;
696 height = 0;
697 }
698 }
699
700 @NonNull public String getResolutionString()
701 {
702 if (isPredefined())
703 return (width + "x" + height);
704
705 return (isFitScreen() ? "fitscreen" : isAutomatic() ? "automatic" : "custom");
706 }
707
708 public boolean isPredefined()
709 {
710 validate();
711 return (resolution == PREDEFINED);
712 }
713
714 public boolean isAutomatic()
715 {
716 validate();
717 return (resolution == AUTOMATIC);
718 }
719
720 public boolean isFitScreen()
721 {
722 validate();
723 return (resolution == FITSCREEN);
724 }
725
726 public boolean isCustom()
727 {
728 validate();
729 return (resolution == CUSTOM);
730 }
731
732 public int getWidth()
733 {
734 validate();
735 return width;
736 }
737
738 public void setWidth(int width)
739 {
740 this.width = width;
741 }
742
743 public int getHeight()
744 {
745 validate();
746 return height;
747 }
748
749 public void setHeight(int height)
750 {
751 this.height = height;
752 }
753
754 public int getColors()
755 {
756 validate();
757 return colors;
758 }
759
760 public void setColors(int colors)
761 {
762 this.colors = colors;
763 }
764
765 public void setScale(@NonNull String mode, int desktop, int device)
766 {
767 scaleMode = "custom".equalsIgnoreCase(mode) ? "custom" : mode;
768 scaleDesktop = desktop;
769 scaleDevice = device;
770 }
771
772 public boolean isCustomScale()
773 {
774 return "custom".equalsIgnoreCase(scaleMode);
775 }
776
777 @NonNull public String getScaleMode()
778 {
779 return scaleMode;
780 }
781
782 public int getScalePreset()
783 {
784 if ("140".equals(scaleMode))
785 return 140;
786 if ("180".equals(scaleMode))
787 return 180;
788 return 100;
789 }
790
791 public int getScaleDesktop()
792 {
793 return scaleDesktop;
794 }
795
796 public int getScaleDevice()
797 {
798 return scaleDevice;
799 }
800
801 @Override public int describeContents()
802 {
803 return 0;
804 }
805
806 @Override public void writeToParcel(@NonNull Parcel out, int flags)
807 {
808 out.writeInt(resolution);
809 out.writeInt(colors);
810 out.writeInt(width);
811 out.writeInt(height);
812 out.writeString(scaleMode);
813 out.writeInt(scaleDesktop);
814 out.writeInt(scaleDevice);
815 }
816 }
817
818 public static class DebugSettings implements Parcelable
819 {
820 public static final Parcelable.Creator<DebugSettings> CREATOR =
821 new Parcelable.Creator<DebugSettings>() {
822 @NonNull public DebugSettings createFromParcel(Parcel in)
823 {
824 return new DebugSettings(in);
825 }
826
827 @NonNull @Override public DebugSettings[] newArray(int size)
828 {
829 return new DebugSettings[size];
830 }
831 };
832
833 @NonNull private String debug = "INFO";
834 private boolean asyncChannel = true;
835 private boolean asyncTransport = false;
836 private boolean asyncUpdate = true;
837
838 public DebugSettings()
839 {
840 }
841
842 // Session Settings
843 public DebugSettings(@NonNull Parcel parcel)
844 {
845 asyncChannel = parcel.readBoolean();
846 asyncTransport = parcel.readBoolean();
847 asyncUpdate = parcel.readBoolean();
848 debug = Objects.requireNonNull(parcel.readString());
849 }
850
851 private void validate()
852 {
853 final String[] levels = { "OFF", "FATAL", "ERROR", "WARN", "INFO", "DEBUG", "TRACE" };
854
855 for (String level : levels)
856 {
857 if (level.equalsIgnoreCase(this.debug))
858 {
859 return;
860 }
861 }
862
863 this.debug = "INFO";
864 }
865
866 @NonNull public String getDebugLevel()
867 {
868 validate();
869 return debug;
870 }
871
872 public void setDebugLevel(@NonNull String debug)
873 {
874 this.debug = debug;
875 }
876
877 public boolean getAsyncUpdate()
878 {
879 return asyncUpdate;
880 }
881
882 public void setAsyncUpdate(boolean enabled)
883 {
884 asyncUpdate = enabled;
885 }
886
887 public boolean getAsyncChannel()
888 {
889 return asyncChannel;
890 }
891
892 public void setAsyncChannel(boolean enabled)
893 {
894 asyncChannel = enabled;
895 }
896
897 @Override public int describeContents()
898 {
899 return 0;
900 }
901
902 @Override public void writeToParcel(@NonNull Parcel out, int flags)
903 {
904 out.writeBoolean(asyncChannel);
905 out.writeBoolean(asyncTransport);
906 out.writeBoolean(asyncUpdate);
907 out.writeString(debug);
908 }
909 }
910
911 // Session Settings
912 public static class AdvancedSettings implements Parcelable
913 {
914 public static final Parcelable.Creator<AdvancedSettings> CREATOR =
915 new Parcelable.Creator<AdvancedSettings>() {
916 @NonNull public AdvancedSettings createFromParcel(Parcel in)
917 {
918 return new AdvancedSettings(in);
919 }
920
921 @NonNull @Override public AdvancedSettings[] newArray(int size)
922 {
923 return new AdvancedSettings[size];
924 }
925 };
926
927 @NonNull private String loadBalanceInfo = "";
928 private boolean redirectSDCard = false;
929 private int redirectSound = 0;
930 private boolean redirectMicrophone = false;
931 private boolean redirectPrinter = false;
932 private int security = 0;
933 private boolean consoleMode = false;
934 private boolean vmConnectMode = false;
935 @NonNull private String vmConnectGuid = "";
936
937 @NonNull private String remoteProgram = "";
938
939 @NonNull private String workDir = "";
940 private int tlsSecLevel = -1;
941 private int tlsMinLevel = -1;
942
943 public AdvancedSettings()
944 {
945 }
946
947 public AdvancedSettings(@NonNull Parcel parcel)
948 {
949 loadBalanceInfo = Objects.requireNonNull(parcel.readString());
950 redirectSDCard = parcel.readBoolean();
951 redirectSound = parcel.readInt();
952 redirectMicrophone = parcel.readBoolean();
953 redirectPrinter = parcel.readBoolean();
954 security = parcel.readInt();
955 consoleMode = parcel.readBoolean();
956 vmConnectMode = parcel.readBoolean();
957 vmConnectGuid = Objects.requireNonNull(parcel.readString());
958 remoteProgram = Objects.requireNonNull(parcel.readString());
959 workDir = Objects.requireNonNull(parcel.readString());
960 tlsSecLevel = parcel.readInt();
961 tlsMinLevel = parcel.readInt();
962 }
963
964 private void validate()
965 {
966 switch (redirectSound)
967 {
968 case 0:
969 case 1:
970 case 2:
971 break;
972 default:
973 redirectSound = 0;
974 break;
975 }
976
977 switch (security)
978 {
979 case 0:
980 case 1:
981 case 2:
982 case 3:
983 break;
984 default:
985 security = 0;
986 break;
987 }
988 }
989
990 public int getTlsSecLevel()
991 {
992 return tlsSecLevel;
993 }
994
995 public void setTlsSecLevel(int level)
996 {
997 tlsSecLevel = level;
998 }
999
1000 public void setTlsMinLevel(int level)
1001 {
1002 tlsMinLevel = level;
1003 }
1004
1005 public int getTlsMinLevel()
1006 {
1007 return tlsMinLevel;
1008 }
1009
1010 @NonNull public String getLoadBalanceInfo()
1011 {
1012 return loadBalanceInfo;
1013 }
1014
1015 public void setLoadBalanceInfo(@NonNull String info)
1016 {
1017 loadBalanceInfo = info;
1018 }
1019 public boolean getRedirectSDCard()
1020 {
1021 return redirectSDCard;
1022 }
1023
1024 public void setRedirectSDCard(boolean redirectSDCard)
1025 {
1026 this.redirectSDCard = redirectSDCard;
1027 }
1028
1029 public boolean getRedirectPrinter()
1030 {
1031 return redirectPrinter;
1032 }
1033
1034 public void setRedirectPrinter(boolean redirectPrinter)
1035 {
1036 this.redirectPrinter = redirectPrinter;
1037 }
1038
1039 public int getRedirectSound()
1040 {
1041 validate();
1042 return redirectSound;
1043 }
1044
1045 public void setRedirectSound(int redirect)
1046 {
1047 this.redirectSound = redirect;
1048 }
1049
1050 public boolean getRedirectMicrophone()
1051 {
1052 return redirectMicrophone;
1053 }
1054
1055 public void setRedirectMicrophone(boolean redirect)
1056 {
1057 this.redirectMicrophone = redirect;
1058 }
1059
1060 public int getSecurity()
1061 {
1062 validate();
1063 return security;
1064 }
1065
1066 public void setSecurity(int security)
1067 {
1068 this.security = security;
1069 }
1070
1071 public boolean getConsoleMode()
1072 {
1073 return consoleMode;
1074 }
1075
1076 public void setConsoleMode(boolean consoleMode)
1077 {
1078 this.consoleMode = consoleMode;
1079 }
1080
1081 @NonNull public String getRemoteProgram()
1082 {
1083 return remoteProgram;
1084 }
1085
1086 public void setRemoteProgram(@NonNull String remoteProgram)
1087 {
1088 this.remoteProgram = remoteProgram;
1089 }
1090
1091 @NonNull public String getWorkDir()
1092 {
1093 return workDir;
1094 }
1095
1096 public void setWorkDir(@NonNull String workDir)
1097 {
1098 this.workDir = workDir;
1099 }
1100
1101 public boolean getVmConnectMode()
1102 {
1103 return vmConnectMode;
1104 }
1105
1106 public void setVmConnectMode(boolean vmConnectMode)
1107 {
1108 this.vmConnectMode = vmConnectMode;
1109 }
1110
1111 @NonNull public String getVmConnectGuid()
1112 {
1113 return vmConnectGuid;
1114 }
1115
1116 public void setVmConnectGuid(@NonNull String vmConnectGuid)
1117 {
1118 this.vmConnectGuid = vmConnectGuid;
1119 }
1120
1121 @Override public int describeContents()
1122 {
1123 return 0;
1124 }
1125
1126 @Override public void writeToParcel(@NonNull Parcel out, int flags)
1127 {
1128 out.writeString(loadBalanceInfo);
1129 out.writeBoolean(redirectSDCard);
1130 out.writeInt(redirectSound);
1131 out.writeBoolean(redirectMicrophone);
1132 out.writeBoolean(redirectPrinter);
1133 out.writeInt(security);
1134 out.writeBoolean(consoleMode);
1135 out.writeBoolean(vmConnectMode);
1136 out.writeString(vmConnectGuid);
1137 out.writeString(remoteProgram);
1138 out.writeString(workDir);
1139 out.writeInt(tlsSecLevel);
1140 out.writeInt(tlsMinLevel);
1141 }
1142 }
1143
1144 public static class GatewaySettings implements Parcelable
1145 {
1146 public static final Parcelable.Creator<GatewaySettings> CREATOR =
1147 new Parcelable.Creator<GatewaySettings>() {
1148 @NonNull public GatewaySettings createFromParcel(Parcel in)
1149 {
1150 return new GatewaySettings(in);
1151 }
1152
1153 @NonNull @Override public GatewaySettings[] newArray(int size)
1154 {
1155 return new GatewaySettings[size];
1156 }
1157 };
1158
1159 @NonNull private String hostname = "";
1160 private int port = 443;
1161
1162 @NonNull private String username = "";
1163
1164 @NonNull private String password = "";
1165
1166 @NonNull private String domain = "";
1167
1168 public GatewaySettings()
1169 {
1170 }
1171
1172 public GatewaySettings(Parcel parcel)
1173 {
1174 hostname = Objects.requireNonNull(parcel.readString());
1175 port = parcel.readInt();
1176 username = Objects.requireNonNull(parcel.readString());
1177 password = Objects.requireNonNull(parcel.readString());
1178 domain = Objects.requireNonNull(parcel.readString());
1179 }
1180
1181 @NonNull public String getHostname()
1182 {
1183 return hostname;
1184 }
1185
1186 public void setHostname(@NonNull String hostname)
1187 {
1188 this.hostname = hostname;
1189 }
1190
1191 public int getPort()
1192 {
1193 return port;
1194 }
1195
1196 public void setPort(int port)
1197 {
1198 this.port = port;
1199 }
1200
1201 @NonNull public String getUsername()
1202 {
1203 return username;
1204 }
1205
1206 public void setUsername(@NonNull String username)
1207 {
1208 this.username = username;
1209 }
1210
1211 @NonNull public String getPassword()
1212 {
1213 return password;
1214 }
1215
1216 public void setPassword(@NonNull String password)
1217 {
1218 this.password = password;
1219 }
1220
1221 @NonNull public String getDomain()
1222 {
1223 return domain;
1224 }
1225
1226 public void setDomain(@NonNull String domain)
1227 {
1228 this.domain = domain;
1229 }
1230
1231 @Override public int describeContents()
1232 {
1233 return 0;
1234 }
1235
1236 @Override public void writeToParcel(@NonNull Parcel out, int flags)
1237 {
1238 out.writeString(hostname);
1239 out.writeInt(port);
1240 out.writeString(username);
1241 out.writeString(password);
1242 out.writeString(domain);
1243 }
1244 }
1245}