diff --git a/core/java/android/database/sqlite/SQLiteDatabase.java b/core/java/android/database/sqlite/SQLiteDatabase.java index e34e7768ca49a..886951b6ffe71 100644 --- a/core/java/android/database/sqlite/SQLiteDatabase.java +++ b/core/java/android/database/sqlite/SQLiteDatabase.java @@ -25,6 +25,7 @@ import android.database.DefaultDatabaseErrorHandler; import android.database.SQLException; import android.database.sqlite.SQLiteDebug.DbStats; import android.os.Debug; +import android.os.StatFs; import android.os.SystemClock; import android.os.SystemProperties; import android.text.TextUtils; @@ -236,6 +237,12 @@ public class SQLiteDatabase extends SQLiteClosable { /** Used to make temp table names unique */ /* package */ int mTempTableSequence = 0; + /** + * The size, in bytes, of a block on "/data". This corresponds to the Unix + * statfs.f_bsize field. note that this field is lazily initialized. + */ + private static int sBlockSize = 0; + /** The path for the database file */ private String mPath; @@ -858,6 +865,15 @@ public class SQLiteDatabase extends SQLiteClosable { errorHandler.onCorruption(sqliteDatabase); sqliteDatabase = new SQLiteDatabase(path, factory, flags); } + + // set sqlite pagesize to mBlockSize + if (sBlockSize == 0) { + // TODO: "/data" should be a static final String constant somewhere. it is hardcoded + // in several places right now. + sBlockSize = new StatFs("/data").getBlockSize(); + } + sqliteDatabase.setPageSize(sBlockSize); + ActiveDatabases.getInstance().mActiveDatabases.add( new WeakReference(sqliteDatabase)); return sqliteDatabase;