From 128da6db04d204dee437012d41dec06be4717537 Mon Sep 17 00:00:00 2001 From: Greyson Parrelli Date: Tue, 16 Apr 2019 10:10:02 -0400 Subject: [PATCH] Fix crash in backup restore related to sqlite_sequence. The new JobManager stuff created a table that had an auto-incrementing ID, which was incorrectly being backed up and restored, causing a crash. Now we skip it on both import and export. --- .../thoughtcrime/securesms/backup/FullBackupExporter.java | 3 ++- .../thoughtcrime/securesms/backup/FullBackupImporter.java | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/org/thoughtcrime/securesms/backup/FullBackupExporter.java b/src/org/thoughtcrime/securesms/backup/FullBackupExporter.java index 9e41a3918..23c252ca7 100644 --- a/src/org/thoughtcrime/securesms/backup/FullBackupExporter.java +++ b/src/org/thoughtcrime/securesms/backup/FullBackupExporter.java @@ -84,7 +84,8 @@ public class FullBackupExporter extends FullBackupBase { !table.equals(OneTimePreKeyDatabase.TABLE_NAME) && !table.equals(SessionDatabase.TABLE_NAME) && !table.startsWith(SearchDatabase.SMS_FTS_TABLE_NAME) && - !table.startsWith(SearchDatabase.MMS_FTS_TABLE_NAME)) + !table.startsWith(SearchDatabase.MMS_FTS_TABLE_NAME) && + !table.startsWith("sqlite_")) { count = exportTable(table, input, outputStream, null, null, count); } diff --git a/src/org/thoughtcrime/securesms/backup/FullBackupImporter.java b/src/org/thoughtcrime/securesms/backup/FullBackupImporter.java index 77ec1f53e..637fd0865 100644 --- a/src/org/thoughtcrime/securesms/backup/FullBackupImporter.java +++ b/src/org/thoughtcrime/securesms/backup/FullBackupImporter.java @@ -109,8 +109,9 @@ public class FullBackupImporter extends FullBackupBase { private static void processStatement(@NonNull SQLiteDatabase db, SqlStatement statement) { boolean isForSmsFtsSecretTable = statement.getStatement().contains(SearchDatabase.SMS_FTS_TABLE_NAME + "_"); boolean isForMmsFtsSecretTable = statement.getStatement().contains(SearchDatabase.MMS_FTS_TABLE_NAME + "_"); + boolean isForSqliteSecretTable = statement.getStatement().toLowerCase().startsWith("create table sqlite_"); - if (isForSmsFtsSecretTable || isForMmsFtsSecretTable) { + if (isForSmsFtsSecretTable || isForMmsFtsSecretTable || isForSqliteSecretTable) { Log.i(TAG, "Ignoring import for statement: " + statement.getStatement()); return; } @@ -165,7 +166,7 @@ public class FullBackupImporter extends FullBackupBase { String name = cursor.getString(0); String type = cursor.getString(1); - if ("table".equals(type)) { + if ("table".equals(type) && !name.startsWith("sqlite_")) { db.execSQL("DROP TABLE IF EXISTS " + name); } }