Upgrade SQLCipher to respect a max window size.

Previously, SQLCipher's memory usage would grow indefinitely, up until
it hit the end of the cursor. We've now switched to a release where the
memory  used by the cursor can be bounded.
This commit is contained in:
Greyson Parrelli
2018-06-11 23:02:40 -07:00
parent eed2c6ec4c
commit dace93abb3
2 changed files with 13 additions and 2 deletions

View File

@@ -8,6 +8,9 @@ import android.os.SystemClock;
import android.support.annotation.NonNull;
import android.util.Log;
import net.sqlcipher.CursorWindow;
import net.sqlcipher.CursorWindowAllocation;
import net.sqlcipher.CustomCursorWindowAllocation;
import net.sqlcipher.database.SQLiteDatabase;
import net.sqlcipher.database.SQLiteDatabaseHook;
import net.sqlcipher.database.SQLiteOpenHelper;
@@ -52,6 +55,14 @@ public class SQLCipherOpenHelper extends SQLiteOpenHelper {
private static final int DATABASE_VERSION = 9;
private static final String DATABASE_NAME = "signal.db";
private static final int MEMORY_INITIAL = 128 * 1024;
private static final int MEMORY_GROW = 1024 * 1024;
private static final int MEMORY_MAX = 4 * 1024 * 1024;
private static final CursorWindowAllocation CURSOR_ALLOCATION = new CustomCursorWindowAllocation(MEMORY_INITIAL, MEMORY_GROW, MEMORY_MAX);
static {
CursorWindow.setCursorWindowAllocation(CURSOR_ALLOCATION);
}
private final Context context;
private final DatabaseSecret databaseSecret;