Page MenuHomePhabricator

D6416.diff
No OneTemporary

D6416.diff

diff --git a/native/android/app/src/cpp/CommSecureStore.cpp b/native/android/app/src/cpp/CommSecureStore.cpp
--- a/native/android/app/src/cpp/CommSecureStore.cpp
+++ b/native/android/app/src/cpp/CommSecureStore.cpp
@@ -1,3 +1,4 @@
+#include "jniHelpers.h"
#include <Tools/CommSecureStore.h>
#include <fbjni/fbjni.h>
@@ -29,7 +30,8 @@
void CommSecureStore::set(const std::string key, const std::string value)
const {
- CommSecureStoreJavaClass::set(key, value);
+ NativeAndroidAccessProvider::runTask(
+ [=]() { CommSecureStoreJavaClass::set(key, value); });
}
folly::Optional<std::string> CommSecureStore::get(const std::string key) const {
diff --git a/native/android/app/src/cpp/PlatformSpecificTools.cpp b/native/android/app/src/cpp/PlatformSpecificTools.cpp
--- a/native/android/app/src/cpp/PlatformSpecificTools.cpp
+++ b/native/android/app/src/cpp/PlatformSpecificTools.cpp
@@ -1,3 +1,4 @@
+#include "jniHelpers.h"
#include <Tools/Logger.h>
#include <Tools/PlatformSpecificTools.h>
#include <fbjni/fbjni.h>
@@ -30,7 +31,9 @@
void PlatformSpecificTools::generateSecureRandomBytes(
crypto::OlmBuffer &buffer,
size_t size) {
- buffer = PlatformSpecificToolsJavaClass::generateSecureRandomBytes(size);
+ NativeAndroidAccessProvider::runTask([&buffer, size]() {
+ buffer = PlatformSpecificToolsJavaClass::generateSecureRandomBytes(size);
+ });
}
std::string PlatformSpecificTools::getDeviceOS() {
diff --git a/native/android/app/src/cpp/jniHelpers.h b/native/android/app/src/cpp/jniHelpers.h
--- a/native/android/app/src/cpp/jniHelpers.h
+++ b/native/android/app/src/cpp/jniHelpers.h
@@ -28,4 +28,14 @@
}
};
+struct NativeAndroidAccessProvider {
+ static void runTask(std::function<void()> &&task) {
+ // Some methods 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.
+ jni::ThreadScope::WithClassLoader(std::move(task));
+ }
+};
+
} // namespace comm
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
@@ -8,10 +8,6 @@
#include <iostream>
#include <thread>
-#ifdef __ANDROID__
-#include <fbjni/fbjni.h>
-#endif
-
#define ACCOUNT_ID 1
namespace comm {
@@ -501,19 +497,6 @@
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";
@@ -1113,10 +1096,7 @@
<< strerror(errno);
throw std::system_error(errno, std::generic_category(), errorStream.str());
}
- auto native_dependent_task = []() {
- SQLiteQueryExecutor::assign_encryption_key();
- };
- run_with_native_accessible(native_dependent_task);
+ SQLiteQueryExecutor::assign_encryption_key();
SQLiteQueryExecutor::migrate();
}

File Metadata

Mime Type
text/plain
Expires
Fri, Dec 20, 4:07 PM (16 h, 40 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2678754
Default Alt Text
D6416.diff (3 KB)

Event Timeline