Page MenuHomePhabricator

D4957.id15998.diff
No OneTemporary

D4957.id15998.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 {
@@ -340,6 +344,19 @@
return true;
}
+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:28 AM (11 h, 11 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2702065
Default Alt Text
D4957.id15998.diff (1 KB)

Event Timeline