Skip to content

Commit d1e4d8b

Browse files
committed
Add possibility to use custom native library loader.
This allows to implement custom strategy for loading jni libraries. For example using ReLinker.
1 parent ab39c2d commit d1e4d8b

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

src/net/sqlcipher/database/SQLiteDatabase.java

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,14 +165,41 @@ private static void loadICUData(Context context, File workingDir) {
165165
}
166166
}
167167

168+
/**
169+
* Implement this interface to provide custom strategy for loading jni libraries.
170+
*/
171+
public interface LibraryLoader {
172+
/**
173+
* Load jni libraries by given names.
174+
* Straightforward implementation will be calling {@link System#loadLibrary(String name)}
175+
* for every provided library name.
176+
*
177+
* @param libNames library names that sqlcipher need to load
178+
*/
179+
void loadLibraries(String... libNames);
180+
}
181+
168182
public static synchronized void loadLibs (Context context) {
169183
loadLibs(context, context.getFilesDir());
170184
}
171185

172186
public static synchronized void loadLibs (Context context, File workingDir) {
173-
System.loadLibrary("stlport_shared");
174-
System.loadLibrary("sqlcipher_android");
175-
System.loadLibrary("database_sqlcipher");
187+
loadLibs(context, workingDir, new LibraryLoader() {
188+
@Override
189+
public void loadLibraries(String... libNames) {
190+
for (String libName : libNames) {
191+
System.loadLibrary(libName);
192+
}
193+
}
194+
});
195+
}
196+
197+
public static synchronized void loadLibs(Context context, LibraryLoader libraryLoader) {
198+
loadLibs(context, context.getFilesDir(), libraryLoader);
199+
}
200+
201+
public static synchronized void loadLibs (Context context, File workingDir, LibraryLoader libraryLoader) {
202+
libraryLoader.loadLibraries("stlport_shared", "sqlcipher_android", "database_sqlcipher");
176203

177204
boolean systemICUFileExists = new File("/system/usr/icu/icudt46l.dat").exists();
178205

0 commit comments

Comments
 (0)