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

Commit c7fe777d authored by Vasu Nori's avatar Vasu Nori
Browse files

treat "can't open database file error" as "database corruption error"

bug:3083665
if sqlite can't open the database, delete it and create a new one.
what else is sqlite supposed to do?

Change-Id: I8b7c3b051fd1a146e4026f8f8acfdd099f9a70cf
parent cd7f5981
Loading
Loading
Loading
Loading
+10 −2
Original line number Diff line number Diff line
@@ -991,8 +991,10 @@ public class SQLiteDatabase extends SQLiteClosable {
            }
            return db;
        } catch (SQLiteDatabaseCorruptException e) {
            db.mErrorHandler.onCorruption(db);
            return SQLiteDatabase.openDatabase(path, factory, flags, errorHandler);
            return handleCorruptedDatabase(db, path, factory, flags, errorHandler);
        } catch (SQLiteCantOpenDatabaseException e) {
            Log.e(TAG, "database file can't be opened. possibly due to database corruption.");
            return handleCorruptedDatabase(db, path, factory, flags, errorHandler);
        } catch (SQLiteException e) {
            Log.e(TAG, "Failed to open the database. closing it.", e);
            db.close();
@@ -1000,6 +1002,12 @@ public class SQLiteDatabase extends SQLiteClosable {
        }
    }

    private static SQLiteDatabase handleCorruptedDatabase(SQLiteDatabase db, String path,
            CursorFactory factory, int flags, DatabaseErrorHandler errorHandler) {
        db.mErrorHandler.onCorruption(db);
        return SQLiteDatabase.openDatabase(path, factory, flags, errorHandler);
    }

    /**
     * Equivalent to openDatabase(file.getPath(), factory, CREATE_IF_NECESSARY).
     */