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

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

Merge "Enhance exception message on SQLiteCantOpenDatabaseException" into rvc-dev

parents 1775d16a a868d701
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -22,4 +22,9 @@ public class SQLiteCantOpenDatabaseException extends SQLiteException {
    public SQLiteCantOpenDatabaseException(String error) {
        super(error);
    }

    /** @hide */
    public SQLiteCantOpenDatabaseException(String error, Throwable cause) {
        super(error, cause);
    }
}
+23 −1
Original line number Diff line number Diff line
@@ -36,6 +36,9 @@ import dalvik.system.CloseGuard;

import java.io.File;
import java.io.IOException;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
@@ -215,12 +218,31 @@ public final class SQLiteConnection implements CancellationSignal.OnCancelListen
    }

    private void open() {
        final String file = mConfiguration.path;
        final int cookie = mRecentOperations.beginOperation("open", null, null);
        try {
            mConnectionPtr = nativeOpen(mConfiguration.path, mConfiguration.openFlags,
            mConnectionPtr = nativeOpen(file, mConfiguration.openFlags,
                    mConfiguration.label,
                    NoPreloadHolder.DEBUG_SQL_STATEMENTS, NoPreloadHolder.DEBUG_SQL_TIME,
                    mConfiguration.lookasideSlotSize, mConfiguration.lookasideSlotCount);
        } catch (SQLiteCantOpenDatabaseException e) {
            String message = String.format("Cannot open database '%s'", file);

            final Path path = FileSystems.getDefault().getPath(file);
            final Path dir = path.getParent();

            if (!Files.isDirectory(dir)) {
                message += ": Directory " + dir + " doesn't exist";
            } else if (!Files.exists(path)) {
                message += ": File " + path + " doesn't exist";
            } else if (!Files.isReadable(path)) {
                message += ": File " + path + " is not readable";
            } else if (Files.isDirectory(path)) {
                message += ": Path " + path + " is a directory";
            } else {
                message += ": Unknown reason";
            }
            throw new SQLiteCantOpenDatabaseException(message, e);
        } finally {
            mRecentOperations.endOperation(cookie);
        }