Skip to content

Commit 8944f29

Browse files
committed
support full hooks in addition to simple postKey SQL
1 parent a6dbea0 commit 8944f29

File tree

2 files changed

+22
-20
lines changed

2 files changed

+22
-20
lines changed

android-database-sqlcipher/src/main/java/net/sqlcipher/database/SupportFactory.java

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,35 @@
2020

2121
public class SupportFactory implements SupportSQLiteOpenHelper.Factory {
2222
private final byte[] passphrase;
23-
private final String postKeySql;
23+
private final SQLiteDatabaseHook hook;
2424

2525
public SupportFactory(byte[] passphrase) {
26-
this(passphrase, null);
26+
this(passphrase, (SQLiteDatabaseHook)null);
2727
}
2828

29-
public SupportFactory(byte[] passphrase, String postKeySql) {
29+
public SupportFactory(byte[] passphrase, final String postKeySql) {
30+
this(passphrase, new SQLiteDatabaseHook() {
31+
@Override
32+
public void preKey(SQLiteDatabase database) {
33+
// unused
34+
}
35+
36+
@Override
37+
public void postKey(SQLiteDatabase database) {
38+
if (postKeySql != null) {
39+
database.rawExecSQL(postKeySql);
40+
}
41+
}
42+
});
43+
}
44+
45+
public SupportFactory(byte[] passphrase, SQLiteDatabaseHook hook) {
3046
this.passphrase = passphrase;
31-
this.postKeySql = postKeySql;
47+
this.hook = hook;
3248
}
3349

3450
@Override
3551
public SupportSQLiteOpenHelper create(SupportSQLiteOpenHelper.Configuration configuration) {
36-
return new SupportHelper(configuration, passphrase, postKeySql);
52+
return new SupportHelper(configuration, passphrase, hook);
3753
}
3854
}

android-database-sqlcipher/src/main/java/net/sqlcipher/database/SupportHelper.java

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,10 @@ public class SupportHelper implements SupportSQLiteOpenHelper {
2424
private byte[] passphrase;
2525

2626
SupportHelper(final SupportSQLiteOpenHelper.Configuration configuration,
27-
byte[] passphrase, final String postKeySql) {
27+
byte[] passphrase, final SQLiteDatabaseHook hook) {
2828
SQLiteDatabase.loadLibs(configuration.context);
2929
this.passphrase = passphrase;
3030

31-
SQLiteDatabaseHook hook = new SQLiteDatabaseHook() {
32-
@Override
33-
public void preKey(SQLiteDatabase database) {
34-
// unused
35-
}
36-
37-
@Override
38-
public void postKey(SQLiteDatabase database) {
39-
if (postKeySql != null) {
40-
database.rawExecSQL(postKeySql);
41-
}
42-
}
43-
};
44-
4531
standardHelper =
4632
new SQLiteOpenHelper(configuration.context, configuration.name,
4733
null, configuration.callback.version, hook) {

0 commit comments

Comments
 (0)