mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-24 02:39:55 +01:00
Fix legacy restore options in new restore flows.
This commit is contained in:
committed by
Michelle Tang
parent
3ea2c01c15
commit
be45bdb562
@@ -32,6 +32,7 @@ import org.thoughtcrime.securesms.database.AttachmentTable;
|
||||
import org.thoughtcrime.securesms.database.EmojiSearchTable;
|
||||
import org.thoughtcrime.securesms.database.GroupReceiptTable;
|
||||
import org.thoughtcrime.securesms.database.KeyValueDatabase;
|
||||
import org.thoughtcrime.securesms.database.KyberPreKeyTable;
|
||||
import org.thoughtcrime.securesms.database.MentionTable;
|
||||
import org.thoughtcrime.securesms.database.MessageTable;
|
||||
import org.thoughtcrime.securesms.database.OneTimePreKeyTable;
|
||||
@@ -88,6 +89,7 @@ public class FullBackupExporter extends FullBackupBase {
|
||||
private static final Set<String> TABLE_CONTENT_BLOCKLIST = SetUtil.newHashSet(
|
||||
SignedPreKeyTable.TABLE_NAME,
|
||||
OneTimePreKeyTable.TABLE_NAME,
|
||||
KyberPreKeyTable.TABLE_NAME,
|
||||
SessionTable.TABLE_NAME,
|
||||
SearchTable.FTS_TABLE_NAME,
|
||||
EmojiSearchTable.TABLE_NAME,
|
||||
|
||||
@@ -29,7 +29,10 @@ import org.thoughtcrime.securesms.crypto.ModernEncryptingPartOutputStream;
|
||||
import org.thoughtcrime.securesms.database.AttachmentTable;
|
||||
import org.thoughtcrime.securesms.database.EmojiSearchTable;
|
||||
import org.thoughtcrime.securesms.database.KeyValueDatabase;
|
||||
import org.thoughtcrime.securesms.database.KyberPreKeyTable;
|
||||
import org.thoughtcrime.securesms.database.OneTimePreKeyTable;
|
||||
import org.thoughtcrime.securesms.database.SearchTable;
|
||||
import org.thoughtcrime.securesms.database.SignedPreKeyTable;
|
||||
import org.thoughtcrime.securesms.database.StickerTable;
|
||||
import org.thoughtcrime.securesms.dependencies.AppDependencies;
|
||||
import org.thoughtcrime.securesms.keyvalue.KeyValueDataSet;
|
||||
@@ -60,11 +63,15 @@ import java.util.Queue;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import kotlin.collections.SetsKt;
|
||||
|
||||
public class FullBackupImporter extends FullBackupBase {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static final String TAG = Log.tag(FullBackupImporter.class);
|
||||
|
||||
private static final Set<String> KEY_TABLES = SetsKt.setOf(KyberPreKeyTable.TABLE_NAME, OneTimePreKeyTable.TABLE_NAME, SignedPreKeyTable.TABLE_NAME);
|
||||
|
||||
public static boolean validatePassphrase(@NonNull Context context,
|
||||
@NonNull Uri uri,
|
||||
@NonNull String passphrase)
|
||||
@@ -83,17 +90,25 @@ public class FullBackupImporter extends FullBackupBase {
|
||||
}
|
||||
}
|
||||
|
||||
public static void importFile(@NonNull Context context, @NonNull AttachmentSecret attachmentSecret,
|
||||
@NonNull SQLiteDatabase db, @NonNull Uri uri, @NonNull String passphrase)
|
||||
public static void importFile(@NonNull Context context,
|
||||
@NonNull AttachmentSecret attachmentSecret,
|
||||
@NonNull SQLiteDatabase db,
|
||||
@NonNull Uri uri,
|
||||
@NonNull String passphrase,
|
||||
boolean excludeKeyTables)
|
||||
throws IOException
|
||||
{
|
||||
try (InputStream is = getInputStream(context, uri)) {
|
||||
importFile(context, attachmentSecret, db, is, passphrase);
|
||||
importFile(context, attachmentSecret, db, is, passphrase, excludeKeyTables);
|
||||
}
|
||||
}
|
||||
|
||||
public static void importFile(@NonNull Context context, @NonNull AttachmentSecret attachmentSecret,
|
||||
@NonNull SQLiteDatabase db, @NonNull InputStream is, @NonNull String passphrase)
|
||||
public static void importFile(@NonNull Context context,
|
||||
@NonNull AttachmentSecret attachmentSecret,
|
||||
@NonNull SQLiteDatabase db,
|
||||
@NonNull InputStream is,
|
||||
@NonNull String passphrase,
|
||||
boolean excludeKeyTables)
|
||||
throws IOException
|
||||
{
|
||||
int count = 0;
|
||||
@@ -106,7 +121,7 @@ public class FullBackupImporter extends FullBackupBase {
|
||||
try {
|
||||
BackupRecordInputStream inputStream = new BackupRecordInputStream(is, passphrase);
|
||||
|
||||
dropAllTables(db);
|
||||
dropAllTables(db, excludeKeyTables);
|
||||
|
||||
BackupFrame frame;
|
||||
|
||||
@@ -115,7 +130,7 @@ public class FullBackupImporter extends FullBackupBase {
|
||||
count++;
|
||||
|
||||
if (frame.version != null) processVersion(db, frame.version);
|
||||
else if (frame.statement != null) processStatement(db, frame.statement);
|
||||
else if (frame.statement != null) processStatement(db, frame.statement, excludeKeyTables);
|
||||
else if (frame.preference != null) processPreference(context, frame.preference);
|
||||
else if (frame.attachment != null) processAttachment(context, attachmentSecret, db, frame.attachment, inputStream);
|
||||
else if (frame.sticker != null) processSticker(context, attachmentSecret, db, frame.sticker, inputStream);
|
||||
@@ -162,7 +177,7 @@ public class FullBackupImporter extends FullBackupBase {
|
||||
db.setVersion(version.version);
|
||||
}
|
||||
|
||||
private static void processStatement(@NonNull SQLiteDatabase db, SqlStatement statement) {
|
||||
private static void processStatement(@NonNull SQLiteDatabase db, SqlStatement statement, boolean excludeKeyTables) {
|
||||
if (statement.statement == null) {
|
||||
Log.w(TAG, "Null statement!");
|
||||
return;
|
||||
@@ -172,8 +187,9 @@ public class FullBackupImporter extends FullBackupBase {
|
||||
boolean isForEmojiSecretTable = statement.statement.contains(EmojiSearchTable.TABLE_NAME + "_");
|
||||
boolean isForSqliteSecretTable = statement.statement.toLowerCase().startsWith("create table sqlite_");
|
||||
boolean isForRemoteMegaphoneTable = statement.statement.toLowerCase().startsWith("insert into remote_megaphone");
|
||||
boolean isForExcludedKeyTable = excludeKeyTables && KEY_TABLES.stream().anyMatch(table -> statement.statement.toLowerCase().contains(table));
|
||||
|
||||
if (isForMmsFtsSecretTable || isForEmojiSecretTable || isForSqliteSecretTable || isForRemoteMegaphoneTable) {
|
||||
if (isForMmsFtsSecretTable || isForEmojiSecretTable || isForSqliteSecretTable || isForRemoteMegaphoneTable || isForExcludedKeyTable) {
|
||||
Log.i(TAG, "Ignoring import for statement: " + statement.statement);
|
||||
return;
|
||||
}
|
||||
@@ -315,12 +331,18 @@ public class FullBackupImporter extends FullBackupBase {
|
||||
}
|
||||
}
|
||||
|
||||
private static void dropAllTables(@NonNull SQLiteDatabase db) {
|
||||
private static void dropAllTables(@NonNull SQLiteDatabase db, boolean excludeKeyTables) {
|
||||
for (String trigger : SqlUtil.getAllTriggers(db)) {
|
||||
Log.i(TAG, "Dropping trigger: " + trigger);
|
||||
db.execSQL("DROP TRIGGER IF EXISTS " + trigger);
|
||||
}
|
||||
|
||||
for (String table : getTablesToDropInOrder(db)) {
|
||||
if (excludeKeyTables && KEY_TABLES.contains(table)) {
|
||||
Log.i(TAG, "Skipping table: " + table);
|
||||
continue;
|
||||
}
|
||||
|
||||
Log.i(TAG, "Dropping table: " + table);
|
||||
db.execSQL("DROP TABLE IF EXISTS " + table);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user