Skip to content

Commit

Permalink
Separate SQLiteGlobal.loadLib() and SQLiteGlobal.initialize() to allo…
Browse files Browse the repository at this point in the history
…w sqlite3_config(...) to be injected.
  • Loading branch information
John-He-928 committed Dec 4, 2020
1 parent 4cbbeca commit a4d1ab4
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 12 deletions.
6 changes: 3 additions & 3 deletions android/jni/com_tencent_wcdb_database_SQLiteGlobal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,9 @@ static jint nativeReleaseMemory(JNIEnv *env, jclass clazz)
return sqlite3_release_memory(SOFT_HEAP_LIMIT);
}

static void nativeSetDefaultCipherSettings(JNIEnv *env, jclass clazz, jint pageSize)
static void nativeInitialize(JNIEnv *env, jclass clazz, jint pageSize)
{
sqliteInitialize();
sqlcipher_set_default_pagesize(pageSize);

// Keep compatibility to WCDB version 1.0, mainly the same as SQLCipher 3.
Expand All @@ -162,14 +163,13 @@ static void nativeSetDefaultCipherSettings(JNIEnv *env, jclass clazz, jint pageS

static JNINativeMethod sMethods[] = {
/* name, signature, funcPtr */
{"nativeInitialize", "(I)V", (void *) nativeInitialize},
{"nativeReleaseMemory", "()I", (void *) nativeReleaseMemory},
{"nativeSetDefaultCipherSettings", "(I)V", (void *) nativeSetDefaultCipherSettings},
};

static int register_wcdb_SQLiteGlobal(JavaVM *vm, JNIEnv *env)
{
gVM = vm;
sqliteInitialize();

jclass clazz;
FIND_CLASS(clazz, "com/tencent/wcdb/database/WCDBInitializationProbe");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class WCDBConcurrentTest extends ConcurrentTest {
@Override
@Before
public void doBefore() {
SQLiteGlobal.loadLib();
SQLiteGlobal.initialize();
super.doBefore();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class WCDBSingleThreadedTest extends SingleThreadedTest {
@Override
@Before
public void doBefore() {
SQLiteGlobal.loadLib();
SQLiteGlobal.initialize();
super.doBefore();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public final class SQLiteDatabase extends SQLiteClosable {

static {
// Ensure libwcdb.so is loaded.
SQLiteGlobal.loadLib();
SQLiteGlobal.initialize();
}

// Stores reference to all databases opened in the current process.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public final class SQLiteDebug {

static {
// Ensure libwcdb.so is loaded.
SQLiteGlobal.loadLib();
SQLiteGlobal.initialize();
}

private SQLiteDebug() {}
Expand Down
7 changes: 4 additions & 3 deletions android/wcdb/src/com/tencent/wcdb/database/SQLiteGlobal.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
public final class SQLiteGlobal {
private static final String TAG = "WCDB.SQLiteGlobal";

private static native void nativeInitialize(int pageSize);
private static native int nativeReleaseMemory();
private static native void nativeSetDefaultCipherSettings(int pageSize);

/** Default page size to use when creating a database. */
public static final int defaultPageSize;
Expand Down Expand Up @@ -74,11 +74,13 @@ public final class SQLiteGlobal {
pageSize = 4096;
}
defaultPageSize = pageSize;
nativeSetDefaultCipherSettings(pageSize);
}
// Dummy static method to trigger class initialization.
// See [JLS 12.4.1](http://docs.oracle.com/javase/specs/jls/se7/html/jls-12.html#jls-12.4.1)
public static void loadLib() {}
public static void initialize() {
nativeInitialize(defaultPageSize);
}

private SQLiteGlobal() {}

Expand All @@ -91,7 +93,6 @@ private SQLiteGlobal() {}
public static int releaseMemory() {
return nativeReleaseMemory();
}

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public abstract class SQLiteOpenHelper {

static {
// Ensure libwcdb.so is loaded.
SQLiteGlobal.loadLib();
SQLiteGlobal.initialize();
}

// When true, getReadableDatabase returns a read-only database if it is just being opened.
Expand Down
2 changes: 1 addition & 1 deletion android/wcdb/src/com/tencent/wcdb/support/Context.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public final class Context {

static {
// Ensure libwcdb.so is loaded.
SQLiteGlobal.loadLib();
SQLiteGlobal.initialize();
}

private static File getDataDirFile(android.content.Context context) {
Expand Down

0 comments on commit a4d1ab4

Please sign in to comment.