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

Commit 8fcffb3b authored by Ugo Yu's avatar Ugo Yu
Browse files

Fix endless crash when load Bluetooth database

Wipe the Bluetooth database if we are unable to load it.
It could happen when database corruption or user downgrades
their device without clear userdata.

Bug: 129111365
Test: runtest bluetooth
Change-Id: Icd7008886aaa39637dc57123a8553b90047ade6c
parent 39aec906
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -89,7 +89,15 @@ public class DatabaseManager {
            switch (msg.what) {
                case MSG_LOAD_DATABASE: {
                    synchronized (mDatabase) {
                        List<Metadata> list = mDatabase.load();
                        List<Metadata> list;
                        try {
                            list = mDatabase.load();
                        } catch (IllegalStateException e) {
                            Log.e(TAG, "Unable to open database: " + e);
                            mDatabase = MetadataDatabase
                                    .createDatabaseWithoutMigration(mAdapterService);
                            list = mDatabase.load();
                        }
                        cacheMetadata(list);
                    }
                    break;
+15 −1
Original line number Diff line number Diff line
@@ -39,7 +39,7 @@ public abstract class MetadataDatabase extends RoomDatabase {
    protected abstract MetadataDao mMetadataDao();

    /**
     * Create a {@link MetadataDatabase} database
     * Create a {@link MetadataDatabase} database with migrations
     *
     * @param context the Context to create database
     * @return the created {@link MetadataDatabase}
@@ -51,6 +51,20 @@ public abstract class MetadataDatabase extends RoomDatabase {
                .build();
    }

    /**
     * Create a {@link MetadataDatabase} database without migration, database
     * would be reset if any load failure happens
     *
     * @param context the Context to create database
     * @return the created {@link MetadataDatabase}
     */
    public static MetadataDatabase createDatabaseWithoutMigration(Context context) {
        return Room.databaseBuilder(context,
                MetadataDatabase.class, DATABASE_NAME)
                .fallbackToDestructiveMigration()
                .build();
    }

    /**
     * Insert a {@link Metadata} to database
     *