Page MenuHomePhabricator

D5236.id17413.diff
No OneTemporary

D5236.id17413.diff

diff --git a/native/android/app/src/cpp/GlobalDBSingleton.cpp b/native/android/app/src/cpp/GlobalDBSingleton.cpp
--- a/native/android/app/src/cpp/GlobalDBSingleton.cpp
+++ b/native/android/app/src/cpp/GlobalDBSingleton.cpp
@@ -1,4 +1,5 @@
#include <InternalModules/GlobalDBSingleton.h>
+#include <InternalModules/GlobalDBSingletonJNIHelper.h>
namespace comm {
GlobalDBSingleton GlobalDBSingleton::instance;
@@ -15,4 +16,33 @@
void GlobalDBSingleton::enableMultithreading() {
this->enableMultithreadingCommonImpl();
}
+
+void GlobalDBSingletonJNIHelper::scheduleOrRun(
+ facebook::jni::alias_ref<GlobalDBSingletonJNIHelper> jThis,
+ facebook::jni::alias_ref<Runnable> task) {
+ auto globalTaskRef = facebook::jni::make_global(task);
+ GlobalDBSingleton::instance.scheduleOrRun(
+ [globalTaskRef = std::move(globalTaskRef)]() mutable {
+ auto runTask = [globalTaskRef = std::move(globalTaskRef)]() mutable {
+ globalTaskRef->run();
+ globalTaskRef.release();
+ };
+ facebook::jni::ThreadScope::WithClassLoader(std::move(runTask));
+ });
+}
+
+void GlobalDBSingletonJNIHelper::enableMultithreading(
+ facebook::jni::alias_ref<GlobalDBSingletonJNIHelper> jThis) {
+ GlobalDBSingleton::instance.enableMultithreading();
+}
+
+void GlobalDBSingletonJNIHelper::registerNatives() {
+ javaClassStatic()->registerNatives({
+ makeNativeMethod(
+ "scheduleOrRun", GlobalDBSingletonJNIHelper::scheduleOrRun),
+ makeNativeMethod(
+ "enableMultithreading",
+ GlobalDBSingletonJNIHelper::enableMultithreading),
+ });
+}
} // namespace comm
diff --git a/native/android/app/src/cpp/jsiInstaller.cpp b/native/android/app/src/cpp/jsiInstaller.cpp
--- a/native/android/app/src/cpp/jsiInstaller.cpp
+++ b/native/android/app/src/cpp/jsiInstaller.cpp
@@ -4,6 +4,7 @@
#include <jsi/jsi.h>
#include <DatabaseManagers/SQLiteQueryExecutor.h>
+#include <InternalModules/GlobalDBSingletonJNIHelper.h>
#include <InternalModules/GlobalNetworkSingletonJNIHelper.h>
#include <NativeModules/CommCoreModule.h>
#include <PersistentStorageUtilities/MessageOperationsUtilities/MessageOperationsUtilitiesJNIHelper.h>
@@ -57,5 +58,6 @@
comm::GlobalNetworkSingletonJNIHelper::registerNatives();
comm::ThreadOperationsJNIHelper::registerNatives();
comm::MessageOperationsUtilitiesJNIHelper::registerNatives();
+ comm::GlobalDBSingletonJNIHelper::registerNatives();
});
}
diff --git a/native/android/app/src/main/java/app/comm/android/fbjni/GlobalDBSingleton.java b/native/android/app/src/main/java/app/comm/android/fbjni/GlobalDBSingleton.java
new file mode 100644
--- /dev/null
+++ b/native/android/app/src/main/java/app/comm/android/fbjni/GlobalDBSingleton.java
@@ -0,0 +1,6 @@
+package app.comm.android.fbjni;
+
+public class GlobalDBSingleton {
+ public static native void scheduleOrRun(Runnable task);
+ public static native void enableMultithreading();
+}
diff --git a/native/cpp/CommonCpp/NativeModules/InternalModules/GlobalDBSingletonJNIHelper.h b/native/cpp/CommonCpp/NativeModules/InternalModules/GlobalDBSingletonJNIHelper.h
new file mode 100644
--- /dev/null
+++ b/native/cpp/CommonCpp/NativeModules/InternalModules/GlobalDBSingletonJNIHelper.h
@@ -0,0 +1,20 @@
+#pragma once
+
+#include <fbjni/NativeRunnable.h>
+#include <fbjni/fbjni.h>
+#include <jniHelpers.h>
+
+namespace comm {
+class GlobalDBSingletonJNIHelper
+ : public facebook::jni::JavaClass<GlobalDBSingletonJNIHelper> {
+public:
+ static auto constexpr kJavaDescriptor =
+ "Lapp/comm/android/fbjni/GlobalDBSingleton;";
+ static void scheduleOrRun(
+ facebook::jni::alias_ref<GlobalDBSingletonJNIHelper> jThis,
+ facebook::jni::alias_ref<Runnable> task);
+ static void enableMultithreading(
+ facebook::jni::alias_ref<GlobalDBSingletonJNIHelper> jThis);
+ static void registerNatives();
+};
+} // namespace comm

File Metadata

Mime Type
text/plain
Expires
Tue, Nov 26, 10:17 PM (14 h, 39 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2585954
Default Alt Text
D5236.id17413.diff (3 KB)

Event Timeline