Merge "API Review update for SQLiteDatabase" into oc-mr1-dev

This commit is contained in:
Fyodor Kupolov
2017-08-08 16:46:24 +00:00
committed by Android (Google) Code Review
6 changed files with 23 additions and 14 deletions

View File

@@ -11909,7 +11909,7 @@ package android.database.sqlite {
method public boolean needUpgrade(int);
method protected void onAllReferencesReleased();
method public static android.database.sqlite.SQLiteDatabase openDatabase(java.lang.String, android.database.sqlite.SQLiteDatabase.CursorFactory, int);
method public static android.database.sqlite.SQLiteDatabase openDatabase(java.lang.String, android.database.sqlite.SQLiteDatabase.OpenParams);
method public static android.database.sqlite.SQLiteDatabase openDatabase(java.io.File, android.database.sqlite.SQLiteDatabase.OpenParams);
method public static android.database.sqlite.SQLiteDatabase openDatabase(java.lang.String, android.database.sqlite.SQLiteDatabase.CursorFactory, int, android.database.DatabaseErrorHandler);
method public static android.database.sqlite.SQLiteDatabase openOrCreateDatabase(java.io.File, android.database.sqlite.SQLiteDatabase.CursorFactory);
method public static android.database.sqlite.SQLiteDatabase openOrCreateDatabase(java.lang.String, android.database.sqlite.SQLiteDatabase.CursorFactory);

View File

@@ -12713,7 +12713,7 @@ package android.database.sqlite {
method public boolean needUpgrade(int);
method protected void onAllReferencesReleased();
method public static android.database.sqlite.SQLiteDatabase openDatabase(java.lang.String, android.database.sqlite.SQLiteDatabase.CursorFactory, int);
method public static android.database.sqlite.SQLiteDatabase openDatabase(java.lang.String, android.database.sqlite.SQLiteDatabase.OpenParams);
method public static android.database.sqlite.SQLiteDatabase openDatabase(java.io.File, android.database.sqlite.SQLiteDatabase.OpenParams);
method public static android.database.sqlite.SQLiteDatabase openDatabase(java.lang.String, android.database.sqlite.SQLiteDatabase.CursorFactory, int, android.database.DatabaseErrorHandler);
method public static android.database.sqlite.SQLiteDatabase openOrCreateDatabase(java.io.File, android.database.sqlite.SQLiteDatabase.CursorFactory);
method public static android.database.sqlite.SQLiteDatabase openOrCreateDatabase(java.lang.String, android.database.sqlite.SQLiteDatabase.CursorFactory);

View File

@@ -11953,7 +11953,7 @@ package android.database.sqlite {
method public boolean needUpgrade(int);
method protected void onAllReferencesReleased();
method public static android.database.sqlite.SQLiteDatabase openDatabase(java.lang.String, android.database.sqlite.SQLiteDatabase.CursorFactory, int);
method public static android.database.sqlite.SQLiteDatabase openDatabase(java.lang.String, android.database.sqlite.SQLiteDatabase.OpenParams);
method public static android.database.sqlite.SQLiteDatabase openDatabase(java.io.File, android.database.sqlite.SQLiteDatabase.OpenParams);
method public static android.database.sqlite.SQLiteDatabase openDatabase(java.lang.String, android.database.sqlite.SQLiteDatabase.CursorFactory, int, android.database.DatabaseErrorHandler);
method public static android.database.sqlite.SQLiteDatabase openOrCreateDatabase(java.io.File, android.database.sqlite.SQLiteDatabase.CursorFactory);
method public static android.database.sqlite.SQLiteDatabase openOrCreateDatabase(java.lang.String, android.database.sqlite.SQLiteDatabase.CursorFactory);

View File

@@ -703,12 +703,19 @@ public final class SQLiteDatabase extends SQLiteClosable {
/**
* Open the database according to the specified {@link OpenParams parameters}
*
* @param path to database file to open and/or create
* @param path path to database file to open and/or create.
* <p><strong>Important:</strong> The file should be constructed either from an absolute path or
* by using {@link android.content.Context#getDatabasePath(String)}.
* @param openParams configuration parameters that are used for opening {@link SQLiteDatabase}
* @return the newly opened database
* @throws SQLiteException if the database cannot be opened
*/
public static SQLiteDatabase openDatabase(@NonNull String path,
public static SQLiteDatabase openDatabase(@NonNull File path,
@NonNull OpenParams openParams) {
return openDatabase(path.getPath(), openParams);
}
private static SQLiteDatabase openDatabase(@NonNull String path,
@NonNull OpenParams openParams) {
Preconditions.checkArgument(openParams != null, "OpenParams cannot be null");
SQLiteDatabase db = new SQLiteDatabase(path, openParams.mOpenFlags,
@@ -873,7 +880,8 @@ public final class SQLiteDatabase extends SQLiteClosable {
*
* @param factory an optional factory class that is called to instantiate a
* cursor when query is called
* @return a SQLiteDatabase object, or null if the database can't be created
* @return a SQLiteDatabase instance
* @throws SQLiteException if the database cannot be created
*/
@NonNull
public static SQLiteDatabase create(@Nullable CursorFactory factory) {
@@ -889,7 +897,8 @@ public final class SQLiteDatabase extends SQLiteClosable {
* <p>Sets the locale of the database to the the system's current locale.
* Call {@link #setLocale} if you would like something else.</p>
* @param openParams configuration parameters that are used for opening SQLiteDatabase
* @return a SQLiteDatabase object, or null if the database can't be created
* @return a SQLiteDatabase instance
* @throws SQLException if the database cannot be created
*/
@NonNull
public static SQLiteDatabase createInMemory(@NonNull OpenParams openParams) {
@@ -2322,7 +2331,7 @@ public final class SQLiteDatabase extends SQLiteClosable {
}
/**
* Returns flags to control database access mode
* Returns flags to control database access mode. Default value is 0.
*
* @see Builder#setOpenFlags(int)
*/

View File

@@ -289,12 +289,12 @@ public abstract class SQLiteOpenHelper {
} else if (mName == null) {
db = SQLiteDatabase.createInMemory(mOpenParamsBuilder.build());
} else {
final String path = mContext.getDatabasePath(mName).getPath();
final File filePath = mContext.getDatabasePath(mName);
SQLiteDatabase.OpenParams params = mOpenParamsBuilder.build();
try {
db = SQLiteDatabase.openDatabase(path, params);
db = SQLiteDatabase.openDatabase(filePath, params);
// Keep pre-O-MR1 behavior by resetting file permissions to 660
setFilePermissionsForDb(path);
setFilePermissionsForDb(filePath.getPath());
} catch (SQLException ex) {
if (writable) {
throw ex;
@@ -302,7 +302,7 @@ public abstract class SQLiteOpenHelper {
Log.e(TAG, "Couldn't open " + mName
+ " for writing (will try read-only):", ex);
params = params.toBuilder().addOpenFlags(SQLiteDatabase.OPEN_READONLY).build();
db = SQLiteDatabase.openDatabase(path, params);
db = SQLiteDatabase.openDatabase(filePath, params);
}
}

View File

@@ -1058,7 +1058,7 @@ public class DatabaseGeneralTest extends AndroidTestCase implements PerformanceT
mDatabase.close();
SQLiteDatabase.OpenParams params = new SQLiteDatabase.OpenParams.Builder()
.setLookasideConfig(0, 0).build();
mDatabase = SQLiteDatabase.openDatabase(mDatabaseFile.getPath(), params);
mDatabase = SQLiteDatabase.openDatabase(mDatabaseFile, params);
verifyLookasideStats(true);
}
@@ -1193,7 +1193,7 @@ public class DatabaseGeneralTest extends AndroidTestCase implements PerformanceT
mDatabase.close();
SQLiteDatabase.OpenParams params = new SQLiteDatabase.OpenParams.Builder()
.setIdleConnectionTimeout(1000).build();
mDatabase = SQLiteDatabase.openDatabase(mDatabaseFile.getPath(), params);
mDatabase = SQLiteDatabase.openDatabase(mDatabaseFile, params);
// Wait a bit and check that connection is still open
Thread.sleep(100);
String output = executeShellCommand("dumpsys dbinfo " + getContext().getPackageName());