Repository navigation
Expand file tree
/
Copy pathPrefStore.java
More file actions
1217 lines (1131 loc) · 36 KB
/
Copy pathPrefStore.java
File metadata and controls
1217 lines (1131 loc) · 36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package ru.meefik.linuxdeploy;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.nio.channels.FileChannel;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.List;
import java.util.Locale;
import java.util.Map.Entry;
import java.util.Set;
import java.util.HashSet;
import com.h6ah4i.android.compat.content.SharedPreferenceCompat;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.graphics.Point;
import android.os.Build;
import android.os.Environment;
import android.view.Display;
import android.view.WindowManager;
public class PrefStore {
public static Boolean CONF_CHANGE = false;
public static final String APP_PREF_NAME = "app_settings";
public static final String PROFILES_PREF_NAME = "profiles";
/**
* Get string with values by resource id
*
* @param c context
* @param resId resource id with variables
* @return string with values
*/
public static String getValues(Context c, int resId) {
return c.getString(resId).replace("${ENV_DIR}",
getEnvDir(c)).replace("${EXTERNAL_STORAGE}", getStorage());
}
/**
* Get string with values by string
*
* @param c context
* @param text string with variables
* @return string with values
*/
public static String getValues(Context c, String text) {
return text.replace("${ENV_DIR}",
getEnvDir(c)).replace("${EXTERNAL_STORAGE}", getStorage());
}
/**
* Get application version
*
* @param c context
* @return version, format versionName-versionCode
*/
public static String getVersion(Context c) {
String version = "";
try {
PackageInfo pi = c.getPackageManager().getPackageInfo(
c.getPackageName(), 0);
version = pi.versionName + "-" + pi.versionCode;
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
return version;
}
/**
* Get external storage path
*
* @return path
*/
public static String getStorage() {
return Environment.getExternalStorageDirectory().getAbsolutePath();
}
/**
* Get environment directory
*
* @param c context
* @return path, e.g. /data/data/com.example.app/files
*/
public static String getEnvDir(Context c) {
return c.getFilesDir().getAbsolutePath();
}
/**
* Get language code
*
* @param c context
* @return language code, e.g. "en"
*/
public static String getLanguage(Context c) {
SharedPreferences pref = c.getSharedPreferences(APP_PREF_NAME,
Context.MODE_PRIVATE);
String language = pref.getString("language", c
.getString(R.string.language));
if (language.length() == 0) {
String countryCode = Locale.getDefault().getLanguage();
switch (countryCode) {
case "ru":
language = countryCode;
break;
default:
language = "en";
}
SharedPreferences.Editor editor = pref.edit();
editor.putString("language", language);
editor.commit();
}
return language;
}
/**
* Get application theme resource id
*
* @param c context
* @return resource id
*/
public static int getTheme(Context c) {
SharedPreferences pref = c.getSharedPreferences(APP_PREF_NAME,
Context.MODE_PRIVATE);
String theme = pref.getString("theme", c.getString(R.string.theme));
int themeId = R.style.DarkTheme;
switch (theme) {
case "dark":
themeId = R.style.DarkTheme;
break;
case "light":
themeId = R.style.LightTheme;
break;
}
return themeId;
}
/**
* Get font size
*
* @param c context
* @return font size
*/
public static int getFontSize(Context c) {
Integer fontSizeInt;
SharedPreferences pref = c.getSharedPreferences(APP_PREF_NAME,
Context.MODE_PRIVATE);
String fontSize = pref.getString("fontsize", c
.getString(R.string.fontsize));
try {
fontSizeInt = Integer.parseInt(fontSize);
} catch (Exception e) {
fontSize = c.getString(R.string.fontsize);
fontSizeInt = Integer.parseInt(fontSize);
SharedPreferences.Editor editor = pref.edit();
editor.putString("fontsize", fontSize);
editor.commit();
}
return fontSizeInt;
}
/**
* Get maximum limit to scroll
*
* @param c context
* @return number of lines
*/
public static int getMaxLines(Context c) {
Integer maxLinesInt;
SharedPreferences pref = c.getSharedPreferences(APP_PREF_NAME,
Context.MODE_PRIVATE);
String maxLines = pref.getString("maxlines", c
.getString(R.string.maxlines));
try {
maxLinesInt = Integer.parseInt(maxLines);
} catch (Exception e) {
maxLines = c.getString(R.string.maxlines);
maxLinesInt = Integer.parseInt(maxLines);
SharedPreferences.Editor editor = pref.edit();
editor.putString("maxlines", maxLines);
editor.commit();
}
return maxLinesInt;
}
/**
* Timestamp is enabled
*
* @param c context
* @return true if enabled
*/
public static Boolean isTimestamp(Context c) {
SharedPreferences pref = c.getSharedPreferences(APP_PREF_NAME,
Context.MODE_PRIVATE);
return pref.getBoolean("timestamp", c.getString(R.string.timestamp)
.equals("true"));
}
/**
* Debug mode is enabled
*
* @param c context
* @return true if enabled
*/
public static Boolean isDebugMode(Context c) {
SharedPreferences pref = c.getSharedPreferences(APP_PREF_NAME,
Context.MODE_PRIVATE);
return pref.getBoolean("debug", c.getString(R.string.debug).equals(
"true"));
}
/**
* Trace mode is enabled
*
* @param c context
* @return true if enabled
*/
public static Boolean isTraceMode(Context c) {
SharedPreferences pref = c.getSharedPreferences(APP_PREF_NAME,
Context.MODE_PRIVATE);
return pref.getBoolean("debug", c.getString(R.string.debug).equals(
"true"))
&& pref.getBoolean("trace", c.getString(R.string.trace).equals(
"true"));
}
/**
* Logging is enabled
*
* @param c context
* @return true if enabled
*/
public static Boolean isLogger(Context c) {
SharedPreferences pref = c.getSharedPreferences(APP_PREF_NAME,
Context.MODE_PRIVATE);
return pref.getBoolean("logger", c.getString(R.string.logger).equals(
"true"));
}
/**
* Get path of log file
*
* @param c context
* @return path
*/
public static String getLogFile(Context c) {
SharedPreferences pref = c.getSharedPreferences(APP_PREF_NAME,
Context.MODE_PRIVATE);
return getValues(c, pref.getString("logfile", c.getString(R.string.logfile)));
}
/**
* Screen lock is enabled
*
* @param c context
* @return true if enabled
*/
public static Boolean isScreenLock(Context c) {
SharedPreferences pref = c.getSharedPreferences(APP_PREF_NAME,
Context.MODE_PRIVATE);
return pref.getBoolean("screenlock", c.getString(R.string.screenlock)
.equals("true"));
}
/**
* Wifi lock is enabled
*
* @param c context
* @return true if enabled
*/
public static Boolean isWifiLock(Context c) {
SharedPreferences pref = c.getSharedPreferences(APP_PREF_NAME,
Context.MODE_PRIVATE);
return pref.getBoolean("wifilock", c.getString(R.string.wifilock)
.equals("true"));
}
/**
* Application autostart is enabled
*
* @param c context
* @return true if enabled
*/
public static Boolean isAutostart(Context c) {
SharedPreferences pref = c.getSharedPreferences(APP_PREF_NAME,
Context.MODE_PRIVATE);
return pref.getBoolean("autostart", c.getString(R.string.autostart)
.equals("true"));
}
/**
* Show icon is enabled
*
* @param c context
* @return true if enabled
*/
public static Boolean isShowIcon(Context c) {
SharedPreferences pref = c.getSharedPreferences(APP_PREF_NAME,
Context.MODE_PRIVATE);
return pref.getBoolean("appicon", c.getString(R.string.appicon).equals(
"true"));
}
/**
* Get BusyBox directory
*
* @param c context
* @return directory path
*/
public static String getBusyboxDir(Context c) {
SharedPreferences pref = c.getSharedPreferences(APP_PREF_NAME,
Context.MODE_PRIVATE);
return pref.getString("busyboxdir", c.getString(R.string.busyboxdir));
}
/**
* Get terminal script
*
* @param c context
* @return script
*/
public static String getTerminalCmd(Context c) {
SharedPreferences pref = c.getSharedPreferences(APP_PREF_NAME,
Context.MODE_PRIVATE);
return getValues(c, pref.getString("terminalcmd", c.getString(R.string.terminalcmd)));
}
/**
* Get shell
*
* @param c context
* @return path to shell, e.g. /system/xbin/ash
*/
public static String getShell(Context c) {
return getBusyboxDir(c) + "/ash";
}
/**
* CLI is enabled
*
* @param c context
* @return true if enabled
*/
public static Boolean isUseCli(Context c) {
SharedPreferences pref = c.getSharedPreferences(APP_PREF_NAME,
Context.MODE_PRIVATE);
return pref.getBoolean("usecli", c.getString(R.string.usecli).equals(
"true"));
}
/**
* Get chroot directory
*
* @param c context
* @return path
*/
public static String getChrootDir(Context c) {
SharedPreferences pref = c.getSharedPreferences(getCurrentProfile(c),
Context.MODE_PRIVATE);
return pref.getString("mountdir", c.getString(R.string.mountdir));
}
/**
* Get target path
*
* @param c context
* @return path
*/
public static String getTargetPath(Context c) {
SharedPreferences pref = c.getSharedPreferences(getCurrentProfile(c),
Context.MODE_PRIVATE);
return getValues(c, pref.getString("diskimage", c.getString(R.string.diskimage)));
}
/**
* Get deploy type
*
* @param c context
* @return type
*/
public static String getTargetType(Context c) {
SharedPreferences pref = c.getSharedPreferences(getCurrentProfile(c),
Context.MODE_PRIVATE);
return pref.getString("deploytype", c.getString(R.string.deploytype));
}
/**
* Get image size
*
* @param c context
* @return size in Mb
*/
public static String getDiskSize(Context c) {
SharedPreferences pref = c.getSharedPreferences(getCurrentProfile(c),
Context.MODE_PRIVATE);
return pref.getString("disksize", c.getString(R.string.disksize));
}
/**
* Get filesystem
*
* @param c context
* @return filesystem: ext2, ext3, ext4 or auto
*/
public static String getFilesystem(Context c) {
SharedPreferences pref = c.getSharedPreferences(getCurrentProfile(c),
Context.MODE_PRIVATE);
return pref.getString("fstype", c.getString(R.string.fstype));
}
/**
* Get GNU/Linux distribution name
*
* @param c context
* @return name, e.g. debian, ubuntu etc.
*/
public static String getDistribution(Context c) {
SharedPreferences pref = c.getSharedPreferences(getCurrentProfile(c),
Context.MODE_PRIVATE);
return pref.getString("distribution", c
.getString(R.string.distribution));
}
/**
* Get distribution suite
*
* @param c context
* @return suite, e.g. jessie, percise etc.
*/
public static String getSuite(Context c) {
SharedPreferences pref = c.getSharedPreferences(getCurrentProfile(c),
Context.MODE_PRIVATE);
return pref.getString("suite", c.getString(R.string.suite));
}
/**
* Get source path
*
* @param c context
* @return path
*/
public static String getSourcePath(Context c) {
SharedPreferences pref = c.getSharedPreferences(getCurrentProfile(c),
Context.MODE_PRIVATE);
return pref.getString("mirror", c.getString(R.string.mirror));
}
/**
* Get distribution architecture
*
* @param c context
* @return architecture, e.g. armel, armhf, i386 etc.
*/
public static String getArchitecture(Context c) {
SharedPreferences pref = c.getSharedPreferences(getCurrentProfile(c),
Context.MODE_PRIVATE);
return pref.getString("architecture", c
.getString(R.string.architecture));
}
/**
* Get user name
*
* @param c context
* @return name in lower case
*/
public static String getUserName(Context c) {
SharedPreferences pref = c.getSharedPreferences(getCurrentProfile(c),
Context.MODE_PRIVATE);
return pref.getString("username", c.getString(R.string.username)).trim();
}
/**
* Get user password
*
* @param c context
* @return plain password
*/
public static String getUserPassword(Context c) {
SharedPreferences pref = c.getSharedPreferences(getCurrentProfile(c),
Context.MODE_PRIVATE);
return pref.getString("password", c.getString(R.string.password));
}
/**
* Get DNS server
*
* @param c context
* @return one or more IP separated by a space
*/
public static String getServerDns(Context c) {
SharedPreferences pref = c.getSharedPreferences(getCurrentProfile(c),
Context.MODE_PRIVATE);
return pref.getString("serverdns", c.getString(R.string.serverdns));
}
/**
* Get distribution locale
*
* @param c context
* @return locale, e.g. ru_RU.UTF-8
*/
public static String getLocale(Context c) {
SharedPreferences pref = c.getSharedPreferences(getCurrentProfile(c),
Context.MODE_PRIVATE);
return pref.getString("locale", c.getString(R.string.locale));
}
/**
* Get desktop environment
*
* @param c context
* @return environment name, e.g. xterm, lxde, xfce, gnome, kde etc.
*/
public static String getDesktopEnv(Context c) {
SharedPreferences pref = c.getSharedPreferences(getCurrentProfile(c),
Context.MODE_PRIVATE);
return pref.getString("desktopenv", c.getString(R.string.desktopenv));
}
/**
* Get used components
*
* @param c context
* @return list of components separated by a space, e.g. ssh, vnc etc.
*/
public static String getUseComponents(Context c) {
SharedPreferences pref = c.getSharedPreferences(getCurrentProfile(c),
Context.MODE_PRIVATE);
Set<String> defcomp = new HashSet<String>(Arrays.asList(c
.getResources().getStringArray(R.array.default_components)));
if (!pref.contains("xcomponents")) {
SharedPreferences.Editor editor = pref.edit();
// set default components
SharedPreferenceCompat.EditorCompat.putStringSet(editor,
"xcomponents", defcomp);
editor.commit();
}
Set<String> comp_set = SharedPreferenceCompat.getStringSet(pref,
"xcomponents", defcomp);
String components = "";
for (String str : comp_set) {
components += str + " ";
}
return components.trim();
}
/**
* Get list of startup
*
* @param c context
* @return list of startup separated by a space, e.g. ssh, vnc etc.
*/
public static String getStartup(Context c) {
SharedPreferences pref = c.getSharedPreferences(getCurrentProfile(c),
Context.MODE_PRIVATE);
String startup = "";
if (pref.getBoolean("sshstartup", c.getString(R.string.sshstartup)
.equals("true"))) {
startup += " ssh";
}
if (pref.getBoolean("guistartup", c.getString(R.string.guistartup)
.equals("true"))) {
startup += " "
+ pref.getString("guitype", c.getString(R.string.guitype));
}
if (pref.getBoolean("customstartup", c
.getString(R.string.customstartup).equals("true"))) {
startup += " custom";
}
return startup.trim();
}
/**
* Get list of custom scripts
*
* @param c context
* @return list of scripts separated by a space
*/
public static String getCustomScripts(Context c) {
SharedPreferences pref = c.getSharedPreferences(getCurrentProfile(c),
Context.MODE_PRIVATE);
String startup = "";
if (pref.getBoolean("customstartup", c
.getString(R.string.customstartup).equals("true"))) {
startup = pref.getString("scripts", c.getString(R.string.scripts));
}
return startup.trim();
}
/**
* Get list of custom mounts
*
* @param c context
* @return list of mount points separated by a space
*/
public static String getCustomMounts(Context c) {
SharedPreferences pref = c.getSharedPreferences(getCurrentProfile(c),
Context.MODE_PRIVATE);
String mountPoints = "";
if (pref.getBoolean("custommounts", c.getString(R.string.custommount)
.equals("true"))) {
mountPoints = pref.getString("mounts", getStorage());
}
return mountPoints.trim();
}
/**
* Get SSH server port
*
* @param c context
* @return port, e.g. 22
*/
public static String getSshPort(Context c) {
SharedPreferences pref = c.getSharedPreferences(getCurrentProfile(c),
Context.MODE_PRIVATE);
return pref.getString("sshport", c.getString(R.string.sshport));
}
/**
* Get VNC display
*
* @param c context
* @return display, e.g. 0
*/
public static String getVncDisplay(Context c) {
SharedPreferences pref = c.getSharedPreferences(getCurrentProfile(c),
Context.MODE_PRIVATE);
return pref.getString("vncdisplay", c.getString(R.string.vncdisplay));
}
/**
* Get VNC color depth
*
* @param c context
* @return depth, e.g. 16
*/
public static String getVncDepth(Context c) {
SharedPreferences pref = c.getSharedPreferences(getCurrentProfile(c),
Context.MODE_PRIVATE);
return pref.getString("vncdepth", c.getString(R.string.vncdepth));
}
/**
* Get VNC DPI
*
* @param c context
* @return dpi, e.g. 100
*/
public static String getVncDpi(Context c) {
SharedPreferences pref = c.getSharedPreferences(getCurrentProfile(c),
Context.MODE_PRIVATE);
return pref.getString("vncdpi", c.getString(R.string.vncdpi));
}
/**
* Get VNC geometry WxH
*
* @param c context
* @return geometry, e.g. 800x400
*/
public static String getVncGeometry(Context c) {
SharedPreferences pref = c.getSharedPreferences(getCurrentProfile(c),
Context.MODE_PRIVATE);
SharedPreferences.Editor editor = pref.edit();
String vncWidth = pref.getString("vncwidth", c
.getString(R.string.vncwidth));
if (vncWidth.length() == 0) {
vncWidth = String.valueOf(getScreenWidth(c));
editor.putString("vncwidth", vncWidth);
editor.commit();
}
String vncHeight = pref.getString("vncheight", c
.getString(R.string.vncheight));
if (vncHeight.length() == 0) {
vncHeight = String.valueOf(getScreenHeight(c));
editor.putString("vncheight", vncHeight);
editor.commit();
}
return vncWidth + "x" + vncHeight;
}
/**
* Get VNC arguments
*
* @param c context
* @return arguments
*/
public static String getVncArgs(Context c) {
SharedPreferences pref = c.getSharedPreferences(getCurrentProfile(c),
Context.MODE_PRIVATE);
return pref.getString("vncargs", c.getString(R.string.vncargs));
}
/**
* Get X server display
*
* @param c context
* @return display, e.g. 0
*/
public static String getXserverDisplay(Context c) {
SharedPreferences pref = c.getSharedPreferences(getCurrentProfile(c),
Context.MODE_PRIVATE);
return pref.getString("xdisplay", c.getString(R.string.xdisplay));
}
/**
* Get X server host
*
* @param c context
* @return host name or IP
*/
public static String getXserverHost(Context c) {
SharedPreferences pref = c.getSharedPreferences(getCurrentProfile(c),
Context.MODE_PRIVATE);
return pref.getString("xhost", c.getString(R.string.xhost));
}
/**
* XServer XSDL is enabled
*
* @param c context
* @return true if enabled
*/
public static Boolean isXserverXsdl(Context c) {
SharedPreferences pref = c.getSharedPreferences(getCurrentProfile(c),
Context.MODE_PRIVATE);
return pref.getBoolean("xserverxsdl", c.getString(R.string.xserverxsdl)
.equals("true"));
}
/**
* Get X display (framebuffer mode)
*
* @param c context
* @return display, e.g. 0
*/
public static String getFbDisplay(Context c) {
SharedPreferences pref = c.getSharedPreferences(getCurrentProfile(c),
Context.MODE_PRIVATE);
return pref.getString("fbdisplay", c.getString(R.string.fbdisplay));
}
/**
* Get X DPI (framebuffer mode)
*
* @param c context
* @return DPI, e.g. 100
*/
public static String getFbDpi(Context c) {
SharedPreferences pref = c.getSharedPreferences(getCurrentProfile(c),
Context.MODE_PRIVATE);
return pref.getString("fbdpi", c.getString(R.string.fbdpi));
}
/**
* Get fbdev
*
* @param c context
* @return device, e.g. /dev/graphics/fb0
*/
public static String getFbDev(Context c) {
SharedPreferences pref = c.getSharedPreferences(getCurrentProfile(c),
Context.MODE_PRIVATE);
return pref.getString("fbdev", c.getString(R.string.fbdev));
}
/**
* Get fb input device
*
* @param c context
* @return device, e.g. /dev/input/event0
*/
public static String getFbInput(Context c) {
SharedPreferences pref = c.getSharedPreferences(getCurrentProfile(c),
Context.MODE_PRIVATE);
return pref.getString("fbinput", c.getString(R.string.fbinput));
}
/**
* Get X arguments (framebuffer mode)
*
* @param c context
* @return arguments
*/
public static String getFbArgs(Context c) {
SharedPreferences pref = c.getSharedPreferences(getCurrentProfile(c),
Context.MODE_PRIVATE);
return pref.getString("fbargs", c.getString(R.string.fbargs));
}
/**
* Get fb refresh mode
*
* @param c context
* @return 0 or 1
*/
public static String getFbRefreshMode(Context c) {
SharedPreferences pref = c.getSharedPreferences(getCurrentProfile(c),
Context.MODE_PRIVATE);
return pref.getBoolean("fbrefresh", c.getString(R.string.fbrefresh).equals("true")) ? "1" : "0";
}
/**
* Get Android freeze mode
*
* @param c context
* @return mode, e.g. pause, stop or none.
*/
public static String getFbFreezeMode(Context c) {
SharedPreferences pref = c.getSharedPreferences(getCurrentProfile(c),
Context.MODE_PRIVATE);
return pref.getString("fbfreeze", c.getString(R.string.fbfreeze));
}
/**
* Get hardware architecture
*
* @param arch unformated architecture
* @return intel, arm or mips
*/
public static String getArch(String arch) {
String march = "unknown";
if (arch.length() > 0) {
char a = arch.toLowerCase().charAt(0);
switch (a) {
case 'a':
if (arch.equals("amd64"))
march = "intel";
else march = "arm";
break;
case 'm':
march = "mips";
break;
case 'i':
case 'x':
march = "intel";
break;
}
}
return march;
}
/**
* Get current hardware architecture
*
* @return intel, arm or mips
*/
public static String getArch() {
return getArch(System.getProperty("os.arch"));
}
/**
* Get width of device screen
*
* @param c context
* @return screen width
*/
@SuppressLint("NewApi")
public static Integer getScreenWidth(Context c) {
int width = 0;
WindowManager wm = (WindowManager) c
.getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
if (Build.VERSION.SDK_INT > 12) {
Point size = new Point();
display.getSize(size);
width = size.x;
} else {
width = display.getWidth(); // deprecated
}
return width;
}
/**
* Get height of device screen
*
* @param c context
* @return screen height
*/
@SuppressLint("NewApi")
public static Integer getScreenHeight(Context c) {
int height = 0;
WindowManager wm = (WindowManager) c
.getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
if (Build.VERSION.SDK_INT > 12) {
Point size = new Point();
display.getSize(size);
height = size.y;
} else {
height = display.getHeight(); // deprecated
}
return height;
}
/**
* Get local IP address
*
* @return ip address
*/
public static String getLocalIpAddress() {
String ip = "127.0.0.1";
try {
for (Enumeration<NetworkInterface> en = NetworkInterface
.getNetworkInterfaces(); en.hasMoreElements();) {
NetworkInterface intf = en.nextElement();
for (Enumeration<InetAddress> enumIpAddr = intf
.getInetAddresses(); enumIpAddr.hasMoreElements();) {
InetAddress inetAddress = enumIpAddr.nextElement();
if (!inetAddress.isLoopbackAddress()
&& !inetAddress.isLinkLocalAddress()) {
ip = inetAddress.getHostAddress().toString();
}
}
}
} catch (SocketException e) {
e.printStackTrace();
}
return ip;
}
/**
* Get current profile
*
* @param c context
* @return profile
*/
public static String getCurrentProfile(Context c) {
SharedPreferences pref = c.getSharedPreferences(APP_PREF_NAME,
Context.MODE_PRIVATE);
String profile = pref.getString("profile", null);
if (profile == null) {
profile = String.valueOf(System.currentTimeMillis());
setCurrentProfile(c, profile);
}
return profile;
}
/**
* Set current profile
*
* @param c context
* @return profile
*/
public static void setCurrentProfile(Context c, String profile) {
SharedPreferences pref = c.getSharedPreferences(APP_PREF_NAME,
Context.MODE_PRIVATE);
SharedPreferences.Editor editor = pref.edit();
editor.putString("profile", profile);
editor.commit();
}
/**
* Get current profile title
*
* @param c context
* @return profile title
*/
public static String getCurrentProfileTitle(Context c) {
SharedPreferences pref = c.getSharedPreferences(PROFILES_PREF_NAME,
Context.MODE_PRIVATE);
return pref
.getString(getCurrentProfile(c), c.getString(R.string.profile));
}
/**
* Get list of profiles
*
* @param c context
* @return list of profiles
*/
public static List<Profile<String, String>> getProfiles(Context c) {
SharedPreferences sp = c.getSharedPreferences(PROFILES_PREF_NAME,
Context.MODE_PRIVATE);
List<Profile<String, String>> p = new ArrayList<Profile<String, String>>();
for (Entry<String, ?> entry : sp.getAll().entrySet()) {
String key = entry.getKey();
String value = (String) entry.getValue();
p.add(new Profile<String, String>(key, value));
}
return p;
}
/**
* Set list of profiles
*