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

Commit 33fd6b59 authored by Fyodor Kupolov's avatar Fyodor Kupolov Committed by Android (Google) Code Review
Browse files

Merge "Added SQLiteOpenHelper.setOpenParams"

parents 4c7dd5ea ab05b143
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -12555,6 +12555,7 @@ package android.database.sqlite {
    method public abstract void onUpgrade(android.database.sqlite.SQLiteDatabase, int, int);
    method public void setIdleConnectionTimeout(long);
    method public void setLookasideConfig(int, int);
    method public void setOpenParams(android.database.sqlite.SQLiteDatabase.OpenParams);
    method public void setWriteAheadLoggingEnabled(boolean);
  }
+26 −3
Original line number Diff line number Diff line
@@ -58,7 +58,7 @@ public abstract class SQLiteOpenHelper {

    private SQLiteDatabase mDatabase;
    private boolean mIsInitializing;
    private final SQLiteDatabase.OpenParams.Builder mOpenParamsBuilder;
    private SQLiteDatabase.OpenParams.Builder mOpenParamsBuilder;

    /**
     * Create a helper object to create, open, and/or manage a database.
@@ -163,8 +163,7 @@ public abstract class SQLiteOpenHelper {
        mName = name;
        mNewVersion = version;
        mMinimumSupportedVersion = Math.max(0, minimumSupportedVersion);
        mOpenParamsBuilder = openParamsBuilder;
        mOpenParamsBuilder.addOpenFlags(SQLiteDatabase.CREATE_IF_NECESSARY);
        setOpenParamsBuilder(openParamsBuilder);
    }

    /**
@@ -229,6 +228,30 @@ public abstract class SQLiteOpenHelper {
        }
    }

    /**
     * Sets configuration parameters that are used for opening {@link SQLiteDatabase}.
     * <p>Please note that {@link SQLiteDatabase#CREATE_IF_NECESSARY} flag will always be set when
     * opening the database
     *
     * @param openParams configuration parameters that are used for opening {@link SQLiteDatabase}.
     * @throws IllegalStateException if the database is already open
     */
    public void setOpenParams(@NonNull SQLiteDatabase.OpenParams openParams) {
        Preconditions.checkNotNull(openParams);
        synchronized (this) {
            if (mDatabase != null && mDatabase.isOpen()) {
                throw new IllegalStateException(
                        "OpenParams cannot be set after opening the database");
            }
            setOpenParamsBuilder(new SQLiteDatabase.OpenParams.Builder(openParams));
        }
    }

    private void setOpenParamsBuilder(SQLiteDatabase.OpenParams.Builder openParamsBuilder) {
        mOpenParamsBuilder = openParamsBuilder;
        mOpenParamsBuilder.addOpenFlags(SQLiteDatabase.CREATE_IF_NECESSARY);
    }

    /**
     * Sets the maximum number of milliseconds that SQLite connection is allowed to be idle
     * before it is closed and removed from the pool.