I changed my DatabaseHelper class to use the SQLCipher library.
For this I:
I copied the assets to my resources folder and libraries (armeabi, x86, commons-codec, guava-r09, sqlcipher) into my libs folder.
Changed the import in my class DatabaseHelperto point to import net.sqlcipher.database.*.
Call SQLiteDatabase.loadLibs(getApplicationContext());when the application starts.
Changed the lines in which I call getReadableDatabase()and getWriteableDatabase()to include the passphrase as a parameter;
Everything works fine, as the data is read / written correctly. My performance problem is because my application can perform database operations at a certain frequency, causing it to become slow (after switching to SQLCipher).
For my DatabaseHelper methods, I believe that I follow standard approaches, for example:
public List<MyObject> getMyObjects() {
List<MyObject> objects = new ArrayList<MyObject>();
String selectQuery = "SELECT * FROM " + TABLE_NAME;
Log.v(LOG, selectQuery);
SQLiteDatabase db = this.getReadableDatabase("...the password...");
Cursor c = db.rawQuery(selectQuery, null);
if (c.moveToFirst()) {
do {
MyObject object = createMyObjectFromCursor(c);
objects.add(object);
} while (c.moveToNext());
}
c.close();
db.close();
return objects;
}
I am not completely familiar with the internal mechanics of SQLCipher (for example, does it decrypt the entire DB file when called getReadableDatabase()?), But when debugging it seems that the overhead is in getReadableDatabase(password)and getWritableDatabase(password)that makes sense if my assumption above is true.
Would moving these calls to the DatabaseHelper.open () and DatabaseHelper.close () methods, which would be called by the actions whenever they instantiate the DatabaseHelper instead of calling them by each individual method, be bad practice? Share your knowledge on how to solve this problem.
EDIT:
DDMS , , SQLiteOpenHelper.getReadableDatabase() ( ~ 4 ). , , , , .
, , :
SQLiteDatabase.OpenOrCreateDatabase → SqLiteDatabase.openDatabase → SqLiteDatabase.openDatabase → SQLiteDatabase.setLocale
, SQLiteDatabase.setLocale(java.util.Locale) , ~ 4 , getReadableDatabase(). SQLiteDatabase, , native_setLocale(locale.toString(), mFlags) (4 . ) .
, ?