Page MenuHomePhabricator

D4957.id16306.diff
No OneTemporary

D4957.id16306.diff

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 <system_error>
#include <thread>
+#ifdef __ANDROID__
+#include <fbjni/fbjni.h>
+#endif
+
#define ACCOUNT_ID 1
namespace comm {
@@ -337,6 +341,19 @@
return !err_msg;
}
+void run_with_native_accessible(std::function<void()> &&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";

File Metadata

Mime Type
text/plain
Expires
Wed, Dec 25, 8:38 AM (10 h, 34 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2702093
Default Alt Text
D4957.id16306.diff (1 KB)

Event Timeline