Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 18bbd767 authored by cketti's avatar cketti
Browse files

Add a way to inject SchemaDefinition into LocalStore

parent 83b6ab06
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ dependencies {
    testImplementation project(':mail:testing')
    testImplementation project(":backend:imap")
    testImplementation project(":mail:protocols:smtp")
    testImplementation project(":app:storage")
    testImplementation "org.robolectric:robolectric:${versions.robolectric}"
    testImplementation "junit:junit:${versions.junit}"
    testImplementation "com.google.truth:truth:${versions.truth}"
+3 −3
Original line number Diff line number Diff line
@@ -354,7 +354,7 @@ public class K9 {
     * {@code SharedPreference}.
     *
     * <p>
     * If the stored version matches {@link LocalStore#DB_VERSION} we know that the databases are
     * If the stored version matches {@link LocalStore#getDbVersion()} we know that the databases are
     * up to date.<br>
     * Using {@code SharedPreferences} should be a lot faster than opening all SQLite databases to
     * get the current database version.
@@ -369,7 +369,7 @@ public class K9 {

        int cachedVersion = databaseVersionCache.getInt(KEY_LAST_ACCOUNT_DATABASE_VERSION, 0);

        if (cachedVersion >= LocalStore.DB_VERSION) {
        if (cachedVersion >= LocalStore.getDbVersion()) {
            K9.setDatabasesUpToDate(false);
        }
        if (cachedVersion < VERSION_MIGRATE_OPENPGP_TO_ACCOUNTS) {
@@ -1073,7 +1073,7 @@ public class K9 {

        if (save) {
            Editor editor = databaseVersionCache.edit();
            editor.putInt(KEY_LAST_ACCOUNT_DATABASE_VERSION, LocalStore.DB_VERSION);
            editor.putInt(KEY_LAST_ACCOUNT_DATABASE_VERSION, LocalStore.getDbVersion());
            editor.apply();
        }
    }
+1 −1
Original line number Diff line number Diff line
@@ -188,7 +188,7 @@ public class LocalMessage extends MimeMessage {
        return (attachmentCount > 0);
    }

    int getAttachmentCount() {
    public int getAttachmentCount() {
        return attachmentCount;
    }

+38 −3
Original line number Diff line number Diff line
@@ -50,6 +50,7 @@ import com.fsck.k9.mail.Part;
import com.fsck.k9.mailstore.LocalFolder.DataLocation;
import com.fsck.k9.mailstore.LocalFolder.MoreMessages;
import com.fsck.k9.mailstore.LockableDatabase.DbCallback;
import com.fsck.k9.mailstore.LockableDatabase.SchemaDefinition;
import com.fsck.k9.mailstore.LockableDatabase.WrappedException;
import com.fsck.k9.mailstore.StorageManager.StorageProvider;
import com.fsck.k9.message.extractors.AttachmentCounter;
@@ -181,8 +182,6 @@ public class LocalStore {
     */
    private static final int THREAD_FLAG_UPDATE_BATCH_SIZE = 500;

    public static final int DB_VERSION = 65;

    private final Context context;
    private final ContentResolver contentResolver;
    private final MessagePreviewCreator messagePreviewCreator;
@@ -211,7 +210,11 @@ public class LocalStore {

        this.account = account;

        database = new LockableDatabase(context, account.getUuid(), new StoreSchemaDefinition(this));
        SchemaDefinitionFactory schemaDefinitionFactory = DI.get(SchemaDefinitionFactory.class);
        RealMigrationsHelper migrationsHelper = new RealMigrationsHelper();
        SchemaDefinition schemaDefinition = schemaDefinitionFactory.createSchemaDefinition(migrationsHelper);

        database = new LockableDatabase(context, account.getUuid(), schemaDefinition);
        database.setStorageProviderId(account.getLocalStorageProviderId());
        database.open();
    }
@@ -247,6 +250,11 @@ public class LocalStore {
        }
    }

    public static int getDbVersion() {
        SchemaDefinitionFactory schemaDefinitionFactory = DI.get(SchemaDefinitionFactory.class);
        return schemaDefinitionFactory.getDatabaseVersion();
    }

    public static void removeAccount(Account account) {
        try {
            removeInstance(account);
@@ -1354,4 +1362,31 @@ public class LocalStore {
            }
        }
    }

    class RealMigrationsHelper implements MigrationsHelper {
        @Override
        public LocalStore getLocalStore() {
            return LocalStore.this;
        }

        @Override
        public Storage getStorage() {
            return LocalStore.this.getStorage();
        }

        @Override
        public Account getAccount() {
            return LocalStore.this.getAccount();
        }

        @Override
        public Context getContext() {
            return LocalStore.this.getContext();
        }

        @Override
        public String serializeFlags(List<Flag> flags) {
            return LocalStore.serializeFlags(flags);
        }
    }
}
+1 −1
Original line number Diff line number Diff line
package com.fsck.k9.mailstore.migrations;
package com.fsck.k9.mailstore;


import java.util.List;
Loading