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

Commit 7a8261dc authored by Makoto Onuki's avatar Makoto Onuki
Browse files

Better handling of DB corruption in SQLiteDatabase.open()

Bug: 123750718
Test: manual test with test code
Change-Id: I80a9d35f7ad6589b3de0a506780cfe956295dcda
parent 6f6ab378
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -448,6 +448,8 @@ public final class SQLiteConnection implements CancellationSignal.OnCancelListen
            } finally {
                execute(success ? "COMMIT" : "ROLLBACK", null, null);
            }
        } catch (SQLiteException ex) {
            throw ex;
        } catch (RuntimeException ex) {
            throw new SQLiteException("Failed to change locale for db '" + mConfiguration.label
                    + "' to '" + newLocale + "'.", ex);
+8 −3
Original line number Diff line number Diff line
@@ -890,9 +890,14 @@ public final class SQLiteDatabase extends SQLiteClosable {
        try {
            try {
                openInner();
            } catch (SQLiteDatabaseCorruptException ex) {
            } catch (RuntimeException ex) {
                if (SQLiteDatabaseCorruptException.isCorruptException(ex)) {
                    Log.e(TAG, "Database corruption detected in open()", ex);
                    onCorruption();
                    openInner();
                } else {
                    throw ex;
                }
            }
        } catch (SQLiteException ex) {
            Log.e(TAG, "Failed to open database '" + getLabel() + "'.", ex);
+16 −0
Original line number Diff line number Diff line
@@ -25,4 +25,20 @@ public class SQLiteDatabaseCorruptException extends SQLiteException {
    public SQLiteDatabaseCorruptException(String error) {
        super(error);
    }

    /**
     * @return true if a given {@link Throwable} or any of its inner causes is of
     * {@link SQLiteDatabaseCorruptException}.
     *
     * @hide
     */
    public static boolean isCorruptException(Throwable th) {
        while (th != null) {
            if (th instanceof SQLiteDatabaseCorruptException) {
                return true;
            }
            th = th.getCause();
        }
        return false;
    }
}