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

Commit 72157842 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Better handling of DB corruption in SQLiteDatabase.open()"

parents 6f55e56e 7a8261dc
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;
    }
}