|
1 | 1 | #include <jni.h> |
2 | | -#include <dlfcn.h> |
3 | | -#include <android/log.h> |
4 | | - |
5 | | -#define LOG_TAG "PowerSyncNative" |
6 | | - |
7 | | -// Forward declarations (no need for full struct definitions) |
8 | | -typedef struct sqlite3 sqlite3; |
9 | | -typedef struct sqlite3_api_routines sqlite3_api_routines; |
10 | | - |
11 | | -typedef int (*sqlite3_auto_extension_fn)(void (*xEntryPoint)(void)); |
12 | | - |
13 | | -extern int sqlite3_powersync_init( |
14 | | - sqlite3 *db, // Database handle |
15 | | - const char **pzErrMsg, // Error message out parameter |
16 | | - const struct sqlite3_api_routines *pThunk // SQLite API routines |
17 | | -); |
18 | 2 |
|
| 3 | +// SQLCipher enables dynamic loading of extensions. We don't need to do anything here. |
19 | 4 | int register_powersync(void) { |
20 | | - void *handle = dlopen("libsqlcipher.so", RTLD_LAZY); |
21 | | - if (!handle) { |
22 | | - __android_log_print(ANDROID_LOG_WARN, LOG_TAG, "Failed to dlopen libsqlcipher.so, trying process handle"); |
23 | | - // Try loading from the process itself |
24 | | - handle = dlopen(NULL, RTLD_LAZY); |
25 | | - if (!handle) { |
26 | | - __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "Failed to dlopen process handle. SQLCipher symbols not found."); |
27 | | - return -1; |
28 | | - } |
29 | | - } else { |
30 | | - __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, "Successfully loaded libsqlcipher.so"); |
31 | | - } |
32 | | - |
33 | | - __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, "Resolving sqlite3_auto_extension symbol"); |
34 | | - sqlite3_auto_extension_fn auto_ext = (sqlite3_auto_extension_fn)dlsym(handle, "sqlite3_auto_extension"); |
35 | | - if (!auto_ext) { |
36 | | - __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "Failed to resolve sqlite3_auto_extension symbol"); |
37 | | - } |
38 | | - |
39 | | - |
40 | | - if (!auto_ext) { |
41 | | - __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "Required symbols not found. Aborting registration."); |
42 | | - dlclose(handle); |
43 | | - return -2; |
44 | | - } |
45 | | - |
46 | | - __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, "Registering powersync extension"); |
47 | | - int result = auto_ext((void(*)(void))sqlite3_powersync_init); |
48 | | - __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, "register_powersync result: %d", result); |
49 | | - dlclose(handle); |
50 | | - __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, "Completed register_powersync"); |
51 | | - return result; |
| 5 | + return 0; |
52 | 6 | } |
53 | 7 |
|
54 | 8 | // JNI wrapper |
|
0 commit comments