Update to 4.9.0

This commit is contained in:
DrKLO 2018-07-30 09:07:02 +07:00
parent e9e40cb13e
commit d073b80063
1874 changed files with 306119 additions and 135049 deletions

View file

@ -10,66 +10,96 @@ package org.telegram.messenger;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.os.SystemClock;
import android.util.Base64;
import org.telegram.tgnet.SerializedData;
import org.telegram.tgnet.TLRPC;
import java.io.File;
import java.util.ArrayList;
import java.util.Map;
public class UserConfig {
private static TLRPC.User currentUser;
public static boolean registeredForPush;
public static String pushString = "";
public static int lastSendMessageId = -210000;
public static int lastLocalId = -210000;
public static int lastBroadcastId = -1;
public static int contactsSavedCount;
public static boolean blockedUsersLoaded;
private final static Object sync = new Object();
public static boolean saveIncomingPhotos;
public static String passcodeHash = "";
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 lastContactsSyncTime;
public static int lastHintsSyncTime;
public static boolean draftsLoaded;
public static boolean notificationsConverted = true;
public static boolean pinnedDialogsLoaded = true;
public static TLRPC.TL_account_tmpPassword tmpPassword;
public static int ratingLoadTime;
public static int botRatingLoadTime;
public static boolean contactsReimported;
public static int selectedAccount;
public final static int MAX_ACCOUNT_COUNT = 3;
private static boolean configLoaded;
private final Object sync = new Object();
private boolean configLoaded;
private TLRPC.User currentUser;
public boolean registeredForPush;
public int lastSendMessageId = -210000;
public int lastBroadcastId = -1;
public int contactsSavedCount;
public int clientUserId;
public boolean blockedUsersLoaded;
public int lastContactsSyncTime;
public int lastHintsSyncTime;
public boolean draftsLoaded;
public boolean pinnedDialogsLoaded = true;
public boolean unreadDialogsLoaded = true;
public TLRPC.TL_account_tmpPassword tmpPassword;
public int ratingLoadTime;
public int botRatingLoadTime;
public boolean contactsReimported;
public int migrateOffsetId = -1;
public int migrateOffsetDate = -1;
public int migrateOffsetUserId = -1;
public int migrateOffsetChatId = -1;
public int migrateOffsetChannelId = -1;
public long migrateOffsetAccess = -1;
public int totalDialogsLoadCount = 0;
public int dialogsLoadOffsetId = 0;
public int dialogsLoadOffsetDate = 0;
public int dialogsLoadOffsetUserId = 0;
public int dialogsLoadOffsetChatId = 0;
public int dialogsLoadOffsetChannelId = 0;
public long dialogsLoadOffsetAccess = 0;
public boolean notificationsSettingsLoaded;
public boolean syncContacts = true;
public boolean suggestContacts = true;
public boolean hasSecureData;
public int loginTime;
public TLRPC.TL_help_termsOfService unacceptedTermsOfService;
public TLRPC.TL_help_appUpdate pendingAppUpdate;
public int pendingAppUpdateBuildVersion;
public long pendingAppUpdateInstallTime;
public long lastUpdateCheckTime;
public static int migrateOffsetId = -1;
public static int migrateOffsetDate = -1;
public static int migrateOffsetUserId = -1;
public static int migrateOffsetChatId = -1;
public static int migrateOffsetChannelId = -1;
public static long migrateOffsetAccess = -1;
public volatile byte[] savedPasswordHash;
public volatile byte[] savedSaltedPassword;
public volatile long savedPasswordTime;
public static int totalDialogsLoadCount = 0;
public static int dialogsLoadOffsetId = 0;
public static int dialogsLoadOffsetDate = 0;
public static int dialogsLoadOffsetUserId = 0;
public static int dialogsLoadOffsetChatId = 0;
public static int dialogsLoadOffsetChannelId = 0;
public static long dialogsLoadOffsetAccess = 0;
private int currentAccount;
private static volatile UserConfig[] Instance = new UserConfig[UserConfig.MAX_ACCOUNT_COUNT];
public static UserConfig getInstance(int num) {
UserConfig localInstance = Instance[num];
if (localInstance == null) {
synchronized (UserConfig.class) {
localInstance = Instance[num];
if (localInstance == null) {
Instance[num] = localInstance = new UserConfig(num);
}
}
}
return localInstance;
}
public static int getNewMessageId() {
public static int getActivatedAccountsCount() {
int count = 0;
for (int a = 0; a < MAX_ACCOUNT_COUNT; a++) {
if (getInstance(a).isClientActivated()) {
count++;
}
}
return count;
}
public UserConfig(int instance) {
currentAccount = instance;
}
public int getNewMessageId() {
int id;
synchronized (sync) {
id = lastSendMessageId;
@ -78,41 +108,41 @@ public class UserConfig {
return id;
}
public static void saveConfig(boolean withFile) {
public void saveConfig(boolean withFile) {
saveConfig(withFile, null);
}
public static void saveConfig(boolean withFile, File oldFile) {
public void saveConfig(boolean withFile, File oldFile) {
synchronized (sync) {
try {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("userconfing", Context.MODE_PRIVATE);
SharedPreferences preferences;
if (currentAccount == 0) {
preferences = ApplicationLoader.applicationContext.getSharedPreferences("userconfing", Context.MODE_PRIVATE);
} else {
preferences = ApplicationLoader.applicationContext.getSharedPreferences("userconfig" + currentAccount, Context.MODE_PRIVATE);
}
SharedPreferences.Editor editor = preferences.edit();
if (currentAccount == 0) {
editor.putInt("selectedAccount", selectedAccount);
}
editor.putBoolean("registeredForPush", registeredForPush);
editor.putString("pushString2", pushString);
editor.putInt("lastSendMessageId", lastSendMessageId);
editor.putInt("lastLocalId", lastLocalId);
editor.putInt("contactsSavedCount", contactsSavedCount);
editor.putBoolean("saveIncomingPhotos", saveIncomingPhotos);
editor.putInt("lastBroadcastId", lastBroadcastId);
editor.putBoolean("blockedUsersLoaded", blockedUsersLoaded);
editor.putString("passcodeHash1", passcodeHash);
editor.putString("passcodeSalt", passcodeSalt.length > 0 ? Base64.encodeToString(passcodeSalt, Base64.DEFAULT) : "");
editor.putBoolean("appLocked", appLocked);
editor.putInt("passcodeType", passcodeType);
editor.putInt("autoLockIn", autoLockIn);
editor.putInt("lastPauseTime", lastPauseTime);
editor.putLong("lastAppPauseTime", lastAppPauseTime);
editor.putString("lastUpdateVersion2", lastUpdateVersion);
editor.putInt("lastContactsSyncTime", lastContactsSyncTime);
editor.putBoolean("useFingerprint", useFingerprint);
editor.putInt("lastHintsSyncTime", lastHintsSyncTime);
editor.putBoolean("draftsLoaded", draftsLoaded);
editor.putBoolean("notificationsConverted", notificationsConverted);
editor.putBoolean("allowScreenCapture", allowScreenCapture);
editor.putBoolean("pinnedDialogsLoaded", pinnedDialogsLoaded);
editor.putBoolean("unreadDialogsLoaded", unreadDialogsLoaded);
editor.putInt("ratingLoadTime", ratingLoadTime);
editor.putInt("botRatingLoadTime", botRatingLoadTime);
editor.putBoolean("contactsReimported", contactsReimported);
editor.putInt("loginTime", loginTime);
editor.putBoolean("syncContacts", syncContacts);
editor.putBoolean("suggestContacts", suggestContacts);
editor.putBoolean("hasSecureData", hasSecureData);
editor.putBoolean("notificationsSettingsLoaded", notificationsSettingsLoaded);
editor.putInt("3migrateOffsetId", migrateOffsetId);
if (migrateOffsetId != -1) {
@ -123,6 +153,38 @@ public class UserConfig {
editor.putLong("3migrateOffsetAccess", migrateOffsetAccess);
}
if (unacceptedTermsOfService != null) {
try {
SerializedData data = new SerializedData(unacceptedTermsOfService.getObjectSize());
unacceptedTermsOfService.serializeToStream(data);
String str = Base64.encodeToString(data.toByteArray(), Base64.DEFAULT);
editor.putString("terms", str);
data.cleanup();
} catch (Exception ignore) {
}
} else {
editor.remove("terms");
}
if (currentAccount == 0) {
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);
editor.putLong("appUpdateTime", pendingAppUpdateInstallTime);
editor.putLong("appUpdateCheckTime", lastUpdateCheckTime);
data.cleanup();
} catch (Exception ignore) {
}
} else {
editor.remove("appUpdate");
}
}
editor.putInt("2totalDialogsLoadCount", totalDialogsLoadCount);
editor.putInt("2dialogsLoadOffsetId", dialogsLoadOffsetId);
@ -132,6 +194,8 @@ public class UserConfig {
editor.putInt("2dialogsLoadOffsetChannelId", dialogsLoadOffsetChannelId);
editor.putLong("2dialogsLoadOffsetAccess", dialogsLoadOffsetAccess);
SharedConfig.saveConfig();
if (tmpPassword != null) {
SerializedData data = new SerializedData();
tmpPassword.serializeToStream(data);
@ -164,293 +228,200 @@ public class UserConfig {
}
}
public static boolean isClientActivated() {
public boolean isClientActivated() {
synchronized (sync) {
return currentUser != null;
}
}
public static int getClientUserId() {
public int getClientUserId() {
synchronized (sync) {
return currentUser != null ? currentUser.id : 0;
}
}
public static TLRPC.User getCurrentUser() {
public String getClientPhone() {
synchronized (sync) {
return currentUser != null && currentUser.phone != null ? currentUser.phone : "";
}
}
public TLRPC.User getCurrentUser() {
synchronized (sync) {
return currentUser;
}
}
public static void setCurrentUser(TLRPC.User user) {
public void setCurrentUser(TLRPC.User user) {
synchronized (sync) {
currentUser = user;
clientUserId = user.id;
}
}
public static void loadConfig() {
public void loadConfig() {
synchronized (sync) {
if (configLoaded) {
return;
}
final File configFile = new File(ApplicationLoader.getFilesDirFixed(), "user.dat");
if (configFile.exists()) {
try {
SerializedData data = new SerializedData(configFile);
int ver = data.readInt32(false);
if (ver == 1) {
int constructor = data.readInt32(false);
currentUser = TLRPC.User.TLdeserialize(data, constructor, false);
MessagesStorage.lastDateValue = data.readInt32(false);
MessagesStorage.lastPtsValue = data.readInt32(false);
MessagesStorage.lastSeqValue = data.readInt32(false);
registeredForPush = data.readBool(false);
pushString = data.readString(false);
lastSendMessageId = data.readInt32(false);
lastLocalId = data.readInt32(false);
data.readString(false);
data.readString(false);
saveIncomingPhotos = data.readBool(false);
MessagesStorage.lastQtsValue = data.readInt32(false);
MessagesStorage.lastSecretVersion = data.readInt32(false);
int val = data.readInt32(false);
if (val == 1) {
MessagesStorage.secretPBytes = data.readByteArray(false);
}
MessagesStorage.secretG = data.readInt32(false);
Utilities.stageQueue.postRunnable(new Runnable() {
@Override
public void run() {
saveConfig(true, configFile);
}
});
} else if (ver == 2) {
int constructor = data.readInt32(false);
currentUser = TLRPC.User.TLdeserialize(data, constructor, false);
SharedPreferences preferences;
if (currentAccount == 0) {
preferences = ApplicationLoader.applicationContext.getSharedPreferences("userconfing", Context.MODE_PRIVATE);
selectedAccount = preferences.getInt("selectedAccount", 0);
} else {
preferences = ApplicationLoader.applicationContext.getSharedPreferences("userconfig" + currentAccount, Context.MODE_PRIVATE);
}
registeredForPush = preferences.getBoolean("registeredForPush", false);
lastSendMessageId = preferences.getInt("lastSendMessageId", -210000);
contactsSavedCount = preferences.getInt("contactsSavedCount", 0);
lastBroadcastId = preferences.getInt("lastBroadcastId", -1);
blockedUsersLoaded = preferences.getBoolean("blockedUsersLoaded", false);
lastContactsSyncTime = preferences.getInt("lastContactsSyncTime", (int) (System.currentTimeMillis() / 1000) - 23 * 60 * 60);
lastHintsSyncTime = preferences.getInt("lastHintsSyncTime", (int) (System.currentTimeMillis() / 1000) - 25 * 60 * 60);
draftsLoaded = preferences.getBoolean("draftsLoaded", false);
pinnedDialogsLoaded = preferences.getBoolean("pinnedDialogsLoaded", false);
unreadDialogsLoaded = preferences.getBoolean("unreadDialogsLoaded", false);
contactsReimported = preferences.getBoolean("contactsReimported", false);
ratingLoadTime = preferences.getInt("ratingLoadTime", 0);
botRatingLoadTime = preferences.getInt("botRatingLoadTime", 0);
loginTime = preferences.getInt("loginTime", currentAccount);
syncContacts = preferences.getBoolean("syncContacts", true);
suggestContacts = preferences.getBoolean("suggestContacts", true);
hasSecureData = preferences.getBoolean("hasSecureData", false);
notificationsSettingsLoaded = preferences.getBoolean("notificationsSettingsLoaded", false);
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("userconfing", Context.MODE_PRIVATE);
registeredForPush = preferences.getBoolean("registeredForPush", false);
pushString = preferences.getString("pushString2", "");
lastSendMessageId = preferences.getInt("lastSendMessageId", -210000);
lastLocalId = preferences.getInt("lastLocalId", -210000);
contactsSavedCount = preferences.getInt("contactsHash", 0);
saveIncomingPhotos = preferences.getBoolean("saveIncomingPhotos", false);
try {
String terms = preferences.getString("terms", null);
if (terms != null) {
byte[] arr = Base64.decode(terms, Base64.DEFAULT);
if (arr != null) {
SerializedData data = new SerializedData(arr);
unacceptedTermsOfService = TLRPC.TL_help_termsOfService.TLdeserialize(data, data.readInt32(false), false);
data.cleanup();
}
if (lastLocalId > -210000) {
lastLocalId = -210000;
}
if (lastSendMessageId > -210000) {
lastSendMessageId = -210000;
}
data.cleanup();
Utilities.stageQueue.postRunnable(new Runnable() {
@Override
public void run() {
saveConfig(true, configFile);
}
} catch (Exception e) {
FileLog.e(e);
}
if (currentAccount == 0) {
lastUpdateCheckTime = preferences.getLong("appUpdateCheckTime", System.currentTimeMillis());
try {
String update = preferences.getString("appUpdate", null);
if (update != null) {
pendingAppUpdateBuildVersion = preferences.getInt("appUpdateBuild", BuildVars.BUILD_VERSION);
pendingAppUpdateInstallTime = preferences.getLong("appUpdateTime", System.currentTimeMillis());
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;
try {
PackageInfo packageInfo = ApplicationLoader.applicationContext.getPackageManager().getPackageInfo(ApplicationLoader.applicationContext.getPackageName(), 0);
updateTime = Math.max(packageInfo.lastUpdateTime, packageInfo.firstInstallTime);
} catch (Exception e) {
FileLog.e(e);
}
if (pendingAppUpdateBuildVersion != BuildVars.BUILD_VERSION || pendingAppUpdateInstallTime < updateTime) {
pendingAppUpdate = null;
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
saveConfig(false);
}
});
}
}
} catch (Exception e) {
FileLog.e(e);
}
} else {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("userconfing", Context.MODE_PRIVATE);
registeredForPush = preferences.getBoolean("registeredForPush", false);
pushString = preferences.getString("pushString2", "");
lastSendMessageId = preferences.getInt("lastSendMessageId", -210000);
lastLocalId = preferences.getInt("lastLocalId", -210000);
contactsSavedCount = preferences.getInt("contactsSavedCount", 0);
saveIncomingPhotos = preferences.getBoolean("saveIncomingPhotos", false);
lastBroadcastId = preferences.getInt("lastBroadcastId", -1);
blockedUsersLoaded = preferences.getBoolean("blockedUsersLoaded", false);
passcodeHash = preferences.getString("passcodeHash1", "");
appLocked = preferences.getBoolean("appLocked", false);
passcodeType = preferences.getInt("passcodeType", 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");
lastContactsSyncTime = preferences.getInt("lastContactsSyncTime", (int) (System.currentTimeMillis() / 1000) - 23 * 60 * 60);
lastHintsSyncTime = preferences.getInt("lastHintsSyncTime", (int) (System.currentTimeMillis() / 1000) - 25 * 60 * 60);
draftsLoaded = preferences.getBoolean("draftsLoaded", false);
notificationsConverted = preferences.getBoolean("notificationsConverted", false);
allowScreenCapture = preferences.getBoolean("allowScreenCapture", false);
pinnedDialogsLoaded = preferences.getBoolean("pinnedDialogsLoaded", false);
contactsReimported = preferences.getBoolean("contactsReimported", false);
ratingLoadTime = preferences.getInt("ratingLoadTime", 0);
botRatingLoadTime = preferences.getInt("botRatingLoadTime", 0);
}
if (UserConfig.passcodeHash.length() > 0 && lastPauseTime == 0) {
lastPauseTime = (int) (System.currentTimeMillis() / 1000 - 60 * 10);
}
migrateOffsetId = preferences.getInt("3migrateOffsetId", 0);
if (migrateOffsetId != -1) {
migrateOffsetDate = preferences.getInt("3migrateOffsetDate", 0);
migrateOffsetUserId = preferences.getInt("3migrateOffsetUserId", 0);
migrateOffsetChatId = preferences.getInt("3migrateOffsetChatId", 0);
migrateOffsetChannelId = preferences.getInt("3migrateOffsetChannelId", 0);
migrateOffsetAccess = preferences.getLong("3migrateOffsetAccess", 0);
}
migrateOffsetId = preferences.getInt("3migrateOffsetId", 0);
if (migrateOffsetId != -1) {
migrateOffsetDate = preferences.getInt("3migrateOffsetDate", 0);
migrateOffsetUserId = preferences.getInt("3migrateOffsetUserId", 0);
migrateOffsetChatId = preferences.getInt("3migrateOffsetChatId", 0);
migrateOffsetChannelId = preferences.getInt("3migrateOffsetChannelId", 0);
migrateOffsetAccess = preferences.getLong("3migrateOffsetAccess", 0);
}
dialogsLoadOffsetId = preferences.getInt("2dialogsLoadOffsetId", -1);
totalDialogsLoadCount = preferences.getInt("2totalDialogsLoadCount", 0);
dialogsLoadOffsetDate = preferences.getInt("2dialogsLoadOffsetDate", -1);
dialogsLoadOffsetUserId = preferences.getInt("2dialogsLoadOffsetUserId", -1);
dialogsLoadOffsetChatId = preferences.getInt("2dialogsLoadOffsetChatId", -1);
dialogsLoadOffsetChannelId = preferences.getInt("2dialogsLoadOffsetChannelId", -1);
dialogsLoadOffsetAccess = preferences.getLong("2dialogsLoadOffsetAccess", -1);
dialogsLoadOffsetId = preferences.getInt("2dialogsLoadOffsetId", -1);
totalDialogsLoadCount = preferences.getInt("2totalDialogsLoadCount", 0);
dialogsLoadOffsetDate = preferences.getInt("2dialogsLoadOffsetDate", -1);
dialogsLoadOffsetUserId = preferences.getInt("2dialogsLoadOffsetUserId", -1);
dialogsLoadOffsetChatId = preferences.getInt("2dialogsLoadOffsetChatId", -1);
dialogsLoadOffsetChannelId = preferences.getInt("2dialogsLoadOffsetChannelId", -1);
dialogsLoadOffsetAccess = preferences.getLong("2dialogsLoadOffsetAccess", -1);
String string = preferences.getString("tmpPassword", null);
if (string != null) {
byte[] bytes = Base64.decode(string, Base64.DEFAULT);
if (bytes != null) {
SerializedData data = new SerializedData(bytes);
tmpPassword = TLRPC.TL_account_tmpPassword.TLdeserialize(data, data.readInt32(false), false);
data.cleanup();
}
}
String string = preferences.getString("tmpPassword", null);
if (string != null) {
byte[] bytes = Base64.decode(string, Base64.DEFAULT);
if (bytes != null) {
SerializedData data = new SerializedData(bytes);
tmpPassword = TLRPC.TL_account_tmpPassword.TLdeserialize(data, data.readInt32(false), false);
data.cleanup();
}
}
string = preferences.getString("user", null);
if (string != null) {
byte[] bytes = Base64.decode(string, Base64.DEFAULT);
if (bytes != null) {
SerializedData data = new SerializedData(bytes);
currentUser = TLRPC.User.TLdeserialize(data, data.readInt32(false), false);
data.cleanup();
}
}
String passcodeSaltString = preferences.getString("passcodeSalt", "");
if (passcodeSaltString.length() > 0) {
passcodeSalt = Base64.decode(passcodeSaltString, Base64.DEFAULT);
} else {
passcodeSalt = new byte[0];
}
if (!notificationsConverted) {
try {
ArrayList<Long> customDialogs = new ArrayList<>();
preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Context.MODE_PRIVATE);
Map<String, ?> all = preferences.getAll();
String defaultSound = LocaleController.getString("SoundDefault", R.string.SoundDefault);
int defaultVibrate = 0;
int defaultPriority = 0;
int defaultColor = 0;
int defaultMaxCount = 2;
int defaultMaxDelay = 3 * 60;
for (Map.Entry<String, ?> entry : all.entrySet()) {
String key = entry.getKey();
if (key.startsWith("sound_")) {
String value = (String) entry.getValue();
if (!value.equals(defaultSound)) {
long dialogId = Utilities.parseLong(key);
if (!customDialogs.contains(dialogId)) {
customDialogs.add(dialogId);
}
}
} else if (key.startsWith("vibrate_")) {
Integer value = (Integer) entry.getValue();
if (value != defaultVibrate) {
long dialogId = Utilities.parseLong(key);
if (!customDialogs.contains(dialogId)) {
customDialogs.add(dialogId);
}
}
} else if (key.startsWith("priority_")) {
Integer value = (Integer) entry.getValue();
if (value != defaultPriority) {
long dialogId = Utilities.parseLong(key);
if (!customDialogs.contains(dialogId)) {
customDialogs.add(dialogId);
}
}
} else if (key.startsWith("color_")) {
Integer value = (Integer) entry.getValue();
if (value != defaultColor) {
long dialogId = Utilities.parseLong(key);
if (!customDialogs.contains(dialogId)) {
customDialogs.add(dialogId);
}
}
} else if (key.startsWith("smart_max_count_")) {
Integer value = (Integer) entry.getValue();
if (value != defaultMaxCount) {
long dialogId = Utilities.parseLong(key);
if (!customDialogs.contains(dialogId)) {
customDialogs.add(dialogId);
}
}
} else if (key.startsWith("smart_delay_")) {
Integer value = (Integer) entry.getValue();
if (value != defaultMaxDelay) {
long dialogId = Utilities.parseLong(key);
if (!customDialogs.contains(dialogId)) {
customDialogs.add(dialogId);
}
}
}
}
if (!customDialogs.isEmpty()) {
SharedPreferences.Editor editor = preferences.edit();
for (int a = 0; a < customDialogs.size(); a++) {
editor.putBoolean("custom_" + customDialogs.get(a), true);
}
editor.commit();
}
} catch (Exception e) {
FileLog.e(e);
}
notificationsConverted = true;
saveConfig(false);
string = preferences.getString("user", null);
if (string != null) {
byte[] bytes = Base64.decode(string, Base64.DEFAULT);
if (bytes != null) {
SerializedData data = new SerializedData(bytes);
currentUser = TLRPC.User.TLdeserialize(data, data.readInt32(false), false);
data.cleanup();
}
}
if (currentUser != null) {
clientUserId = currentUser.id;
}
configLoaded = 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(false);
} 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 void savePassword(byte[] hash, byte[] salted) {
savedPasswordTime = SystemClock.elapsedRealtime();
savedPasswordHash = hash;
savedSaltedPassword = salted;
}
public static void clearConfig() {
public void checkSavedPassword() {
if (savedSaltedPassword == null && savedPasswordHash == null || Math.abs(SystemClock.elapsedRealtime() - savedPasswordTime) < 30 * 60 * 1000) {
return;
}
resetSavedPassword();
}
public void resetSavedPassword() {
savedPasswordTime = 0;
if (savedPasswordHash != null) {
for (int a = 0; a < savedPasswordHash.length; a++) {
savedPasswordHash[a] = 0;
}
savedPasswordHash = null;
}
if (savedSaltedPassword != null) {
for (int a = 0; a < savedSaltedPassword.length; a++) {
savedSaltedPassword[a] = 0;
}
savedSaltedPassword = null;
}
}
public void clearConfig() {
currentUser = null;
clientUserId = 0;
registeredForPush = false;
contactsSavedCount = 0;
lastSendMessageId = -210000;
lastBroadcastId = -1;
saveIncomingPhotos = false;
blockedUsersLoaded = false;
notificationsSettingsLoaded = false;
migrateOffsetId = -1;
migrateOffsetDate = -1;
migrateOffsetUserId = -1;
@ -466,22 +437,29 @@ public class UserConfig {
dialogsLoadOffsetAccess = 0;
ratingLoadTime = 0;
botRatingLoadTime = 0;
appLocked = false;
passcodeType = 0;
passcodeHash = "";
passcodeSalt = new byte[0];
autoLockIn = 60 * 60;
lastPauseTime = 0;
useFingerprint = true;
draftsLoaded = true;
notificationsConverted = true;
contactsReimported = true;
isWaitingForPasscodeEnter = false;
allowScreenCapture = false;
syncContacts = true;
suggestContacts = true;
pinnedDialogsLoaded = false;
lastUpdateVersion = BuildVars.BUILD_VERSION_STRING;
unreadDialogsLoaded = true;
unacceptedTermsOfService = null;
pendingAppUpdate = null;
hasSecureData = false;
loginTime = (int) (System.currentTimeMillis() / 1000);
lastContactsSyncTime = (int) (System.currentTimeMillis() / 1000) - 23 * 60 * 60;
lastHintsSyncTime = (int) (System.currentTimeMillis() / 1000) - 25 * 60 * 60;
resetSavedPassword();
boolean hasActivated = false;
for (int a = 0; a < MAX_ACCOUNT_COUNT; a++) {
if (UserConfig.getInstance(a).isClientActivated()) {
hasActivated = true;
break;
}
}
if (!hasActivated) {
SharedConfig.clearConfig();
}
saveConfig(true);
}
}