diff --git a/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.cpp b/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.cpp --- a/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.cpp +++ b/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.cpp @@ -17,6 +17,10 @@ #include #include +#ifdef __ANDROID__ +#include +#endif + #define ACCOUNT_ID 1 namespace comm { @@ -337,6 +341,19 @@ return !err_msg; } +void run_with_native_accessible(std::function &&task) { + // Some methods of SQLiteQueryExecutor are meant to be executed on + // auxiliary threads. In case they require access to native Java + // API we need to temporarily attach the thread to JVM + // This function attaches thread to JVM for the time + // lambda passed to this function will be executing. +#ifdef __ANDROID__ + facebook::jni::ThreadScope::WithClassLoader(std::move(task)); +#else + task(); +#endif +} + void validate_encryption() { std::string temp_encrypted_db_path = SQLiteQueryExecutor::sqliteFilePath + "_temp_encrypted";