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