2018-07-30 04:07:02 +02:00
|
|
|
/*
|
2019-01-23 18:03:33 +01:00
|
|
|
* This is the source code of Telegram for Android v. 5.x.x.
|
2018-07-30 04:07:02 +02:00
|
|
|
* It is licensed under GNU GPL v. 2 or later.
|
|
|
|
* You should have received a copy of the license in this archive (see LICENSE).
|
|
|
|
*
|
2019-01-23 18:03:33 +01:00
|
|
|
* Copyright Nikolai Kudashov, 2013-2018.
|
2018-07-30 04:07:02 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
package org.telegram.messenger;
|
|
|
|
|
|
|
|
import android.app.Activity;
|
2019-07-18 15:01:39 +02:00
|
|
|
import android.app.ActivityManager;
|
2018-07-30 04:07:02 +02:00
|
|
|
import android.content.Context;
|
|
|
|
import android.content.SharedPreferences;
|
2019-07-18 15:01:39 +02:00
|
|
|
import android.os.Build;
|
2018-07-30 04:07:02 +02:00
|
|
|
import android.os.Environment;
|
|
|
|
import android.os.SystemClock;
|
|
|
|
import android.text.TextUtils;
|
|
|
|
import android.util.Base64;
|
2019-08-22 01:53:26 +02:00
|
|
|
import android.util.SparseArray;
|
2018-07-30 04:07:02 +02:00
|
|
|
|
2018-08-27 10:33:11 +02:00
|
|
|
import org.json.JSONObject;
|
2018-07-30 04:07:02 +02:00
|
|
|
import org.telegram.tgnet.ConnectionsManager;
|
|
|
|
import org.telegram.tgnet.SerializedData;
|
|
|
|
|
|
|
|
import java.io.File;
|
2019-07-18 15:01:39 +02:00
|
|
|
import java.io.RandomAccessFile;
|
2018-07-30 04:07:02 +02:00
|
|
|
import java.util.ArrayList;
|
2018-08-27 10:33:11 +02:00
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Iterator;
|
2018-07-30 04:07:02 +02:00
|
|
|
|
|
|
|
public class SharedConfig {
|
|
|
|
|
|
|
|
public static String pushString = "";
|
2019-07-18 15:01:39 +02:00
|
|
|
public static String pushStringStatus = "";
|
2018-07-30 04:07:02 +02:00
|
|
|
public static byte[] pushAuthKey;
|
|
|
|
public static byte[] pushAuthKeyId;
|
|
|
|
|
2019-05-14 14:08:05 +02:00
|
|
|
public static long directShareHash;
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
public static boolean saveIncomingPhotos;
|
|
|
|
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 passcodeType;
|
|
|
|
public static int autoLockIn = 60 * 60;
|
|
|
|
public static boolean allowScreenCapture;
|
|
|
|
public static int lastPauseTime;
|
|
|
|
public static long lastAppPauseTime;
|
|
|
|
public static boolean isWaitingForPasscodeEnter;
|
|
|
|
public static boolean useFingerprint = true;
|
|
|
|
public static String lastUpdateVersion;
|
|
|
|
public static int suggestStickers;
|
2019-08-22 01:53:26 +02:00
|
|
|
public static boolean loopStickers;
|
|
|
|
public static int keepMedia = 2;
|
|
|
|
public static int lastKeepMediaCheckTime;
|
2018-07-30 04:07:02 +02:00
|
|
|
private static int lastLocalId = -210000;
|
|
|
|
|
2018-08-27 10:33:11 +02:00
|
|
|
private static String passportConfigJson = "";
|
|
|
|
private static HashMap<String, String> passportConfigMap;
|
|
|
|
public static int passportConfigHash;
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
private static boolean configLoaded;
|
|
|
|
private static final Object sync = new Object();
|
|
|
|
private static final Object localIdSync = new Object();
|
|
|
|
|
|
|
|
public static boolean saveToGallery;
|
|
|
|
public static int mapPreviewType = 2;
|
|
|
|
public static boolean autoplayGifs = true;
|
2019-03-03 21:40:48 +01:00
|
|
|
public static boolean autoplayVideo = true;
|
2018-07-30 04:07:02 +02:00
|
|
|
public static boolean raiseToSpeak = true;
|
|
|
|
public static boolean customTabs = true;
|
|
|
|
public static boolean directShare = true;
|
|
|
|
public static boolean inappCamera = true;
|
|
|
|
public static boolean roundCamera16to9 = true;
|
2019-03-03 21:40:48 +01:00
|
|
|
public static boolean noSoundHintShowed = false;
|
2018-07-30 04:07:02 +02:00
|
|
|
public static boolean streamMedia = true;
|
|
|
|
public static boolean streamAllVideo = false;
|
2019-03-03 21:40:48 +01:00
|
|
|
public static boolean streamMkv = false;
|
2018-07-30 04:07:02 +02:00
|
|
|
public static boolean saveStreamMedia = true;
|
2019-01-23 18:03:33 +01:00
|
|
|
public static boolean sortContactsByName;
|
2018-07-30 04:07:02 +02:00
|
|
|
public static boolean shuffleMusic;
|
|
|
|
public static boolean playOrderReversed;
|
|
|
|
public static boolean hasCameraCache;
|
2019-05-14 14:08:05 +02:00
|
|
|
public static boolean showNotificationsForAllAccounts = true;
|
2018-07-30 04:07:02 +02:00
|
|
|
public static int repeatMode;
|
|
|
|
public static boolean allowBigEmoji;
|
|
|
|
public static boolean useSystemEmoji;
|
|
|
|
public static int fontSize = AndroidUtilities.dp(16);
|
2019-07-18 15:01:39 +02:00
|
|
|
private static int devicePerformanceClass;
|
2018-07-30 04:07:02 +02:00
|
|
|
|
2019-05-14 14:08:05 +02:00
|
|
|
public static boolean drawDialogIcons;
|
|
|
|
public static boolean useThreeLinesLayout;
|
|
|
|
public static boolean archiveHidden;
|
|
|
|
|
2019-07-18 15:01:39 +02:00
|
|
|
public static int distanceSystemType;
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
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 a, int p, String u, String pw, String s) {
|
|
|
|
address = a;
|
|
|
|
port = p;
|
|
|
|
username = u;
|
|
|
|
password = pw;
|
|
|
|
secret = s;
|
|
|
|
if (address == null) {
|
|
|
|
address = "";
|
|
|
|
}
|
|
|
|
if (password == null) {
|
|
|
|
password = "";
|
|
|
|
}
|
|
|
|
if (username == null) {
|
|
|
|
username = "";
|
|
|
|
}
|
|
|
|
if (secret == null) {
|
|
|
|
secret = "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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.putLong("lastAppPauseTime", lastAppPauseTime);
|
|
|
|
editor.putString("lastUpdateVersion2", lastUpdateVersion);
|
|
|
|
editor.putBoolean("useFingerprint", useFingerprint);
|
|
|
|
editor.putBoolean("allowScreenCapture", allowScreenCapture);
|
|
|
|
editor.putString("pushString2", pushString);
|
|
|
|
editor.putString("pushAuthKey", pushAuthKey != null ? Base64.encodeToString(pushAuthKey, Base64.DEFAULT) : "");
|
|
|
|
editor.putInt("lastLocalId", lastLocalId);
|
2018-08-27 10:33:11 +02:00
|
|
|
editor.putString("passportConfigJson", passportConfigJson);
|
|
|
|
editor.putInt("passportConfigHash", passportConfigHash);
|
2019-01-23 18:03:33 +01:00
|
|
|
editor.putBoolean("sortContactsByName", sortContactsByName);
|
2018-07-30 04:07:02 +02:00
|
|
|
editor.commit();
|
|
|
|
} 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) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
lastAppPauseTime = preferences.getLong("lastAppPauseTime", 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", "");
|
2018-08-27 10:33:11 +02:00
|
|
|
passportConfigJson = preferences.getString("passportConfigJson", "");
|
|
|
|
passportConfigHash = preferences.getInt("passportConfigHash", 0);
|
2018-07-30 04:07:02 +02:00
|
|
|
String authKeyString = preferences.getString("pushAuthKey", null);
|
|
|
|
if (!TextUtils.isEmpty(authKeyString)) {
|
|
|
|
pushAuthKey = Base64.decode(authKeyString, Base64.DEFAULT);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (passcodeHash.length() > 0 && lastPauseTime == 0) {
|
|
|
|
lastPauseTime = (int) (System.currentTimeMillis() / 1000 - 60 * 10);
|
|
|
|
}
|
|
|
|
|
|
|
|
String passcodeSaltString = preferences.getString("passcodeSalt", "");
|
|
|
|
if (passcodeSaltString.length() > 0) {
|
|
|
|
passcodeSalt = Base64.decode(passcodeSaltString, Base64.DEFAULT);
|
|
|
|
} else {
|
|
|
|
passcodeSalt = new byte[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
|
|
|
|
saveToGallery = preferences.getBoolean("save_gallery", false);
|
|
|
|
autoplayGifs = preferences.getBoolean("autoplay_gif", true);
|
2019-03-03 21:40:48 +01:00
|
|
|
autoplayVideo = preferences.getBoolean("autoplay_video", true);
|
2018-07-30 04:07:02 +02:00
|
|
|
mapPreviewType = preferences.getInt("mapPreviewType", 2);
|
|
|
|
raiseToSpeak = preferences.getBoolean("raise_to_speak", true);
|
|
|
|
customTabs = preferences.getBoolean("custom_tabs", true);
|
|
|
|
directShare = preferences.getBoolean("direct_share", true);
|
|
|
|
shuffleMusic = preferences.getBoolean("shuffleMusic", false);
|
|
|
|
playOrderReversed = preferences.getBoolean("playOrderReversed", false);
|
|
|
|
inappCamera = preferences.getBoolean("inappCamera", true);
|
|
|
|
hasCameraCache = preferences.contains("cameraCache");
|
|
|
|
roundCamera16to9 = true;//preferences.getBoolean("roundCamera16to9", false);
|
|
|
|
repeatMode = preferences.getInt("repeatMode", 0);
|
|
|
|
fontSize = preferences.getInt("fons_size", AndroidUtilities.isTablet() ? 18 : 16);
|
2019-05-14 14:08:05 +02:00
|
|
|
allowBigEmoji = preferences.getBoolean("allowBigEmoji", true);
|
2018-07-30 04:07:02 +02:00
|
|
|
useSystemEmoji = preferences.getBoolean("useSystemEmoji", false);
|
|
|
|
streamMedia = preferences.getBoolean("streamMedia", true);
|
|
|
|
saveStreamMedia = preferences.getBoolean("saveStreamMedia", true);
|
|
|
|
streamAllVideo = preferences.getBoolean("streamAllVideo", BuildVars.DEBUG_VERSION);
|
2019-03-03 21:40:48 +01:00
|
|
|
streamMkv = preferences.getBoolean("streamMkv", false);
|
2018-07-30 04:07:02 +02:00
|
|
|
suggestStickers = preferences.getInt("suggestStickers", 0);
|
2019-01-23 18:03:33 +01:00
|
|
|
sortContactsByName = preferences.getBoolean("sortContactsByName", false);
|
2019-03-03 21:40:48 +01:00
|
|
|
noSoundHintShowed = preferences.getBoolean("noSoundHintShowed", false);
|
2019-05-14 14:08:05 +02:00
|
|
|
directShareHash = preferences.getLong("directShareHash", 0);
|
|
|
|
useThreeLinesLayout = preferences.getBoolean("useThreeLinesLayout", false);
|
|
|
|
archiveHidden = preferences.getBoolean("archiveHidden", false);
|
2019-07-18 15:01:39 +02:00
|
|
|
distanceSystemType = preferences.getInt("distanceSystemType", 0);
|
|
|
|
devicePerformanceClass = preferences.getInt("devicePerformanceClass", -1);
|
2019-08-22 01:53:26 +02:00
|
|
|
loopStickers = preferences.getBoolean("loopStickers", true);
|
|
|
|
keepMedia = preferences.getInt("keep_media", 2);
|
|
|
|
lastKeepMediaCheckTime = preferences.getInt("lastKeepMediaCheckTime", 0);
|
2019-05-14 14:08:05 +02:00
|
|
|
|
|
|
|
preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
|
|
|
|
showNotificationsForAllAccounts = preferences.getBoolean("AllAccounts", true);
|
2018-07-30 04:07:02 +02:00
|
|
|
|
|
|
|
configLoaded = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void increaseBadPasscodeTries() {
|
|
|
|
SharedConfig.badPasscodeTries++;
|
|
|
|
if (badPasscodeTries >= 3) {
|
|
|
|
switch (SharedConfig.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;
|
|
|
|
}
|
|
|
|
SharedConfig.lastUptimeMillis = SystemClock.elapsedRealtime();
|
|
|
|
}
|
|
|
|
saveConfig();
|
|
|
|
}
|
|
|
|
|
2018-08-27 10:33:11 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
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 = 0;
|
|
|
|
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;
|
|
|
|
saveConfig();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setSuggestStickers(int type) {
|
|
|
|
suggestStickers = type;
|
|
|
|
SharedPreferences preferences = MessagesController.getGlobalMainSettings();
|
|
|
|
SharedPreferences.Editor editor = preferences.edit();
|
|
|
|
editor.putInt("suggestStickers", suggestStickers);
|
|
|
|
editor.commit();
|
|
|
|
}
|
|
|
|
|
2019-08-22 01:53:26 +02:00
|
|
|
public static void setKeepMedia(int value) {
|
|
|
|
keepMedia = value;
|
|
|
|
SharedPreferences preferences = MessagesController.getGlobalMainSettings();
|
|
|
|
SharedPreferences.Editor editor = preferences.edit();
|
|
|
|
editor.putInt("keep_media", keepMedia);
|
|
|
|
editor.commit();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void checkKeepMedia() {
|
|
|
|
int time = (int) (System.currentTimeMillis() / 1000);
|
|
|
|
if (keepMedia == 2 || Math.abs(time - lastKeepMediaCheckTime) < 24 * 60 * 60) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
lastKeepMediaCheckTime = time;
|
|
|
|
Utilities.globalQueue.postRunnable(() -> {
|
|
|
|
int days;
|
|
|
|
if (keepMedia == 0) {
|
|
|
|
days = 7;
|
|
|
|
} else if (keepMedia == 1) {
|
|
|
|
days = 30;
|
|
|
|
} else {
|
|
|
|
days = 3;
|
|
|
|
}
|
|
|
|
long currentTime = time - 60 * 60 * 24 * days;
|
|
|
|
final SparseArray<File> paths = ImageLoader.getInstance().createMediaPaths();
|
|
|
|
for (int a = 0; a < paths.size(); a++) {
|
|
|
|
if (paths.keyAt(a) == FileLoader.MEDIA_DIR_CACHE) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
Utilities.clearDir(paths.valueAt(a).getAbsolutePath(), 0, currentTime);
|
|
|
|
} catch (Throwable e) {
|
|
|
|
FileLog.e(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SharedPreferences preferences = MessagesController.getGlobalMainSettings();
|
|
|
|
SharedPreferences.Editor editor = preferences.edit();
|
|
|
|
editor.putInt("lastKeepMediaCheckTime", lastKeepMediaCheckTime);
|
|
|
|
editor.commit();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void toggleLoopStickers() {
|
|
|
|
loopStickers = !loopStickers;
|
|
|
|
SharedPreferences preferences = MessagesController.getGlobalMainSettings();
|
|
|
|
SharedPreferences.Editor editor = preferences.edit();
|
|
|
|
editor.putBoolean("loopStickers", loopStickers);
|
|
|
|
editor.commit();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void toggleBigEmoji() {
|
|
|
|
allowBigEmoji = !allowBigEmoji;
|
|
|
|
SharedPreferences preferences = MessagesController.getGlobalMainSettings();
|
|
|
|
SharedPreferences.Editor editor = preferences.edit();
|
|
|
|
editor.putBoolean("allowBigEmoji", allowBigEmoji);
|
|
|
|
editor.commit();
|
|
|
|
}
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
public static void toggleShuffleMusic(int type) {
|
|
|
|
if (type == 2) {
|
|
|
|
shuffleMusic = !shuffleMusic;
|
|
|
|
} else {
|
|
|
|
playOrderReversed = !playOrderReversed;
|
|
|
|
}
|
|
|
|
MediaController.getInstance().checkIsNextMediaFileDownloaded();
|
|
|
|
SharedPreferences preferences = MessagesController.getGlobalMainSettings();
|
|
|
|
SharedPreferences.Editor editor = preferences.edit();
|
|
|
|
editor.putBoolean("shuffleMusic", shuffleMusic);
|
|
|
|
editor.putBoolean("playOrderReversed", playOrderReversed);
|
|
|
|
editor.commit();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void toggleRepeatMode() {
|
|
|
|
repeatMode++;
|
|
|
|
if (repeatMode > 2) {
|
|
|
|
repeatMode = 0;
|
|
|
|
}
|
|
|
|
SharedPreferences preferences = MessagesController.getGlobalMainSettings();
|
|
|
|
SharedPreferences.Editor editor = preferences.edit();
|
|
|
|
editor.putInt("repeatMode", repeatMode);
|
|
|
|
editor.commit();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void toggleSaveToGallery() {
|
|
|
|
saveToGallery = !saveToGallery;
|
|
|
|
SharedPreferences preferences = MessagesController.getGlobalMainSettings();
|
|
|
|
SharedPreferences.Editor editor = preferences.edit();
|
|
|
|
editor.putBoolean("save_gallery", saveToGallery);
|
|
|
|
editor.commit();
|
|
|
|
checkSaveToGalleryFiles();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void toggleAutoplayGifs() {
|
|
|
|
autoplayGifs = !autoplayGifs;
|
|
|
|
SharedPreferences preferences = MessagesController.getGlobalMainSettings();
|
|
|
|
SharedPreferences.Editor editor = preferences.edit();
|
|
|
|
editor.putBoolean("autoplay_gif", autoplayGifs);
|
|
|
|
editor.commit();
|
|
|
|
}
|
|
|
|
|
2019-05-14 14:08:05 +02:00
|
|
|
public static void setUseThreeLinesLayout(boolean value) {
|
|
|
|
useThreeLinesLayout = value;
|
|
|
|
SharedPreferences preferences = MessagesController.getGlobalMainSettings();
|
|
|
|
SharedPreferences.Editor editor = preferences.edit();
|
|
|
|
editor.putBoolean("useThreeLinesLayout", useThreeLinesLayout);
|
|
|
|
editor.commit();
|
|
|
|
NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.dialogsNeedReload, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void toggleArchiveHidden() {
|
|
|
|
archiveHidden = !archiveHidden;
|
|
|
|
SharedPreferences preferences = MessagesController.getGlobalMainSettings();
|
|
|
|
SharedPreferences.Editor editor = preferences.edit();
|
|
|
|
editor.putBoolean("archiveHidden", archiveHidden);
|
|
|
|
editor.commit();
|
|
|
|
}
|
|
|
|
|
2019-03-03 21:40:48 +01:00
|
|
|
public static void toggleAutoplayVideo() {
|
|
|
|
autoplayVideo = !autoplayVideo;
|
|
|
|
SharedPreferences preferences = MessagesController.getGlobalMainSettings();
|
|
|
|
SharedPreferences.Editor editor = preferences.edit();
|
|
|
|
editor.putBoolean("autoplay_video", autoplayVideo);
|
|
|
|
editor.commit();
|
|
|
|
}
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
public static boolean isSecretMapPreviewSet() {
|
|
|
|
SharedPreferences preferences = MessagesController.getGlobalMainSettings();
|
|
|
|
return preferences.contains("mapPreviewType");
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setSecretMapPreviewType(int value) {
|
|
|
|
mapPreviewType = value;
|
|
|
|
SharedPreferences preferences = MessagesController.getGlobalMainSettings();
|
|
|
|
SharedPreferences.Editor editor = preferences.edit();
|
|
|
|
editor.putInt("mapPreviewType", mapPreviewType);
|
|
|
|
editor.commit();
|
|
|
|
}
|
|
|
|
|
2019-03-03 21:40:48 +01:00
|
|
|
public static void setNoSoundHintShowed(boolean value) {
|
|
|
|
if (noSoundHintShowed == value) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
noSoundHintShowed = value;
|
|
|
|
SharedPreferences preferences = MessagesController.getGlobalMainSettings();
|
|
|
|
SharedPreferences.Editor editor = preferences.edit();
|
|
|
|
editor.putBoolean("noSoundHintShowed", noSoundHintShowed);
|
|
|
|
editor.commit();
|
|
|
|
}
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
public static void toogleRaiseToSpeak() {
|
|
|
|
raiseToSpeak = !raiseToSpeak;
|
|
|
|
SharedPreferences preferences = MessagesController.getGlobalMainSettings();
|
|
|
|
SharedPreferences.Editor editor = preferences.edit();
|
|
|
|
editor.putBoolean("raise_to_speak", raiseToSpeak);
|
|
|
|
editor.commit();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void toggleCustomTabs() {
|
|
|
|
customTabs = !customTabs;
|
|
|
|
SharedPreferences preferences = MessagesController.getGlobalMainSettings();
|
|
|
|
SharedPreferences.Editor editor = preferences.edit();
|
|
|
|
editor.putBoolean("custom_tabs", customTabs);
|
|
|
|
editor.commit();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void toggleDirectShare() {
|
|
|
|
directShare = !directShare;
|
|
|
|
SharedPreferences preferences = MessagesController.getGlobalMainSettings();
|
|
|
|
SharedPreferences.Editor editor = preferences.edit();
|
|
|
|
editor.putBoolean("direct_share", directShare);
|
|
|
|
editor.commit();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void toggleStreamMedia() {
|
|
|
|
streamMedia = !streamMedia;
|
|
|
|
SharedPreferences preferences = MessagesController.getGlobalMainSettings();
|
|
|
|
SharedPreferences.Editor editor = preferences.edit();
|
|
|
|
editor.putBoolean("streamMedia", streamMedia);
|
|
|
|
editor.commit();
|
2019-01-23 18:03:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void toggleSortContactsByName() {
|
|
|
|
sortContactsByName = !sortContactsByName;
|
|
|
|
SharedPreferences preferences = MessagesController.getGlobalMainSettings();
|
|
|
|
SharedPreferences.Editor editor = preferences.edit();
|
|
|
|
editor.putBoolean("sortContactsByName", sortContactsByName);
|
|
|
|
editor.commit();
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void toggleStreamAllVideo() {
|
|
|
|
streamAllVideo = !streamAllVideo;
|
|
|
|
SharedPreferences preferences = MessagesController.getGlobalMainSettings();
|
|
|
|
SharedPreferences.Editor editor = preferences.edit();
|
|
|
|
editor.putBoolean("streamAllVideo", streamAllVideo);
|
|
|
|
editor.commit();
|
|
|
|
}
|
|
|
|
|
2019-03-03 21:40:48 +01:00
|
|
|
public static void toggleStreamMkv() {
|
|
|
|
streamMkv = !streamMkv;
|
|
|
|
SharedPreferences preferences = MessagesController.getGlobalMainSettings();
|
|
|
|
SharedPreferences.Editor editor = preferences.edit();
|
|
|
|
editor.putBoolean("streamMkv", streamMkv);
|
|
|
|
editor.commit();
|
|
|
|
}
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
public static void toggleSaveStreamMedia() {
|
|
|
|
saveStreamMedia = !saveStreamMedia;
|
|
|
|
SharedPreferences preferences = MessagesController.getGlobalMainSettings();
|
|
|
|
SharedPreferences.Editor editor = preferences.edit();
|
|
|
|
editor.putBoolean("saveStreamMedia", saveStreamMedia);
|
|
|
|
editor.commit();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void toggleInappCamera() {
|
|
|
|
inappCamera = !inappCamera;
|
|
|
|
SharedPreferences preferences = MessagesController.getGlobalMainSettings();
|
|
|
|
SharedPreferences.Editor editor = preferences.edit();
|
|
|
|
editor.putBoolean("inappCamera", inappCamera);
|
|
|
|
editor.commit();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void toggleRoundCamera16to9() {
|
|
|
|
roundCamera16to9 = !roundCamera16to9;
|
|
|
|
SharedPreferences preferences = MessagesController.getGlobalMainSettings();
|
|
|
|
SharedPreferences.Editor editor = preferences.edit();
|
|
|
|
editor.putBoolean("roundCamera16to9", roundCamera16to9);
|
|
|
|
editor.commit();
|
|
|
|
}
|
|
|
|
|
2019-07-18 15:01:39 +02:00
|
|
|
public static void setDistanceSystemType(int type) {
|
|
|
|
distanceSystemType = type;
|
|
|
|
SharedPreferences preferences = MessagesController.getGlobalMainSettings();
|
|
|
|
SharedPreferences.Editor editor = preferences.edit();
|
|
|
|
editor.putInt("distanceSystemType", distanceSystemType);
|
|
|
|
editor.commit();
|
|
|
|
LocaleController.resetImperialSystemType();
|
|
|
|
}
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
public static void loadProxyList() {
|
|
|
|
if (proxyListLoaded) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
|
|
|
|
String proxyAddress = preferences.getString("proxy_ip", "");
|
|
|
|
String proxyUsername = preferences.getString("proxy_user", "");
|
|
|
|
String proxyPassword = preferences.getString("proxy_pass", "");
|
|
|
|
String proxySecret = preferences.getString("proxy_secret", "");
|
|
|
|
int proxyPort = preferences.getInt("proxy_port", 1080);
|
|
|
|
|
|
|
|
proxyListLoaded = true;
|
|
|
|
proxyList.clear();
|
|
|
|
currentProxy = null;
|
|
|
|
String list = preferences.getString("proxy_list", null);
|
|
|
|
if (!TextUtils.isEmpty(list)) {
|
|
|
|
byte[] bytes = Base64.decode(list, Base64.DEFAULT);
|
|
|
|
SerializedData data = new SerializedData(bytes);
|
|
|
|
int count = data.readInt32(false);
|
|
|
|
for (int a = 0; a < count; a++) {
|
|
|
|
ProxyInfo info = new ProxyInfo(
|
|
|
|
data.readString(false),
|
|
|
|
data.readInt32(false),
|
|
|
|
data.readString(false),
|
|
|
|
data.readString(false),
|
|
|
|
data.readString(false));
|
|
|
|
proxyList.add(info);
|
|
|
|
if (currentProxy == null && !TextUtils.isEmpty(proxyAddress)) {
|
|
|
|
if (proxyAddress.equals(info.address) && proxyPort == info.port && proxyUsername.equals(info.username) && proxyPassword.equals(info.password)) {
|
|
|
|
currentProxy = info;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
data.cleanup();
|
|
|
|
}
|
|
|
|
if (currentProxy == null && !TextUtils.isEmpty(proxyAddress)) {
|
|
|
|
ProxyInfo info = currentProxy = new ProxyInfo(proxyAddress, proxyPort, proxyUsername, proxyPassword, proxySecret);
|
|
|
|
proxyList.add(0, info);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void saveProxyList() {
|
|
|
|
SerializedData serializedData = new SerializedData();
|
|
|
|
int count = proxyList.size();
|
|
|
|
serializedData.writeInt32(count);
|
|
|
|
for (int a = 0; a < count; a++) {
|
|
|
|
ProxyInfo info = proxyList.get(a);
|
|
|
|
serializedData.writeString(info.address != null ? info.address : "");
|
|
|
|
serializedData.writeInt32(info.port);
|
|
|
|
serializedData.writeString(info.username != null ? info.username : "");
|
|
|
|
serializedData.writeString(info.password != null ? info.password : "");
|
|
|
|
serializedData.writeString(info.secret != null ? info.secret : "");
|
|
|
|
}
|
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
|
|
|
|
preferences.edit().putString("proxy_list", Base64.encodeToString(serializedData.toByteArray(), Base64.NO_WRAP)).commit();
|
|
|
|
serializedData.cleanup();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static ProxyInfo addProxy(ProxyInfo proxyInfo) {
|
|
|
|
loadProxyList();
|
|
|
|
int count = proxyList.size();
|
|
|
|
for (int a = 0; a < count; a++) {
|
|
|
|
ProxyInfo info = proxyList.get(a);
|
|
|
|
if (proxyInfo.address.equals(info.address) && proxyInfo.port == info.port && proxyInfo.username.equals(info.username) && proxyInfo.password.equals(info.password) && proxyInfo.secret.equals(info.secret)) {
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
proxyList.add(proxyInfo);
|
|
|
|
saveProxyList();
|
|
|
|
return proxyInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void deleteProxy(ProxyInfo proxyInfo) {
|
|
|
|
if (currentProxy == proxyInfo) {
|
|
|
|
currentProxy = null;
|
|
|
|
SharedPreferences preferences = MessagesController.getGlobalMainSettings();
|
|
|
|
boolean enabled = preferences.getBoolean("proxy_enabled", false);
|
|
|
|
SharedPreferences.Editor editor = preferences.edit();
|
|
|
|
editor.putString("proxy_ip", "");
|
|
|
|
editor.putString("proxy_pass", "");
|
|
|
|
editor.putString("proxy_user", "");
|
|
|
|
editor.putString("proxy_secret", "");
|
|
|
|
editor.putInt("proxy_port", 1080);
|
|
|
|
editor.putBoolean("proxy_enabled", false);
|
|
|
|
editor.putBoolean("proxy_enabled_calls", false);
|
|
|
|
editor.commit();
|
|
|
|
if (enabled) {
|
|
|
|
ConnectionsManager.setProxySettings(false, "", 0, "", "", "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
proxyList.remove(proxyInfo);
|
|
|
|
saveProxyList();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void checkSaveToGalleryFiles() {
|
|
|
|
try {
|
|
|
|
File telegramPath = new File(Environment.getExternalStorageDirectory(), "Telegram");
|
|
|
|
File imagePath = new File(telegramPath, "Telegram Images");
|
|
|
|
imagePath.mkdir();
|
|
|
|
File videoPath = new File(telegramPath, "Telegram Video");
|
|
|
|
videoPath.mkdir();
|
|
|
|
|
|
|
|
if (saveToGallery) {
|
|
|
|
if (imagePath.isDirectory()) {
|
|
|
|
new File(imagePath, ".nomedia").delete();
|
|
|
|
}
|
|
|
|
if (videoPath.isDirectory()) {
|
|
|
|
new File(videoPath, ".nomedia").delete();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (imagePath.isDirectory()) {
|
|
|
|
new File(imagePath, ".nomedia").createNewFile();
|
|
|
|
}
|
|
|
|
if (videoPath.isDirectory()) {
|
|
|
|
new File(videoPath, ".nomedia").createNewFile();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e(e);
|
|
|
|
}
|
|
|
|
}
|
2019-07-18 15:01:39 +02:00
|
|
|
|
|
|
|
public final static int PERFORMANCE_CLASS_LOW = 0;
|
|
|
|
public final static int PERFORMANCE_CLASS_AVERAGE = 1;
|
|
|
|
public final static int PERFORMANCE_CLASS_HIGH = 2;
|
|
|
|
|
|
|
|
public static int getDevicePerfomanceClass() {
|
|
|
|
if (devicePerformanceClass == -1) {
|
|
|
|
int maxCpuFreq = -1;
|
|
|
|
try {
|
|
|
|
RandomAccessFile reader = new RandomAccessFile("/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq", "r");
|
|
|
|
String line = reader.readLine();
|
|
|
|
if (line != null) {
|
|
|
|
maxCpuFreq = Utilities.parseInt(line) / 1000;
|
|
|
|
}
|
|
|
|
reader.close();
|
|
|
|
} catch (Throwable ignore) {
|
|
|
|
|
|
|
|
}
|
|
|
|
int androidVersion = Build.VERSION.SDK_INT;
|
|
|
|
int cpuCount = ConnectionsManager.CPU_COUNT;
|
|
|
|
int memoryClass = ((ActivityManager) ApplicationLoader.applicationContext.getSystemService(Context.ACTIVITY_SERVICE)).getMemoryClass();
|
|
|
|
if (androidVersion < 21 || cpuCount <= 2 || memoryClass <= 100 || cpuCount <= 4 && maxCpuFreq != -1 && maxCpuFreq <= 1250 || cpuCount <= 4 && maxCpuFreq <= 1600 && memoryClass <= 128 && androidVersion <= 21) {
|
|
|
|
devicePerformanceClass = PERFORMANCE_CLASS_LOW;
|
|
|
|
} else if (cpuCount < 8 || memoryClass <= 160 || maxCpuFreq != -1 && maxCpuFreq <= 1650) {
|
|
|
|
devicePerformanceClass = PERFORMANCE_CLASS_AVERAGE;
|
|
|
|
} else {
|
|
|
|
devicePerformanceClass = PERFORMANCE_CLASS_HIGH;
|
|
|
|
}
|
|
|
|
if (BuildVars.DEBUG_VERSION) {
|
|
|
|
FileLog.d("device performance info (cpu_count = " + cpuCount + ", freq = " + maxCpuFreq + ", memoryClass = " + memoryClass + ", android version " + androidVersion + ")");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return devicePerformanceClass;
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|