-
Notifications
You must be signed in to change notification settings - Fork 7.8k
/
SharedConfig.java
1774 lines (1580 loc) · 76.8 KB
/
SharedConfig.java
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
/*
* This is the source code of Telegram for Android v. 5.x.x.
* It is licensed under GNU GPL v. 2 or later.
* You should have received a copy of the license in this archive (see LICENSE).
*
* Copyright Nikolai Kudashov, 2013-2018.
*/
package org.telegram.messenger;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.Dialog;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.media.MediaCodecInfo;
import android.media.MediaCodecList;
import android.os.Build;
import android.os.Environment;
import android.os.SystemClock;
import android.text.TextUtils;
import android.util.Base64;
import android.util.Log;
import android.webkit.WebView;
import androidx.annotation.IntDef;
import androidx.annotation.RequiresApi;
import androidx.core.content.pm.ShortcutManagerCompat;
import org.json.JSONObject;
import org.telegram.tgnet.ConnectionsManager;
import org.telegram.tgnet.SerializedData;
import org.telegram.tgnet.TLRPC;
import org.telegram.ui.ActionBar.AlertDialog;
import org.telegram.ui.ActionBar.BaseFragment;
import org.telegram.ui.Components.SwipeGestureSettingsView;
import org.telegram.ui.LaunchActivity;
import java.io.File;
import java.io.RandomAccessFile;
import java.io.UnsupportedEncodingException;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
public class SharedConfig {
/**
* V2: Ping and check time serialized
*/
private final static int PROXY_SCHEMA_V2 = 2;
private final static int PROXY_CURRENT_SCHEMA_VERSION = PROXY_SCHEMA_V2;
public final static int PASSCODE_TYPE_PIN = 0,
PASSCODE_TYPE_PASSWORD = 1;
private static int legacyDevicePerformanceClass = -1;
public static boolean loopStickers() {
return LiteMode.isEnabled(LiteMode.FLAG_ANIMATED_STICKERS_CHAT);
}
public static boolean readOnlyStorageDirAlertShowed;
public static void checkSdCard(File file) {
if (file == null || SharedConfig.storageCacheDir == null || readOnlyStorageDirAlertShowed) {
return;
}
if (file.getPath().startsWith(SharedConfig.storageCacheDir)) {
AndroidUtilities.runOnUIThread(() -> {
if (readOnlyStorageDirAlertShowed) {
return;
}
BaseFragment fragment = LaunchActivity.getLastFragment();
if (fragment != null && fragment.getParentActivity() != null) {
SharedConfig.storageCacheDir = null;
SharedConfig.saveConfig();
ImageLoader.getInstance().checkMediaPaths(() -> {
});
readOnlyStorageDirAlertShowed = true;
AlertDialog.Builder dialog = new AlertDialog.Builder(fragment.getParentActivity());
dialog.setTitle(LocaleController.getString("SdCardError", R.string.SdCardError));
dialog.setSubtitle(LocaleController.getString("SdCardErrorDescription", R.string.SdCardErrorDescription));
dialog.setPositiveButton(LocaleController.getString("DoNotUseSDCard", R.string.DoNotUseSDCard), (dialog1, which) -> {
});
Dialog dialogFinal = dialog.create();
dialogFinal.setCanceledOnTouchOutside(false);
dialogFinal.show();
}
});
}
}
static Boolean allowPreparingHevcPlayers;
public static boolean allowPreparingHevcPlayers() {
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.M) {
return false;
}
if (allowPreparingHevcPlayers == null) {
int codecCount = MediaCodecList.getCodecCount();
int maxInstances = 0;
int capabilities = 0;
for (int i = 0; i < codecCount; i++) {
MediaCodecInfo codecInfo = MediaCodecList.getCodecInfoAt(i);
if (codecInfo.isEncoder()) {
continue;
}
boolean found = false;
for (int k = 0; k < codecInfo.getSupportedTypes().length; k++) {
if (codecInfo.getSupportedTypes()[k].contains("video/hevc")) {
found = true;
break;
}
}
if (!found) {
continue;
}
capabilities = codecInfo.getCapabilitiesForType("video/hevc").getMaxSupportedInstances();
if (capabilities > maxInstances) {
maxInstances = capabilities;
}
}
allowPreparingHevcPlayers = maxInstances >= 8;
}
return allowPreparingHevcPlayers;
}
public static void togglePaymentByInvoice() {
payByInvoice = !payByInvoice;
ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE)
.edit()
.putBoolean("payByInvoice", payByInvoice)
.apply();
}
public static void toggleSurfaceInStories() {
useSurfaceInStories = !useSurfaceInStories;
ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE)
.edit()
.putBoolean("useSurfaceInStories", useSurfaceInStories)
.apply();
}
public static void togglePhotoViewerBlur() {
photoViewerBlur = !photoViewerBlur;
ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE)
.edit()
.putBoolean("photoViewerBlur", photoViewerBlur)
.apply();
}
private static String goodHevcEncoder;
private static HashSet<String> hevcEncoderWhitelist = new HashSet<>();
static {
hevcEncoderWhitelist.add("c2.exynos.hevc.encoder");
hevcEncoderWhitelist.add("OMX.Exynos.HEVC.Encoder".toLowerCase());
}
@RequiresApi(api = Build.VERSION_CODES.Q)
public static String findGoodHevcEncoder() {
if (goodHevcEncoder == null) {
int codecCount = MediaCodecList.getCodecCount();
for (int i = 0; i < codecCount; i++) {
MediaCodecInfo codecInfo = MediaCodecList.getCodecInfoAt(i);
if (!codecInfo.isEncoder()) {
continue;
}
for (int k = 0; k < codecInfo.getSupportedTypes().length; k++) {
if (codecInfo.getSupportedTypes()[k].contains("video/hevc") && codecInfo.isHardwareAccelerated() && isWhitelisted(codecInfo)) {
return goodHevcEncoder = codecInfo.getName();
}
}
}
goodHevcEncoder = "";
}
return TextUtils.isEmpty(goodHevcEncoder) ? null : goodHevcEncoder;
}
private static boolean isWhitelisted(MediaCodecInfo codecInfo) {
if (BuildVars.DEBUG_PRIVATE_VERSION) {
return true;
}
return hevcEncoderWhitelist.contains(codecInfo.getName().toLowerCase());
}
@Retention(RetentionPolicy.SOURCE)
@IntDef({
PASSCODE_TYPE_PIN,
PASSCODE_TYPE_PASSWORD
})
public @interface PasscodeType {}
public final static int SAVE_TO_GALLERY_FLAG_PEER = 1;
public final static int SAVE_TO_GALLERY_FLAG_GROUP = 2;
public final static int SAVE_TO_GALLERY_FLAG_CHANNELS = 4;
@PushListenerController.PushType
public static int pushType = PushListenerController.PUSH_TYPE_FIREBASE;
public static String pushString = "";
public static String pushStringStatus = "";
public static long pushStringGetTimeStart;
public static long pushStringGetTimeEnd;
public static boolean pushStatSent;
public static byte[] pushAuthKey;
public static byte[] pushAuthKeyId;
public static String directShareHash;
@PasscodeType
public static int passcodeType;
public static String passcodeHash = "";
public static long passcodeRetryInMs;
public static long lastUptimeMillis;
public static int badPasscodeTries;
public static byte[] passcodeSalt = new byte[0];
public static boolean appLocked;
public static int autoLockIn = 60 * 60;
public static boolean saveIncomingPhotos;
public static boolean allowScreenCapture;
public static int lastPauseTime;
public static boolean isWaitingForPasscodeEnter;
public static boolean useFingerprint = true;
public static String lastUpdateVersion;
public static int suggestStickers;
public static boolean suggestAnimatedEmoji;
public static int keepMedia = CacheByChatsController.KEEP_MEDIA_ONE_MONTH; //deprecated
public static int lastKeepMediaCheckTime;
public static int lastLogsCheckTime;
public static int searchMessagesAsListHintShows;
public static int textSelectionHintShows;
public static int scheduledOrNoSoundHintShows;
public static long scheduledOrNoSoundHintSeenAt;
public static int scheduledHintShows;
public static long scheduledHintSeenAt;
public static int lockRecordAudioVideoHint;
public static boolean forwardingOptionsHintShown, replyingOptionsHintShown;
public static boolean searchMessagesAsListUsed;
public static boolean stickersReorderingHintUsed;
public static int dayNightWallpaperSwitchHint;
public static boolean storyReactionsLongPressHint;
public static boolean storiesIntroShown;
public static boolean disableVoiceAudioEffects;
public static boolean forceDisableTabletMode;
public static boolean updateStickersOrderOnSend = true;
public static boolean bigCameraForRound;
public static boolean useSurfaceInStories;
public static boolean photoViewerBlur = true;
public static boolean payByInvoice;
public static int stealthModeSendMessageConfirm = 2;
private static int lastLocalId = -210000;
public static String storageCacheDir;
private static String passportConfigJson = "";
private static HashMap<String, String> passportConfigMap;
public static int passportConfigHash;
private static boolean configLoaded;
private static final Object sync = new Object();
private static final Object localIdSync = new Object();
// public static int saveToGalleryFlags;
public static int mapPreviewType = 2;
public static boolean chatBubbles = Build.VERSION.SDK_INT >= 30;
public static boolean raiseToSpeak = false;
public static boolean raiseToListen = true;
public static boolean nextMediaTap = true;
public static boolean recordViaSco = false;
public static boolean customTabs = true;
public static boolean directShare = true;
public static boolean inappCamera = true;
public static boolean roundCamera16to9 = true;
public static boolean noSoundHintShowed = false;
public static boolean streamMedia = true;
public static boolean streamAllVideo = false;
public static boolean streamMkv = false;
public static boolean saveStreamMedia = true;
public static boolean pauseMusicOnRecord = false;
public static boolean pauseMusicOnMedia = false;
public static boolean noiseSupression;
public static final boolean noStatusBar = true;
public static boolean debugWebView;
public static boolean sortContactsByName;
public static boolean sortFilesByName;
public static boolean shuffleMusic;
public static boolean playOrderReversed;
public static boolean hasCameraCache;
public static boolean showNotificationsForAllAccounts = true;
public static int repeatMode;
public static boolean allowBigEmoji;
public static boolean useSystemEmoji;
public static int fontSize = 16;
public static boolean fontSizeIsDefault;
public static int bubbleRadius = 17;
public static int ivFontSize = 16;
public static boolean proxyRotationEnabled;
public static int proxyRotationTimeout;
public static int messageSeenHintCount;
public static int emojiInteractionsHintCount;
public static int dayNightThemeSwitchHintCount;
public static TLRPC.TL_help_appUpdate pendingAppUpdate;
public static int pendingAppUpdateBuildVersion;
public static long lastUpdateCheckTime;
public static boolean hasEmailLogin;
@PerformanceClass
private static int devicePerformanceClass;
@PerformanceClass
private static int overrideDevicePerformanceClass;
public static boolean drawDialogIcons;
public static boolean useThreeLinesLayout;
public static boolean archiveHidden;
private static int chatSwipeAction;
public static int distanceSystemType;
public static int mediaColumnsCount = 3;
public static int storiesColumnsCount = 3;
public static int fastScrollHintCount = 3;
public static boolean dontAskManageStorage;
public static boolean translateChats = true;
public static boolean isFloatingDebugActive;
public static LiteMode liteMode;
private static final int[] LOW_SOC = {
-1775228513, // EXYNOS 850
802464304, // EXYNOS 7872
802464333, // EXYNOS 7880
802464302, // EXYNOS 7870
2067362118, // MSM8953
2067362060, // MSM8937
2067362084, // MSM8940
2067362241, // MSM8992
2067362117, // MSM8952
2067361998, // MSM8917
-1853602818 // SDM439
};
static {
loadConfig();
}
public static class ProxyInfo {
public String address;
public int port;
public String username;
public String password;
public String secret;
public long proxyCheckPingId;
public long ping;
public boolean checking;
public boolean available;
public long availableCheckTime;
public ProxyInfo(String address, int port, String username, String password, String secret) {
this.address = address;
this.port = port;
this.username = username;
this.password = password;
this.secret = secret;
if (this.address == null) {
this.address = "";
}
if (this.password == null) {
this.password = "";
}
if (this.username == null) {
this.username = "";
}
if (this.secret == null) {
this.secret = "";
}
}
public String getLink() {
StringBuilder url = new StringBuilder(!TextUtils.isEmpty(secret) ? "https://t.me/proxy?" : "https://t.me/socks?");
try {
url.append("server=").append(URLEncoder.encode(address, "UTF-8")).append("&").append("port=").append(port);
if (!TextUtils.isEmpty(username)) {
url.append("&user=").append(URLEncoder.encode(username, "UTF-8"));
}
if (!TextUtils.isEmpty(password)) {
url.append("&pass=").append(URLEncoder.encode(password, "UTF-8"));
}
if (!TextUtils.isEmpty(secret)) {
url.append("&secret=").append(URLEncoder.encode(secret, "UTF-8"));
}
} catch (UnsupportedEncodingException ignored) {}
return url.toString();
}
}
public static ArrayList<ProxyInfo> proxyList = new ArrayList<>();
private static boolean proxyListLoaded;
public static ProxyInfo currentProxy;
public static void saveConfig() {
synchronized (sync) {
try {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("userconfing", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.putBoolean("saveIncomingPhotos", saveIncomingPhotos);
editor.putString("passcodeHash1", passcodeHash);
editor.putString("passcodeSalt", passcodeSalt.length > 0 ? Base64.encodeToString(passcodeSalt, Base64.DEFAULT) : "");
editor.putBoolean("appLocked", appLocked);
editor.putInt("passcodeType", passcodeType);
editor.putLong("passcodeRetryInMs", passcodeRetryInMs);
editor.putLong("lastUptimeMillis", lastUptimeMillis);
editor.putInt("badPasscodeTries", badPasscodeTries);
editor.putInt("autoLockIn", autoLockIn);
editor.putInt("lastPauseTime", lastPauseTime);
editor.putString("lastUpdateVersion2", lastUpdateVersion);
editor.putBoolean("useFingerprint", useFingerprint);
editor.putBoolean("allowScreenCapture", allowScreenCapture);
editor.putString("pushString2", pushString);
editor.putInt("pushType", pushType);
editor.putBoolean("pushStatSent", pushStatSent);
editor.putString("pushAuthKey", pushAuthKey != null ? Base64.encodeToString(pushAuthKey, Base64.DEFAULT) : "");
editor.putInt("lastLocalId", lastLocalId);
editor.putString("passportConfigJson", passportConfigJson);
editor.putInt("passportConfigHash", passportConfigHash);
editor.putBoolean("sortContactsByName", sortContactsByName);
editor.putBoolean("sortFilesByName", sortFilesByName);
editor.putInt("textSelectionHintShows", textSelectionHintShows);
editor.putInt("scheduledOrNoSoundHintShows", scheduledOrNoSoundHintShows);
editor.putLong("scheduledOrNoSoundHintSeenAt", scheduledOrNoSoundHintSeenAt);
editor.putInt("scheduledHintShows", scheduledHintShows);
editor.putLong("scheduledHintSeenAt", scheduledHintSeenAt);
editor.putBoolean("forwardingOptionsHintShown", forwardingOptionsHintShown);
editor.putBoolean("replyingOptionsHintShown", replyingOptionsHintShown);
editor.putInt("lockRecordAudioVideoHint", lockRecordAudioVideoHint);
editor.putString("storageCacheDir", !TextUtils.isEmpty(storageCacheDir) ? storageCacheDir : "");
editor.putBoolean("proxyRotationEnabled", proxyRotationEnabled);
editor.putInt("proxyRotationTimeout", proxyRotationTimeout);
if (pendingAppUpdate != null) {
try {
SerializedData data = new SerializedData(pendingAppUpdate.getObjectSize());
pendingAppUpdate.serializeToStream(data);
String str = Base64.encodeToString(data.toByteArray(), Base64.DEFAULT);
editor.putString("appUpdate", str);
editor.putInt("appUpdateBuild", pendingAppUpdateBuildVersion);
data.cleanup();
} catch (Exception ignore) {
}
} else {
editor.remove("appUpdate");
}
editor.putLong("appUpdateCheckTime", lastUpdateCheckTime);
editor.apply();
editor = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Context.MODE_PRIVATE).edit();
editor.putBoolean("hasEmailLogin", hasEmailLogin);
editor.putBoolean("floatingDebugActive", isFloatingDebugActive);
editor.putBoolean("record_via_sco", recordViaSco);
editor.apply();
} catch (Exception e) {
FileLog.e(e);
}
}
}
public static int getLastLocalId() {
int value;
synchronized (localIdSync) {
value = lastLocalId--;
}
return value;
}
public static void loadConfig() {
synchronized (sync) {
if (configLoaded || ApplicationLoader.applicationContext == null) {
return;
}
BackgroundActivityPrefs.prefs = ApplicationLoader.applicationContext.getSharedPreferences("background_activity", Context.MODE_PRIVATE);
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("userconfing", Context.MODE_PRIVATE);
saveIncomingPhotos = preferences.getBoolean("saveIncomingPhotos", false);
passcodeHash = preferences.getString("passcodeHash1", "");
appLocked = preferences.getBoolean("appLocked", false);
passcodeType = preferences.getInt("passcodeType", 0);
passcodeRetryInMs = preferences.getLong("passcodeRetryInMs", 0);
lastUptimeMillis = preferences.getLong("lastUptimeMillis", 0);
badPasscodeTries = preferences.getInt("badPasscodeTries", 0);
autoLockIn = preferences.getInt("autoLockIn", 60 * 60);
lastPauseTime = preferences.getInt("lastPauseTime", 0);
useFingerprint = preferences.getBoolean("useFingerprint", true);
lastUpdateVersion = preferences.getString("lastUpdateVersion2", "3.5");
allowScreenCapture = preferences.getBoolean("allowScreenCapture", false);
lastLocalId = preferences.getInt("lastLocalId", -210000);
pushString = preferences.getString("pushString2", "");
pushType = preferences.getInt("pushType", PushListenerController.PUSH_TYPE_FIREBASE);
pushStatSent = preferences.getBoolean("pushStatSent", false);
passportConfigJson = preferences.getString("passportConfigJson", "");
passportConfigHash = preferences.getInt("passportConfigHash", 0);
storageCacheDir = preferences.getString("storageCacheDir", null);
proxyRotationEnabled = preferences.getBoolean("proxyRotationEnabled", false);
proxyRotationTimeout = preferences.getInt("proxyRotationTimeout", ProxyRotationController.DEFAULT_TIMEOUT_INDEX);
String authKeyString = preferences.getString("pushAuthKey", null);
if (!TextUtils.isEmpty(authKeyString)) {
pushAuthKey = Base64.decode(authKeyString, Base64.DEFAULT);
}
if (passcodeHash.length() > 0 && lastPauseTime == 0) {
lastPauseTime = (int) (SystemClock.elapsedRealtime() / 1000 - 60 * 10);
}
String passcodeSaltString = preferences.getString("passcodeSalt", "");
if (passcodeSaltString.length() > 0) {
passcodeSalt = Base64.decode(passcodeSaltString, Base64.DEFAULT);
} else {
passcodeSalt = new byte[0];
}
lastUpdateCheckTime = preferences.getLong("appUpdateCheckTime", System.currentTimeMillis());
try {
String update = preferences.getString("appUpdate", null);
if (update != null) {
pendingAppUpdateBuildVersion = preferences.getInt("appUpdateBuild", BuildVars.BUILD_VERSION);
byte[] arr = Base64.decode(update, Base64.DEFAULT);
if (arr != null) {
SerializedData data = new SerializedData(arr);
pendingAppUpdate = (TLRPC.TL_help_appUpdate) TLRPC.help_AppUpdate.TLdeserialize(data, data.readInt32(false), false);
data.cleanup();
}
}
if (pendingAppUpdate != null) {
long updateTime = 0;
int updateVersion = 0;
String updateVersionString = null;
try {
PackageInfo packageInfo = ApplicationLoader.applicationContext.getPackageManager().getPackageInfo(ApplicationLoader.applicationContext.getPackageName(), 0);
updateVersion = packageInfo.versionCode;
updateVersionString = packageInfo.versionName;
} catch (Exception e) {
FileLog.e(e);
}
if (updateVersion == 0) {
updateVersion = BuildVars.BUILD_VERSION;
}
if (updateVersionString == null) {
updateVersionString = BuildVars.BUILD_VERSION_STRING;
}
if (pendingAppUpdateBuildVersion != updateVersion || pendingAppUpdate.version == null || updateVersionString.compareTo(pendingAppUpdate.version) >= 0 || BuildVars.DEBUG_PRIVATE_VERSION) {
pendingAppUpdate = null;
AndroidUtilities.runOnUIThread(SharedConfig::saveConfig);
}
}
} catch (Exception e) {
FileLog.e(e);
}
preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
SaveToGallerySettingsHelper.load(preferences);
mapPreviewType = preferences.getInt("mapPreviewType", 2);
raiseToListen = preferences.getBoolean("raise_to_listen", true);
raiseToSpeak = preferences.getBoolean("raise_to_speak", false);
nextMediaTap = preferences.getBoolean("next_media_on_tap", true);
recordViaSco = preferences.getBoolean("record_via_sco", false);
customTabs = preferences.getBoolean("custom_tabs", true);
directShare = preferences.getBoolean("direct_share", true);
shuffleMusic = preferences.getBoolean("shuffleMusic", false);
playOrderReversed = !shuffleMusic && preferences.getBoolean("playOrderReversed", false);
inappCamera = preferences.getBoolean("inappCamera", true);
hasCameraCache = preferences.contains("cameraCache");
roundCamera16to9 = true;
repeatMode = preferences.getInt("repeatMode", 0);
fontSize = preferences.getInt("fons_size", AndroidUtilities.isTablet() ? 18 : 16);
fontSizeIsDefault = !preferences.contains("fons_size");
bubbleRadius = preferences.getInt("bubbleRadius", 17);
ivFontSize = preferences.getInt("iv_font_size", fontSize);
allowBigEmoji = preferences.getBoolean("allowBigEmoji", true);
useSystemEmoji = preferences.getBoolean("useSystemEmoji", false);
streamMedia = preferences.getBoolean("streamMedia", true);
saveStreamMedia = preferences.getBoolean("saveStreamMedia", true);
pauseMusicOnRecord = preferences.getBoolean("pauseMusicOnRecord", false);
pauseMusicOnMedia = preferences.getBoolean("pauseMusicOnMedia", false);
forceDisableTabletMode = preferences.getBoolean("forceDisableTabletMode", false);
streamAllVideo = preferences.getBoolean("streamAllVideo", BuildVars.DEBUG_VERSION);
streamMkv = preferences.getBoolean("streamMkv", false);
suggestStickers = preferences.getInt("suggestStickers", 0);
suggestAnimatedEmoji = preferences.getBoolean("suggestAnimatedEmoji", true);
overrideDevicePerformanceClass = preferences.getInt("overrideDevicePerformanceClass", -1);
devicePerformanceClass = preferences.getInt("devicePerformanceClass", -1);
sortContactsByName = preferences.getBoolean("sortContactsByName", false);
sortFilesByName = preferences.getBoolean("sortFilesByName", false);
noSoundHintShowed = preferences.getBoolean("noSoundHintShowed", false);
directShareHash = preferences.getString("directShareHash2", null);
useThreeLinesLayout = preferences.getBoolean("useThreeLinesLayout", false);
archiveHidden = preferences.getBoolean("archiveHidden", false);
distanceSystemType = preferences.getInt("distanceSystemType", 0);
keepMedia = preferences.getInt("keep_media", CacheByChatsController.KEEP_MEDIA_ONE_MONTH);
debugWebView = preferences.getBoolean("debugWebView", false);
lastKeepMediaCheckTime = preferences.getInt("lastKeepMediaCheckTime", 0);
lastLogsCheckTime = preferences.getInt("lastLogsCheckTime", 0);
searchMessagesAsListHintShows = preferences.getInt("searchMessagesAsListHintShows", 0);
searchMessagesAsListUsed = preferences.getBoolean("searchMessagesAsListUsed", false);
stickersReorderingHintUsed = preferences.getBoolean("stickersReorderingHintUsed", false);
storyReactionsLongPressHint = preferences.getBoolean("storyReactionsLongPressHint", false);
storiesIntroShown = preferences.getBoolean("storiesIntroShown", false);
textSelectionHintShows = preferences.getInt("textSelectionHintShows", 0);
scheduledOrNoSoundHintShows = preferences.getInt("scheduledOrNoSoundHintShows", 0);
scheduledOrNoSoundHintSeenAt = preferences.getLong("scheduledOrNoSoundHintSeenAt", 0);
scheduledHintShows = preferences.getInt("scheduledHintShows", 0);
scheduledHintSeenAt = preferences.getLong("scheduledHintSeenAt", 0);
forwardingOptionsHintShown = preferences.getBoolean("forwardingOptionsHintShown", false);
replyingOptionsHintShown = preferences.getBoolean("replyingOptionsHintShown", false);
lockRecordAudioVideoHint = preferences.getInt("lockRecordAudioVideoHint", 0);
disableVoiceAudioEffects = preferences.getBoolean("disableVoiceAudioEffects", false);
noiseSupression = preferences.getBoolean("noiseSupression", false);
chatSwipeAction = preferences.getInt("ChatSwipeAction", -1);
messageSeenHintCount = preferences.getInt("messageSeenCount", 3);
emojiInteractionsHintCount = preferences.getInt("emojiInteractionsHintCount", 3);
dayNightThemeSwitchHintCount = preferences.getInt("dayNightThemeSwitchHintCount", 3);
stealthModeSendMessageConfirm = preferences.getInt("stealthModeSendMessageConfirm", 2);
mediaColumnsCount = preferences.getInt("mediaColumnsCount", 3);
storiesColumnsCount = preferences.getInt("storiesColumnsCount", 3);
fastScrollHintCount = preferences.getInt("fastScrollHintCount", 3);
dontAskManageStorage = preferences.getBoolean("dontAskManageStorage", false);
hasEmailLogin = preferences.getBoolean("hasEmailLogin", false);
isFloatingDebugActive = preferences.getBoolean("floatingDebugActive", false);
updateStickersOrderOnSend = preferences.getBoolean("updateStickersOrderOnSend", true);
dayNightWallpaperSwitchHint = preferences.getInt("dayNightWallpaperSwitchHint", 0);
bigCameraForRound = preferences.getBoolean("bigCameraForRound", false);
useSurfaceInStories = preferences.getBoolean("useSurfaceInStories", Build.VERSION.SDK_INT >= 30);
payByInvoice = preferences.getBoolean("payByInvoice", false);
photoViewerBlur = preferences.getBoolean("photoViewerBlur", true);
loadDebugConfig(preferences);
preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
showNotificationsForAllAccounts = preferences.getBoolean("AllAccounts", true);
configLoaded = true;
try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && debugWebView) {
WebView.setWebContentsDebuggingEnabled(true);
}
} catch (Exception e) {
FileLog.e(e);
}
}
}
public static void updateTabletConfig() {
if (fontSizeIsDefault) {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
fontSize = preferences.getInt("fons_size", AndroidUtilities.isTablet() ? 18 : 16);
ivFontSize = preferences.getInt("iv_font_size", fontSize);
}
}
public static void increaseBadPasscodeTries() {
badPasscodeTries++;
if (badPasscodeTries >= 3) {
switch (badPasscodeTries) {
case 3:
passcodeRetryInMs = 5000;
break;
case 4:
passcodeRetryInMs = 10000;
break;
case 5:
passcodeRetryInMs = 15000;
break;
case 6:
passcodeRetryInMs = 20000;
break;
case 7:
passcodeRetryInMs = 25000;
break;
default:
passcodeRetryInMs = 30000;
break;
}
lastUptimeMillis = SystemClock.elapsedRealtime();
}
saveConfig();
}
public static boolean isAutoplayVideo() {
return LiteMode.isEnabled(LiteMode.FLAG_AUTOPLAY_VIDEOS);
}
public static boolean isAutoplayGifs() {
return LiteMode.isEnabled(LiteMode.FLAG_AUTOPLAY_GIFS);
}
public static boolean isPassportConfigLoaded() {
return passportConfigMap != null;
}
public static void setPassportConfig(String json, int hash) {
passportConfigMap = null;
passportConfigJson = json;
passportConfigHash = hash;
saveConfig();
getCountryLangs();
}
public static HashMap<String, String> getCountryLangs() {
if (passportConfigMap == null) {
passportConfigMap = new HashMap<>();
try {
JSONObject object = new JSONObject(passportConfigJson);
Iterator<String> iter = object.keys();
while (iter.hasNext()) {
String key = iter.next();
passportConfigMap.put(key.toUpperCase(), object.getString(key).toUpperCase());
}
} catch (Throwable e) {
FileLog.e(e);
}
}
return passportConfigMap;
}
public static boolean isAppUpdateAvailable() {
if (pendingAppUpdate == null || pendingAppUpdate.document == null || !ApplicationLoader.isStandaloneBuild()) {
return false;
}
int currentVersion;
try {
PackageInfo pInfo = ApplicationLoader.applicationContext.getPackageManager().getPackageInfo(ApplicationLoader.applicationContext.getPackageName(), 0);
currentVersion = pInfo.versionCode;
} catch (Exception e) {
FileLog.e(e);
currentVersion = BuildVars.BUILD_VERSION;
}
return pendingAppUpdateBuildVersion == currentVersion;
}
public static boolean setNewAppVersionAvailable(TLRPC.TL_help_appUpdate update) {
String updateVersionString = null;
int versionCode = 0;
try {
PackageInfo packageInfo = ApplicationLoader.applicationContext.getPackageManager().getPackageInfo(ApplicationLoader.applicationContext.getPackageName(), 0);
versionCode = packageInfo.versionCode;
updateVersionString = packageInfo.versionName;
} catch (Exception e) {
FileLog.e(e);
}
if (versionCode == 0) {
versionCode = BuildVars.BUILD_VERSION;
}
if (updateVersionString == null) {
updateVersionString = BuildVars.BUILD_VERSION_STRING;
}
if (update.version == null || versionBiggerOrEqual(updateVersionString, update.version)) {
return false;
}
pendingAppUpdate = update;
pendingAppUpdateBuildVersion = versionCode;
saveConfig();
return true;
}
// returns a >= b
private static boolean versionBiggerOrEqual(String a, String b) {
String[] partsA = a.split("\\.");
String[] partsB = b.split("\\.");
for (int i = 0; i < Math.min(partsA.length, partsB.length); ++i) {
int numA = Integer.parseInt(partsA[i]);
int numB = Integer.parseInt(partsB[i]);
if (numA < numB) {
return false;
} else if (numA > numB) {
return true;
}
}
return true;
}
public static boolean checkPasscode(String passcode) {
if (passcodeSalt.length == 0) {
boolean result = Utilities.MD5(passcode).equals(passcodeHash);
if (result) {
try {
passcodeSalt = new byte[16];
Utilities.random.nextBytes(passcodeSalt);
byte[] passcodeBytes = passcode.getBytes("UTF-8");
byte[] bytes = new byte[32 + passcodeBytes.length];
System.arraycopy(passcodeSalt, 0, bytes, 0, 16);
System.arraycopy(passcodeBytes, 0, bytes, 16, passcodeBytes.length);
System.arraycopy(passcodeSalt, 0, bytes, passcodeBytes.length + 16, 16);
passcodeHash = Utilities.bytesToHex(Utilities.computeSHA256(bytes, 0, bytes.length));
saveConfig();
} catch (Exception e) {
FileLog.e(e);
}
}
return result;
} else {
try {
byte[] passcodeBytes = passcode.getBytes("UTF-8");
byte[] bytes = new byte[32 + passcodeBytes.length];
System.arraycopy(passcodeSalt, 0, bytes, 0, 16);
System.arraycopy(passcodeBytes, 0, bytes, 16, passcodeBytes.length);
System.arraycopy(passcodeSalt, 0, bytes, passcodeBytes.length + 16, 16);
String hash = Utilities.bytesToHex(Utilities.computeSHA256(bytes, 0, bytes.length));
return passcodeHash.equals(hash);
} catch (Exception e) {
FileLog.e(e);
}
}
return false;
}
public static void clearConfig() {
saveIncomingPhotos = false;
appLocked = false;
passcodeType = PASSCODE_TYPE_PIN;
passcodeRetryInMs = 0;
lastUptimeMillis = 0;
badPasscodeTries = 0;
passcodeHash = "";
passcodeSalt = new byte[0];
autoLockIn = 60 * 60;
lastPauseTime = 0;
useFingerprint = true;
isWaitingForPasscodeEnter = false;
allowScreenCapture = false;
lastUpdateVersion = BuildVars.BUILD_VERSION_STRING;
textSelectionHintShows = 0;
scheduledOrNoSoundHintShows = 0;
scheduledOrNoSoundHintSeenAt = 0;
scheduledHintShows = 0;
scheduledHintSeenAt = 0;
lockRecordAudioVideoHint = 0;
forwardingOptionsHintShown = false;
replyingOptionsHintShown = false;
messageSeenHintCount = 3;
emojiInteractionsHintCount = 3;
dayNightThemeSwitchHintCount = 3;
stealthModeSendMessageConfirm = 2;
dayNightWallpaperSwitchHint = 0;
saveConfig();
}
public static void setSuggestStickers(int type) {
suggestStickers = type;
SharedPreferences preferences = MessagesController.getGlobalMainSettings();
SharedPreferences.Editor editor = preferences.edit();
editor.putInt("suggestStickers", suggestStickers);
editor.apply();
}
public static void setSearchMessagesAsListUsed(boolean value) {
searchMessagesAsListUsed = value;
SharedPreferences preferences = MessagesController.getGlobalMainSettings();
SharedPreferences.Editor editor = preferences.edit();
editor.putBoolean("searchMessagesAsListUsed", searchMessagesAsListUsed);
editor.apply();
}
public static void setStickersReorderingHintUsed(boolean value) {
stickersReorderingHintUsed = value;
SharedPreferences preferences = MessagesController.getGlobalMainSettings();
SharedPreferences.Editor editor = preferences.edit();
editor.putBoolean("stickersReorderingHintUsed", stickersReorderingHintUsed);
editor.apply();
}
public static void setStoriesReactionsLongPressHintUsed(boolean value) {
storyReactionsLongPressHint = value;
SharedPreferences preferences = MessagesController.getGlobalMainSettings();
SharedPreferences.Editor editor = preferences.edit();
editor.putBoolean("storyReactionsLongPressHint", storyReactionsLongPressHint);
editor.apply();
}
public static void setStoriesIntroShown(boolean isShown) {
storiesIntroShown = isShown;
SharedPreferences preferences = MessagesController.getGlobalMainSettings();
SharedPreferences.Editor editor = preferences.edit();
editor.putBoolean("storiesIntroShown", storiesIntroShown);
editor.apply();
}
public static void increaseTextSelectionHintShowed() {
SharedPreferences preferences = MessagesController.getGlobalMainSettings();
SharedPreferences.Editor editor = preferences.edit();
editor.putInt("textSelectionHintShows", ++textSelectionHintShows);
editor.apply();
}
public static void increaseDayNightWallpaperSiwtchHint() {
SharedPreferences preferences = MessagesController.getGlobalMainSettings();
SharedPreferences.Editor editor = preferences.edit();
editor.putInt("dayNightWallpaperSwitchHint", ++dayNightWallpaperSwitchHint);
editor.apply();
}
public static void removeTextSelectionHint() {
SharedPreferences preferences = MessagesController.getGlobalMainSettings();
SharedPreferences.Editor editor = preferences.edit();
editor.putInt("textSelectionHintShows", 3);
editor.apply();
}
public static void increaseScheduledOrNoSoundHintShowed() {
SharedPreferences preferences = MessagesController.getGlobalMainSettings();
SharedPreferences.Editor editor = preferences.edit();
scheduledOrNoSoundHintSeenAt = System.currentTimeMillis();
editor.putInt("scheduledOrNoSoundHintShows", ++scheduledOrNoSoundHintShows);
editor.putLong("scheduledOrNoSoundHintSeenAt", scheduledOrNoSoundHintSeenAt);
editor.apply();
}
public static void increaseScheduledHintShowed() {
SharedPreferences preferences = MessagesController.getGlobalMainSettings();
SharedPreferences.Editor editor = preferences.edit();
scheduledHintSeenAt = System.currentTimeMillis();
editor.putInt("scheduledHintShows", ++scheduledHintShows);
editor.putLong("scheduledHintSeenAt", scheduledHintSeenAt);
editor.apply();
}
public static void forwardingOptionsHintHintShowed() {
SharedPreferences preferences = MessagesController.getGlobalMainSettings();
SharedPreferences.Editor editor = preferences.edit();
forwardingOptionsHintShown = true;
editor.putBoolean("forwardingOptionsHintShown", forwardingOptionsHintShown);
editor.apply();
}
public static void replyingOptionsHintHintShowed() {
SharedPreferences preferences = MessagesController.getGlobalMainSettings();
SharedPreferences.Editor editor = preferences.edit();
replyingOptionsHintShown = true;
editor.putBoolean("replyingOptionsHintShown", replyingOptionsHintShown);
editor.apply();
}
public static void removeScheduledOrNoSoundHint() {
SharedPreferences preferences = MessagesController.getGlobalMainSettings();
SharedPreferences.Editor editor = preferences.edit();
editor.putInt("scheduledOrNoSoundHintShows", 3);
editor.apply();
}
public static void removeScheduledHint() {
SharedPreferences preferences = MessagesController.getGlobalMainSettings();
SharedPreferences.Editor editor = preferences.edit();
editor.putInt("scheduledHintShows", 3);
editor.apply();
}
public static void increaseLockRecordAudioVideoHintShowed() {
SharedPreferences preferences = MessagesController.getGlobalMainSettings();
SharedPreferences.Editor editor = preferences.edit();
editor.putInt("lockRecordAudioVideoHint", ++lockRecordAudioVideoHint);
editor.apply();
}
public static void removeLockRecordAudioVideoHint() {
SharedPreferences preferences = MessagesController.getGlobalMainSettings();
SharedPreferences.Editor editor = preferences.edit();
editor.putInt("lockRecordAudioVideoHint", 3);
editor.apply();
}
public static void increaseSearchAsListHintShows() {
SharedPreferences preferences = MessagesController.getGlobalMainSettings();
SharedPreferences.Editor editor = preferences.edit();
editor.putInt("searchMessagesAsListHintShows", ++searchMessagesAsListHintShows);
editor.apply();
}
public static void setKeepMedia(int value) {
keepMedia = value;
SharedPreferences preferences = MessagesController.getGlobalMainSettings();
SharedPreferences.Editor editor = preferences.edit();
editor.putInt("keep_media", keepMedia);
editor.apply();