8000 Merge branch 'Tapchicoma-improve_jni_loading' · dw3/android-database-sqlcipher@286f9bb · GitHub
[go: up one dir, main page]

Skip to content

Commit 286f9bb

Browse files
Merge branch 'Tapchicoma-improve_jni_loading'
2 parents b621bae + 744bd1f commit 286f9bb

File tree

1 file changed

+43
-8
lines changed

1 file changed

+43
-8
lines changed

src/net/sqlcipher/database/SQLiteDatabase.java

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -181,19 +181,54 @@ private static void loadICUData(Context context, File workingDir) {
181181
}
182182
}
183183

184-
/**
185-
* Loads the native SQLCipher library into the application process.
186-
*/
184+
/**
185+
* Implement this interface to provide custom strategy for loading jni libraries.
186+
*/
187+
public interface LibraryLoader {
188+
/**
189+
* Load jni libraries by given names.
190+
* Straightforward implementation will be calling {@link System#loadLibrary(String name)}
191+
* for every provided library name.
192+
*
193+
* @param libNames library names that sqlcipher need to load
194+
*/
195+
void loadLibraries(String... libNames);
196+
}
197+
198+
/**
199+
* Loads the native SQLCipher library into the application process.
200+
*/
187201
public static synchronized void loadLibs (Context context) {
188202
loadLibs(context, context.getFilesDir());
189203
}
190204

191-
/**
192-
* Loads the native SQLCipher library into the application process.
193-
*/
205+
/**
206+
* Loads the native SQLCipher library into the application process.
207+
*/
194208
public static synchronized void loadLibs (Context context, File workingDir) {
195-
System.loadLibrary("sqlcipher");
196-
209+
loadLibs(context, workingDir, new LibraryLoader() {
210+
@Override
211+
public void loadLibraries(String... libNames) {
212+
for (String libName : libNames) {
213+
System.loadLibrary(libName);
214+
}
215+
}
216+
});
217+
}
218+
219+
/**
220+
* Loads the native SQLCipher library into the application process.
221+
*/
222+
public static synchronized void loadLibs(Context context, LibraryLoader libraryLoader) {
223+
loadLibs(context, context.getFilesDir(), libraryLoader);
224+
}
225+
226+
/**
227+
* Loads the native SQLCipher library into the application process.
228+
*/
229+
public static synchronized void loadLibs (Context context, File workingDir, LibraryLoader libraryLoader) {
230+
libraryLoader.loadLibraries("sqlcipher");
231+
197232
// System.loadLibrary("stlport_shared");
198233
// System.loadLibrary("sqlcipher_android");
199234
// System.loadLibrary("database_sqlcipher");

0 commit comments

Comments
 (0)
0