2013-10-25 17:19:00 +02:00
|
|
|
/*
|
2015-10-29 18:10:07 +01:00
|
|
|
* This is the source code of Telegram for Android v. 3.x.x.
|
2013-10-25 17:19:00 +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).
|
|
|
|
*
|
2017-03-31 01:58:05 +02:00
|
|
|
* Copyright Nikolai Kudashov, 2013-2017.
|
2013-10-25 17:19:00 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
package org.telegram.messenger;
|
|
|
|
|
2013-11-04 13:31:01 +01:00
|
|
|
import android.content.Context;
|
|
|
|
import android.content.SharedPreferences;
|
2013-12-20 20:25:49 +01:00
|
|
|
import android.util.Base64;
|
2013-11-04 13:31:01 +01:00
|
|
|
|
2015-09-24 22:52:02 +02:00
|
|
|
import org.telegram.tgnet.SerializedData;
|
|
|
|
import org.telegram.tgnet.TLRPC;
|
2013-10-25 17:19:00 +02:00
|
|
|
|
|
|
|
import java.io.File;
|
2017-03-31 01:58:05 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Map;
|
2013-10-25 17:19:00 +02:00
|
|
|
|
|
|
|
public class UserConfig {
|
2015-05-21 23:27:27 +02:00
|
|
|
|
2014-06-13 12:42:21 +02:00
|
|
|
private static TLRPC.User currentUser;
|
2016-06-24 12:27:15 +02:00
|
|
|
public static boolean registeredForPush;
|
2013-10-25 17:19:00 +02:00
|
|
|
public static String pushString = "";
|
2013-12-20 20:25:49 +01:00
|
|
|
public static int lastSendMessageId = -210000;
|
|
|
|
public static int lastLocalId = -210000;
|
2014-07-27 00:28:33 +02:00
|
|
|
public static int lastBroadcastId = -1;
|
2013-10-25 17:19:00 +02:00
|
|
|
public static String contactsHash = "";
|
2016-06-24 12:27:15 +02:00
|
|
|
public static boolean blockedUsersLoaded;
|
2014-10-05 23:23:57 +02:00
|
|
|
private final static Object sync = new Object();
|
2016-06-24 12:27:15 +02:00
|
|
|
public static boolean saveIncomingPhotos;
|
2015-02-26 02:32:51 +01:00
|
|
|
public static String passcodeHash = "";
|
2015-05-21 23:27:27 +02:00
|
|
|
public static byte[] passcodeSalt = new byte[0];
|
2016-06-24 12:27:15 +02:00
|
|
|
public static boolean appLocked;
|
|
|
|
public static int passcodeType;
|
2015-02-26 02:32:51 +01:00
|
|
|
public static int autoLockIn = 60 * 60;
|
2017-03-31 01:58:05 +02:00
|
|
|
public static boolean allowScreenCapture;
|
2016-06-24 12:27:15 +02:00
|
|
|
public static int lastPauseTime;
|
2017-07-08 18:32:04 +02:00
|
|
|
public static long lastAppPauseTime;
|
2016-06-24 12:27:15 +02:00
|
|
|
public static boolean isWaitingForPasscodeEnter;
|
2015-10-29 18:10:07 +01:00
|
|
|
public static boolean useFingerprint = true;
|
2016-03-06 02:49:31 +01:00
|
|
|
public static String lastUpdateVersion;
|
2015-08-13 11:23:31 +02:00
|
|
|
public static int lastContactsSyncTime;
|
2016-05-25 23:49:47 +02:00
|
|
|
public static int lastHintsSyncTime;
|
2016-06-24 12:27:15 +02:00
|
|
|
public static boolean draftsLoaded;
|
2017-03-31 01:58:05 +02:00
|
|
|
public static boolean notificationsConverted = true;
|
|
|
|
public static boolean pinnedDialogsLoaded = true;
|
|
|
|
public static TLRPC.TL_account_tmpPassword tmpPassword;
|
2015-11-26 22:04:02 +01:00
|
|
|
|
|
|
|
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;
|
2013-10-25 17:19:00 +02:00
|
|
|
|
2017-07-08 18:32:04 +02:00
|
|
|
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;
|
|
|
|
|
2013-10-25 17:19:00 +02:00
|
|
|
public static int getNewMessageId() {
|
|
|
|
int id;
|
|
|
|
synchronized (sync) {
|
|
|
|
id = lastSendMessageId;
|
|
|
|
lastSendMessageId--;
|
|
|
|
}
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
2013-11-04 13:31:01 +01:00
|
|
|
public static void saveConfig(boolean withFile) {
|
2013-12-20 20:25:49 +01:00
|
|
|
saveConfig(withFile, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void saveConfig(boolean withFile, File oldFile) {
|
2013-10-25 17:19:00 +02:00
|
|
|
synchronized (sync) {
|
2013-12-20 20:25:49 +01:00
|
|
|
try {
|
2013-11-04 13:31:01 +01:00
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("userconfing", Context.MODE_PRIVATE);
|
|
|
|
SharedPreferences.Editor editor = preferences.edit();
|
2014-02-28 23:28:25 +01:00
|
|
|
editor.putBoolean("registeredForPush", registeredForPush);
|
2016-01-11 18:19:48 +01:00
|
|
|
editor.putString("pushString2", pushString);
|
2014-02-28 23:28:25 +01:00
|
|
|
editor.putInt("lastSendMessageId", lastSendMessageId);
|
|
|
|
editor.putInt("lastLocalId", lastLocalId);
|
|
|
|
editor.putString("contactsHash", contactsHash);
|
|
|
|
editor.putBoolean("saveIncomingPhotos", saveIncomingPhotos);
|
2014-07-27 00:28:33 +02:00
|
|
|
editor.putInt("lastBroadcastId", lastBroadcastId);
|
2014-08-22 16:24:33 +02:00
|
|
|
editor.putBoolean("blockedUsersLoaded", blockedUsersLoaded);
|
2015-02-26 02:32:51 +01:00
|
|
|
editor.putString("passcodeHash1", passcodeHash);
|
2015-05-21 23:27:27 +02:00
|
|
|
editor.putString("passcodeSalt", passcodeSalt.length > 0 ? Base64.encodeToString(passcodeSalt, Base64.DEFAULT) : "");
|
2015-02-26 02:32:51 +01:00
|
|
|
editor.putBoolean("appLocked", appLocked);
|
|
|
|
editor.putInt("passcodeType", passcodeType);
|
|
|
|
editor.putInt("autoLockIn", autoLockIn);
|
|
|
|
editor.putInt("lastPauseTime", lastPauseTime);
|
2017-07-08 18:32:04 +02:00
|
|
|
editor.putLong("lastAppPauseTime", lastAppPauseTime);
|
2016-03-06 02:49:31 +01:00
|
|
|
editor.putString("lastUpdateVersion2", lastUpdateVersion);
|
2015-08-13 11:23:31 +02:00
|
|
|
editor.putInt("lastContactsSyncTime", lastContactsSyncTime);
|
2015-10-29 18:10:07 +01:00
|
|
|
editor.putBoolean("useFingerprint", useFingerprint);
|
2016-05-25 23:49:47 +02:00
|
|
|
editor.putInt("lastHintsSyncTime", lastHintsSyncTime);
|
2016-06-24 12:27:15 +02:00
|
|
|
editor.putBoolean("draftsLoaded", draftsLoaded);
|
2017-03-31 01:58:05 +02:00
|
|
|
editor.putBoolean("notificationsConverted", notificationsConverted);
|
|
|
|
editor.putBoolean("allowScreenCapture", allowScreenCapture);
|
|
|
|
editor.putBoolean("pinnedDialogsLoaded", pinnedDialogsLoaded);
|
2015-02-26 02:32:51 +01:00
|
|
|
|
2017-07-08 18:32:04 +02:00
|
|
|
editor.putInt("3migrateOffsetId", migrateOffsetId);
|
2015-11-26 22:04:02 +01:00
|
|
|
if (migrateOffsetId != -1) {
|
2017-07-08 18:32:04 +02:00
|
|
|
editor.putInt("3migrateOffsetDate", migrateOffsetDate);
|
|
|
|
editor.putInt("3migrateOffsetUserId", migrateOffsetUserId);
|
|
|
|
editor.putInt("3migrateOffsetChatId", migrateOffsetChatId);
|
|
|
|
editor.putInt("3migrateOffsetChannelId", migrateOffsetChannelId);
|
|
|
|
editor.putLong("3migrateOffsetAccess", migrateOffsetAccess);
|
2015-11-26 22:04:02 +01:00
|
|
|
}
|
2017-07-08 18:32:04 +02:00
|
|
|
|
|
|
|
|
|
|
|
editor.putInt("2totalDialogsLoadCount", totalDialogsLoadCount);
|
|
|
|
editor.putInt("2dialogsLoadOffsetId", dialogsLoadOffsetId);
|
|
|
|
editor.putInt("2dialogsLoadOffsetDate", dialogsLoadOffsetDate);
|
|
|
|
editor.putInt("2dialogsLoadOffsetUserId", dialogsLoadOffsetUserId);
|
|
|
|
editor.putInt("2dialogsLoadOffsetChatId", dialogsLoadOffsetChatId);
|
|
|
|
editor.putInt("2dialogsLoadOffsetChannelId", dialogsLoadOffsetChannelId);
|
|
|
|
editor.putLong("2dialogsLoadOffsetAccess", dialogsLoadOffsetAccess);
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
if (tmpPassword != null) {
|
|
|
|
SerializedData data = new SerializedData();
|
|
|
|
tmpPassword.serializeToStream(data);
|
|
|
|
String string = Base64.encodeToString(data.toByteArray(), Base64.DEFAULT);
|
|
|
|
editor.putString("tmpPassword", string);
|
|
|
|
data.cleanup();
|
|
|
|
} else {
|
|
|
|
editor.remove("tmpPassword");
|
|
|
|
}
|
2015-11-26 22:04:02 +01:00
|
|
|
|
2013-12-20 20:25:49 +01:00
|
|
|
if (currentUser != null) {
|
|
|
|
if (withFile) {
|
|
|
|
SerializedData data = new SerializedData();
|
|
|
|
currentUser.serializeToStream(data);
|
2017-03-31 01:58:05 +02:00
|
|
|
String string = Base64.encodeToString(data.toByteArray(), Base64.DEFAULT);
|
|
|
|
editor.putString("user", string);
|
2015-02-27 20:57:58 +01:00
|
|
|
data.cleanup();
|
2013-11-04 13:31:01 +01:00
|
|
|
}
|
2013-12-20 20:25:49 +01:00
|
|
|
} else {
|
|
|
|
editor.remove("user");
|
|
|
|
}
|
2015-05-21 23:27:27 +02:00
|
|
|
|
2013-12-20 20:25:49 +01:00
|
|
|
editor.commit();
|
|
|
|
if (oldFile != null) {
|
|
|
|
oldFile.delete();
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2013-12-20 20:25:49 +01:00
|
|
|
} catch (Exception e) {
|
2017-03-31 01:58:05 +02:00
|
|
|
FileLog.e(e);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-13 12:42:21 +02:00
|
|
|
public static boolean isClientActivated() {
|
|
|
|
synchronized (sync) {
|
|
|
|
return currentUser != null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static int getClientUserId() {
|
|
|
|
synchronized (sync) {
|
|
|
|
return currentUser != null ? currentUser.id : 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static TLRPC.User getCurrentUser() {
|
|
|
|
synchronized (sync) {
|
|
|
|
return currentUser;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setCurrentUser(TLRPC.User user) {
|
|
|
|
synchronized (sync) {
|
|
|
|
currentUser = user;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-25 17:19:00 +02:00
|
|
|
public static void loadConfig() {
|
|
|
|
synchronized (sync) {
|
2015-10-29 18:10:07 +01:00
|
|
|
final File configFile = new File(ApplicationLoader.getFilesDirFixed(), "user.dat");
|
2013-10-25 17:19:00 +02:00
|
|
|
if (configFile.exists()) {
|
|
|
|
try {
|
|
|
|
SerializedData data = new SerializedData(configFile);
|
2015-05-03 13:48:36 +02:00
|
|
|
int ver = data.readInt32(false);
|
2013-11-04 13:31:01 +01:00
|
|
|
if (ver == 1) {
|
2015-05-03 13:48:36 +02:00
|
|
|
int constructor = data.readInt32(false);
|
2015-06-29 19:12:11 +02:00
|
|
|
currentUser = TLRPC.User.TLdeserialize(data, constructor, false);
|
2015-05-03 13:48:36 +02:00
|
|
|
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);
|
|
|
|
contactsHash = data.readString(false);
|
2016-06-24 12:27:15 +02:00
|
|
|
data.readString(false);
|
2015-05-03 13:48:36 +02:00
|
|
|
saveIncomingPhotos = data.readBool(false);
|
|
|
|
MessagesStorage.lastQtsValue = data.readInt32(false);
|
|
|
|
MessagesStorage.lastSecretVersion = data.readInt32(false);
|
|
|
|
int val = data.readInt32(false);
|
2013-10-25 17:19:00 +02:00
|
|
|
if (val == 1) {
|
2015-05-03 13:48:36 +02:00
|
|
|
MessagesStorage.secretPBytes = data.readByteArray(false);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
MessagesStorage.secretG = data.readInt32(false);
|
2013-12-20 20:25:49 +01:00
|
|
|
Utilities.stageQueue.postRunnable(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
saveConfig(true, configFile);
|
|
|
|
}
|
|
|
|
});
|
2013-11-04 13:31:01 +01:00
|
|
|
} else if (ver == 2) {
|
2015-05-03 13:48:36 +02:00
|
|
|
int constructor = data.readInt32(false);
|
2015-06-29 19:12:11 +02:00
|
|
|
currentUser = TLRPC.User.TLdeserialize(data, constructor, false);
|
2013-11-04 13:31:01 +01:00
|
|
|
|
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("userconfing", Context.MODE_PRIVATE);
|
|
|
|
registeredForPush = preferences.getBoolean("registeredForPush", false);
|
2016-01-11 18:19:48 +01:00
|
|
|
pushString = preferences.getString("pushString2", "");
|
2013-12-20 20:25:49 +01:00
|
|
|
lastSendMessageId = preferences.getInt("lastSendMessageId", -210000);
|
|
|
|
lastLocalId = preferences.getInt("lastLocalId", -210000);
|
2013-11-04 13:31:01 +01:00
|
|
|
contactsHash = preferences.getString("contactsHash", "");
|
|
|
|
saveIncomingPhotos = preferences.getBoolean("saveIncomingPhotos", false);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2013-12-20 20:25:49 +01:00
|
|
|
if (lastLocalId > -210000) {
|
|
|
|
lastLocalId = -210000;
|
|
|
|
}
|
|
|
|
if (lastSendMessageId > -210000) {
|
|
|
|
lastSendMessageId = -210000;
|
|
|
|
}
|
2015-02-27 20:57:58 +01:00
|
|
|
data.cleanup();
|
2013-12-20 20:25:49 +01:00
|
|
|
Utilities.stageQueue.postRunnable(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
saveConfig(true, configFile);
|
|
|
|
}
|
|
|
|
});
|
2013-10-25 17:19:00 +02:00
|
|
|
} catch (Exception e) {
|
2017-03-31 01:58:05 +02:00
|
|
|
FileLog.e(e);
|
2013-12-20 20:25:49 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("userconfing", Context.MODE_PRIVATE);
|
|
|
|
registeredForPush = preferences.getBoolean("registeredForPush", false);
|
2016-01-11 18:19:48 +01:00
|
|
|
pushString = preferences.getString("pushString2", "");
|
2013-12-20 20:25:49 +01:00
|
|
|
lastSendMessageId = preferences.getInt("lastSendMessageId", -210000);
|
|
|
|
lastLocalId = preferences.getInt("lastLocalId", -210000);
|
|
|
|
contactsHash = preferences.getString("contactsHash", "");
|
|
|
|
saveIncomingPhotos = preferences.getBoolean("saveIncomingPhotos", false);
|
2014-07-27 00:28:33 +02:00
|
|
|
lastBroadcastId = preferences.getInt("lastBroadcastId", -1);
|
2014-08-22 16:24:33 +02:00
|
|
|
blockedUsersLoaded = preferences.getBoolean("blockedUsersLoaded", false);
|
2015-02-26 02:32:51 +01:00
|
|
|
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);
|
2017-07-08 18:32:04 +02:00
|
|
|
lastAppPauseTime = preferences.getLong("lastAppPauseTime", 0);
|
2015-10-29 18:10:07 +01:00
|
|
|
useFingerprint = preferences.getBoolean("useFingerprint", true);
|
2016-03-06 02:49:31 +01:00
|
|
|
lastUpdateVersion = preferences.getString("lastUpdateVersion2", "3.5");
|
2015-08-13 11:23:31 +02:00
|
|
|
lastContactsSyncTime = preferences.getInt("lastContactsSyncTime", (int) (System.currentTimeMillis() / 1000) - 23 * 60 * 60);
|
2016-05-25 23:49:47 +02:00
|
|
|
lastHintsSyncTime = preferences.getInt("lastHintsSyncTime", (int) (System.currentTimeMillis() / 1000) - 25 * 60 * 60);
|
2016-06-24 12:27:15 +02:00
|
|
|
draftsLoaded = preferences.getBoolean("draftsLoaded", false);
|
2017-03-31 01:58:05 +02:00
|
|
|
notificationsConverted = preferences.getBoolean("notificationsConverted", false);
|
|
|
|
allowScreenCapture = preferences.getBoolean("allowScreenCapture", false);
|
|
|
|
pinnedDialogsLoaded = preferences.getBoolean("pinnedDialogsLoaded", false);
|
|
|
|
|
|
|
|
if (UserConfig.passcodeHash.length() > 0 && lastPauseTime == 0) {
|
|
|
|
lastPauseTime = (int) (System.currentTimeMillis() / 1000 - 60 * 10);
|
|
|
|
}
|
2015-11-26 22:04:02 +01:00
|
|
|
|
2017-07-08 18:32:04 +02:00
|
|
|
migrateOffsetId = preferences.getInt("3migrateOffsetId", 0);
|
2015-11-26 22:04:02 +01:00
|
|
|
if (migrateOffsetId != -1) {
|
2017-07-08 18:32:04 +02:00
|
|
|
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);
|
2015-11-26 22:04:02 +01:00
|
|
|
}
|
2017-07-08 18:32:04 +02:00
|
|
|
// migrateOffsetId = 0;
|
|
|
|
// migrateOffsetDate = 0;
|
|
|
|
// migrateOffsetUserId = 0;
|
|
|
|
// migrateOffsetChatId = 0;
|
|
|
|
// migrateOffsetChannelId = 0;
|
|
|
|
// migrateOffsetAccess = 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 = -1;
|
|
|
|
// totalDialogsLoadCount = 0;
|
|
|
|
// dialogsLoadOffsetDate = -1;
|
|
|
|
// dialogsLoadOffsetUserId = -1;
|
|
|
|
// dialogsLoadOffsetChatId = -1;
|
|
|
|
// dialogsLoadOffsetChannelId = -1;
|
|
|
|
// dialogsLoadOffsetAccess = -1;
|
2015-11-26 22:04:02 +01:00
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
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);
|
2015-06-29 19:12:11 +02:00
|
|
|
currentUser = TLRPC.User.TLdeserialize(data, data.readInt32(false), false);
|
2015-02-27 20:57:58 +01:00
|
|
|
data.cleanup();
|
2013-12-20 20:25:49 +01:00
|
|
|
}
|
|
|
|
}
|
2015-05-21 23:27:27 +02:00
|
|
|
String passcodeSaltString = preferences.getString("passcodeSalt", "");
|
|
|
|
if (passcodeSaltString.length() > 0) {
|
|
|
|
passcodeSalt = Base64.decode(passcodeSaltString, Base64.DEFAULT);
|
|
|
|
} else {
|
|
|
|
passcodeSalt = new byte[0];
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2015-05-21 23:27:27 +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(false);
|
|
|
|
} catch (Exception e) {
|
2017-03-31 01:58:05 +02:00
|
|
|
FileLog.e(e);
|
2015-05-21 23:27:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
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) {
|
2017-03-31 01:58:05 +02:00
|
|
|
FileLog.e(e);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
}
|
2015-05-21 23:27:27 +02:00
|
|
|
return false;
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void clearConfig() {
|
|
|
|
currentUser = null;
|
|
|
|
registeredForPush = false;
|
|
|
|
contactsHash = "";
|
2013-12-20 20:25:49 +01:00
|
|
|
lastSendMessageId = -210000;
|
2014-07-27 00:28:33 +02:00
|
|
|
lastBroadcastId = -1;
|
2013-10-25 17:19:00 +02:00
|
|
|
saveIncomingPhotos = false;
|
2014-08-22 16:24:33 +02:00
|
|
|
blockedUsersLoaded = false;
|
2015-11-26 22:04:02 +01:00
|
|
|
migrateOffsetId = -1;
|
|
|
|
migrateOffsetDate = -1;
|
|
|
|
migrateOffsetUserId = -1;
|
|
|
|
migrateOffsetChatId = -1;
|
|
|
|
migrateOffsetChannelId = -1;
|
|
|
|
migrateOffsetAccess = -1;
|
2017-07-08 18:32:04 +02:00
|
|
|
dialogsLoadOffsetId = 0;
|
|
|
|
totalDialogsLoadCount = 0;
|
|
|
|
dialogsLoadOffsetDate = 0;
|
|
|
|
dialogsLoadOffsetUserId = 0;
|
|
|
|
dialogsLoadOffsetChatId = 0;
|
|
|
|
dialogsLoadOffsetChannelId = 0;
|
|
|
|
dialogsLoadOffsetAccess = 0;
|
2015-02-26 02:32:51 +01:00
|
|
|
appLocked = false;
|
|
|
|
passcodeType = 0;
|
|
|
|
passcodeHash = "";
|
2015-05-21 23:27:27 +02:00
|
|
|
passcodeSalt = new byte[0];
|
2015-02-26 02:32:51 +01:00
|
|
|
autoLockIn = 60 * 60;
|
|
|
|
lastPauseTime = 0;
|
2015-10-29 18:10:07 +01:00
|
|
|
useFingerprint = true;
|
2016-06-24 12:27:15 +02:00
|
|
|
draftsLoaded = true;
|
2017-03-31 01:58:05 +02:00
|
|
|
notificationsConverted = true;
|
2015-02-26 02:32:51 +01:00
|
|
|
isWaitingForPasscodeEnter = false;
|
2017-03-31 01:58:05 +02:00
|
|
|
allowScreenCapture = false;
|
|
|
|
pinnedDialogsLoaded = false;
|
2016-03-06 02:49:31 +01:00
|
|
|
lastUpdateVersion = BuildVars.BUILD_VERSION_STRING;
|
2015-08-13 11:23:31 +02:00
|
|
|
lastContactsSyncTime = (int) (System.currentTimeMillis() / 1000) - 23 * 60 * 60;
|
2016-05-25 23:49:47 +02:00
|
|
|
lastHintsSyncTime = (int) (System.currentTimeMillis() / 1000) - 25 * 60 * 60;
|
2013-11-04 13:31:01 +01:00
|
|
|
saveConfig(true);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
}
|