mirror of
https://github.com/wrwrabbit/Partisan-Telegram-Android.git
synced 2026-05-22 19:54:34 +00:00
clear database after file protection disabling
This commit is contained in:
parent
7983d512f3
commit
bb7f67030d
5 changed files with 72 additions and 4 deletions
|
|
@ -444,6 +444,7 @@ public class SharedConfig {
|
|||
public static boolean showEncryptedChatsFromEncryptedGroups = false;
|
||||
public static boolean encryptedGroupsEnabled = false;
|
||||
public static boolean fileProtectionForAllAccountsEnabled = true;
|
||||
public static boolean disableFileProtectionAfterRestart = false;
|
||||
public static boolean fileProtectionWorksWhenFakePasscodeActivated = true;
|
||||
|
||||
private static final int[] LOW_SOC = {
|
||||
|
|
@ -738,7 +739,8 @@ public class SharedConfig {
|
|||
BrowserHistory.clearHistory();
|
||||
}, 1000);
|
||||
sharedConfigMigrationVersion++;
|
||||
} if (sharedConfigMigrationVersion == 1) {
|
||||
}
|
||||
if (sharedConfigMigrationVersion == 1) {
|
||||
boolean updatedFromOldPtg = prevMigrationVersion == 1 || !fakePasscodes.isEmpty() || !passcodeHash.isEmpty();
|
||||
if (updatedFromOldPtg) { // check if ptg has just been updated
|
||||
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("userconfing", Context.MODE_PRIVATE);
|
||||
|
|
@ -963,6 +965,7 @@ public class SharedConfig {
|
|||
showEncryptedChatsFromEncryptedGroups = preferences.getBoolean("showEncryptedChatsFromEncryptedGroups", false);
|
||||
encryptedGroupsEnabled = preferences.getBoolean("encryptedGroupsEnabled", encryptedGroupsEnabled);
|
||||
fileProtectionForAllAccountsEnabled = preferences.getBoolean("fileProtectionForAllAccountsEnabled", fileProtectionForAllAccountsEnabled);
|
||||
disableFileProtectionAfterRestart = preferences.getBoolean("disableFileProtectionAfterRestart", disableFileProtectionAfterRestart);
|
||||
fileProtectionWorksWhenFakePasscodeActivated = preferences.getBoolean("fileProtectionWorksWhenFakePasscodeActivated", fileProtectionWorksWhenFakePasscodeActivated);
|
||||
dayNightWallpaperSwitchHint = preferences.getInt("dayNightWallpaperSwitchHint", 0);
|
||||
bigCameraForRound = preferences.getBoolean("bigCameraForRound", false);
|
||||
|
|
@ -1084,6 +1087,14 @@ public class SharedConfig {
|
|||
editor.commit();
|
||||
}
|
||||
|
||||
public static void setDisableFileProtectionAfterRestart(boolean value) {
|
||||
disableFileProtectionAfterRestart = value;
|
||||
SharedPreferences preferences = MessagesController.getGlobalMainSettings();
|
||||
SharedPreferences.Editor editor = preferences.edit();
|
||||
editor.putBoolean("disableFileProtectionAfterRestart", value);
|
||||
editor.commit();
|
||||
}
|
||||
|
||||
public static void toggleFileProtectionWorksWhenFakePasscodeActivated() {
|
||||
fileProtectionWorksWhenFakePasscodeActivated = !fileProtectionWorksWhenFakePasscodeActivated;
|
||||
SharedPreferences preferences = MessagesController.getGlobalMainSettings();
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@ import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
|||
|
||||
import com.google.android.exoplayer2.util.Log;
|
||||
|
||||
import org.telegram.messenger.fakepasscode.FakePasscode;
|
||||
import org.telegram.messenger.fakepasscode.FakePasscodeUtils;
|
||||
import org.telegram.messenger.partisan.SecurityIssue;
|
||||
import org.telegram.tgnet.SerializedData;
|
||||
|
|
@ -120,6 +119,7 @@ public class UserConfig extends BaseController {
|
|||
public boolean showSecuritySuggestions = false;
|
||||
public long lastSecuritySuggestionsShow = 0;
|
||||
public boolean fileProtectionEnabled = false;
|
||||
public boolean disableFileProtectionAfterRestart = false;
|
||||
private final Map<Integer, Boolean> temporarilyLoadedPinnedDialogs = new ConcurrentHashMap<>();
|
||||
|
||||
private static ObjectMapper jsonMapper = null;
|
||||
|
|
@ -299,6 +299,7 @@ public class UserConfig extends BaseController {
|
|||
editor.putBoolean("showSecuritySuggestions", showSecuritySuggestions);
|
||||
editor.putLong("lastSecuritySuggestionsShow", lastSecuritySuggestionsShow);
|
||||
editor.putBoolean("fileProtectionEnabled", fileProtectionEnabled);
|
||||
editor.putBoolean("disableFileProtectionAfterRestart", disableFileProtectionAfterRestart);
|
||||
String savedChannelsStr = savedChannels.stream().reduce("", (acc, s) -> acc.isEmpty() ? s : acc + "," + s);
|
||||
editor.putString("savedChannels", savedChannelsStr);
|
||||
String pinnedSavedChannelsStr = pinnedSavedChannels.stream().reduce("", (acc, s) -> acc.isEmpty() ? s : acc + "," + s);
|
||||
|
|
@ -471,6 +472,7 @@ public class UserConfig extends BaseController {
|
|||
if (SharedConfig.fileProtectionForAllAccountsEnabled) { // Don't enable file protection for accounts if global file protection enabled.
|
||||
fileProtectionEnabled = false;
|
||||
}
|
||||
disableFileProtectionAfterRestart = preferences.getBoolean("disableFileProtectionAfterRestart", disableFileProtectionAfterRestart);
|
||||
String savedChannelsStr = preferences.getString("savedChannels", defaultChannels);
|
||||
savedChannels = new HashSet<>(Arrays.asList(savedChannelsStr.split(",")));
|
||||
savedChannels.remove("");
|
||||
|
|
@ -651,6 +653,7 @@ public class UserConfig extends BaseController {
|
|||
showSecuritySuggestions = false;
|
||||
lastSecuritySuggestionsShow = 0;
|
||||
fileProtectionEnabled = false;
|
||||
disableFileProtectionAfterRestart = false;
|
||||
registeredForPush = false;
|
||||
contactsSavedCount = 0;
|
||||
lastSendMessageId = -210000;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,44 @@
|
|||
package org.telegram.messenger.partisan.fileprotection;
|
||||
|
||||
import org.telegram.messenger.AndroidUtilities;
|
||||
import org.telegram.messenger.NotificationCenter;
|
||||
import org.telegram.messenger.SharedConfig;
|
||||
import org.telegram.messenger.UserConfig;
|
||||
import org.telegram.messenger.partisan.PartisanLog;
|
||||
import org.telegram.messenger.partisan.Utils;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class FileProtectionPostRestartCleaner implements NotificationCenter.NotificationCenterDelegate {
|
||||
private final Set<Integer> accountsToClear = new HashSet<>();
|
||||
|
||||
public void checkAndClean() {
|
||||
Utils.foreachActivatedAccountInstance(accountInstance -> {
|
||||
UserConfig userConfig = accountInstance.getUserConfig();
|
||||
if (userConfig.disableFileProtectionAfterRestart || SharedConfig.disableFileProtectionAfterRestart) {
|
||||
PartisanLog.d("Clean the database after disabling file protection for account " + accountInstance.getCurrentAccount());
|
||||
accountsToClear.add(accountInstance.getCurrentAccount());
|
||||
AndroidUtilities.runOnUIThread(() -> {
|
||||
accountInstance.getNotificationCenter().addObserver(this, NotificationCenter.onDatabaseReset);
|
||||
accountInstance.getMessagesStorage().clearLocalDatabase();
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void didReceivedNotification(int id, int account, Object... args) {
|
||||
if (id == NotificationCenter.onDatabaseReset) {
|
||||
PartisanLog.d("Cleaning the database after disabling file protection for account " + account + " finished");
|
||||
NotificationCenter.getInstance(account).removeObserver(this, NotificationCenter.onDatabaseReset);
|
||||
UserConfig userConfig = UserConfig.getInstance(account);
|
||||
userConfig.disableFileProtectionAfterRestart = false;
|
||||
userConfig.saveConfig(false);
|
||||
accountsToClear.remove(account);
|
||||
if (accountsToClear.isEmpty()) {
|
||||
SharedConfig.setDisableFileProtectionAfterRestart(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -52,11 +52,15 @@ public class FileProtectionSwitcher implements NotificationCenter.NotificationCe
|
|||
fragment.showDialog(enablingFileProtectionDialog);
|
||||
|
||||
if (!enableForAllAccounts && valuesPerAccounts.isEmpty()) {
|
||||
if (SharedConfig.fileProtectionForAllAccountsEnabled) {
|
||||
SharedConfig.setDisableFileProtectionAfterRestart(true);
|
||||
}
|
||||
SharedConfig.setFileProtectionForAllAccounts(enableForAllAccounts);
|
||||
Utils.foreachActivatedAccountInstance(accountInstance -> {
|
||||
UserConfig userConfig = accountInstance.getUserConfig();
|
||||
if (userConfig.fileProtectionEnabled) {
|
||||
userConfig.fileProtectionEnabled = false;
|
||||
userConfig.disableFileProtectionAfterRestart = true;
|
||||
userConfig.clearPinnedDialogsLoaded();
|
||||
accountInstance.getUserConfig().saveConfig(false);
|
||||
}
|
||||
|
|
@ -89,6 +93,9 @@ public class FileProtectionSwitcher implements NotificationCenter.NotificationCe
|
|||
}
|
||||
|
||||
private void updateConfigs() {
|
||||
if (SharedConfig.fileProtectionForAllAccountsEnabled) {
|
||||
SharedConfig.setDisableFileProtectionAfterRestart(true);
|
||||
}
|
||||
SharedConfig.setFileProtectionForAllAccounts(enableForAllAccounts);
|
||||
Utils.foreachActivatedAccountInstance(accountInstance -> {
|
||||
boolean enabledInConfig = valuesPerAccounts.getOrDefault(accountInstance.getCurrentAccount(), false);
|
||||
|
|
@ -98,6 +105,9 @@ public class FileProtectionSwitcher implements NotificationCenter.NotificationCe
|
|||
if (userConfig.fileProtectionEnabled != enabledForAccountOrGlobally) {
|
||||
userConfig.clearPinnedDialogsLoaded();
|
||||
}
|
||||
if (userConfig.fileProtectionEnabled && !enabledInConfig) {
|
||||
userConfig.disableFileProtectionAfterRestart = true;
|
||||
}
|
||||
userConfig.fileProtectionEnabled = enabledInConfig;
|
||||
userConfig.saveConfig(false);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -132,8 +132,7 @@ import org.telegram.messenger.partisan.appmigration.MigrationIntentHandler;
|
|||
import org.telegram.messenger.partisan.appmigration.AppMigrator;
|
||||
import org.telegram.messenger.partisan.appmigration.AppMigratorPreferences;
|
||||
import org.telegram.messenger.partisan.appmigration.MaskedMigratorHelper;
|
||||
import org.telegram.messenger.partisan.secretgroups.EncryptedGroup;
|
||||
import org.telegram.messenger.partisan.secretgroups.EncryptedGroupState;
|
||||
import org.telegram.messenger.partisan.fileprotection.FileProtectionPostRestartCleaner;
|
||||
import org.telegram.messenger.partisan.secretgroups.EncryptedGroupUtils;
|
||||
import org.telegram.messenger.partisan.update.UpdateChecker;
|
||||
import org.telegram.messenger.partisan.update.UpdateData;
|
||||
|
|
@ -1606,6 +1605,7 @@ public class LaunchActivity extends BasePermissionsActivity implements INavigati
|
|||
NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.fileLoadProgressChanged);
|
||||
NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.fileLoadFailed);
|
||||
SecurityChecker.checkSecurityIssuesAndSave(this, currentAccount, false);
|
||||
Utilities.globalQueue.postRunnable(() -> new FileProtectionPostRestartCleaner().checkAndClean(), 1000);
|
||||
if (updateLayout != null && updateLayout.isCancelIcon() && SharedConfig.pendingPtgAppUpdate != null && getUpdateAccountNum() != currentAccount) {
|
||||
NotificationCenter.getInstance(getUpdateAccountNum()).addObserver(this, NotificationCenter.fileLoaded);
|
||||
NotificationCenter.getInstance(getUpdateAccountNum()).addObserver(this, NotificationCenter.fileLoadProgressChanged);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue