Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3486199
D6210.id21607.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
6 KB
Referenced Files
None
Subscribers
None
D6210.id21607.diff
View Options
diff --git a/native/android/app/src/cpp/DatabaseInitializerJNIHelper.cpp b/native/android/app/src/cpp/DatabaseInitializerJNIHelper.cpp
new file mode 100644
--- /dev/null
+++ b/native/android/app/src/cpp/DatabaseInitializerJNIHelper.cpp
@@ -0,0 +1,18 @@
+#include <DatabaseManagers/DatabaseManager.h>
+#include <InternalModules/DatabaseInitializerJNIHelper.h>
+
+namespace comm {
+void DatabaseInitializerJNIHelper::initializeDatabaseManager(
+ facebook::jni::alias_ref<DatabaseInitializerJNIHelper> jThis,
+ std::string sqliteFilePath) {
+ DatabaseManager::initializeQueryExecutor(sqliteFilePath);
+}
+
+void DatabaseInitializerJNIHelper::registerNatives() {
+ javaClassStatic()->registerNatives({
+ makeNativeMethod(
+ "initializeDatabaseManager",
+ DatabaseInitializerJNIHelper::initializeDatabaseManager),
+ });
+}
+} // namespace comm
diff --git a/native/android/app/src/cpp/MessageOperationsUtilitiesJNIHelper.cpp b/native/android/app/src/cpp/MessageOperationsUtilitiesJNIHelper.cpp
--- a/native/android/app/src/cpp/MessageOperationsUtilitiesJNIHelper.cpp
+++ b/native/android/app/src/cpp/MessageOperationsUtilitiesJNIHelper.cpp
@@ -1,4 +1,4 @@
-#include <DatabaseManagers/SQLiteQueryExecutor.h>
+#include <DatabaseManagers/DatabaseManager.h>
#include <PersistentStorageUtilities/MessageOperationsUtilities/MessageOperationsUtilities.h>
#include <PersistentStorageUtilities/MessageOperationsUtilities/MessageOperationsUtilitiesJNIHelper.h>
@@ -9,7 +9,7 @@
facebook::jni::JString rawMessageInfosString) {
std::string sqliteFilePathCpp = sqliteFilePath.toStdString();
std::string rawMessageInfosStringCpp = rawMessageInfosString.toStdString();
- SQLiteQueryExecutor::initialize(sqliteFilePathCpp);
+ DatabaseManager::initializeQueryExecutor(sqliteFilePathCpp);
MessageOperationsUtilities::storeMessageInfos(rawMessageInfosStringCpp);
}
diff --git a/native/android/app/src/cpp/ThreadOperationsJNIHelper.cpp b/native/android/app/src/cpp/ThreadOperationsJNIHelper.cpp
--- a/native/android/app/src/cpp/ThreadOperationsJNIHelper.cpp
+++ b/native/android/app/src/cpp/ThreadOperationsJNIHelper.cpp
@@ -1,4 +1,4 @@
-#include <DatabaseManagers/SQLiteQueryExecutor.h>
+#include <DatabaseManagers/DatabaseManager.h>
#include <PersistentStorageUtilities/ThreadOperationsUtilities/ThreadOperations.h>
#include <PersistentStorageUtilities/ThreadOperationsUtilities/ThreadOperationsJNIHelper.h>
@@ -8,7 +8,7 @@
std::string sqliteFilePath,
std::string threadID,
bool unread) {
- SQLiteQueryExecutor::initialize(sqliteFilePath);
+ DatabaseManager::initializeQueryExecutor(sqliteFilePath);
ThreadOperations::updateSQLiteUnreadStatus(threadID, unread);
}
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/DatabaseInitializerJNIHelper.h>
#include <InternalModules/GlobalDBSingletonJNIHelper.h>
#include <NativeModules/CommCoreModule.h>
#include <PersistentStorageUtilities/MessageOperationsUtilities/MessageOperationsUtilitiesJNIHelper.h>
@@ -57,5 +58,6 @@
comm::ThreadOperationsJNIHelper::registerNatives();
comm::MessageOperationsUtilitiesJNIHelper::registerNatives();
comm::GlobalDBSingletonJNIHelper::registerNatives();
+ comm::DatabaseInitializerJNIHelper::registerNatives();
});
}
diff --git a/native/android/app/src/main/java/app/comm/android/MainApplication.java b/native/android/app/src/main/java/app/comm/android/MainApplication.java
--- a/native/android/app/src/main/java/app/comm/android/MainApplication.java
+++ b/native/android/app/src/main/java/app/comm/android/MainApplication.java
@@ -5,6 +5,9 @@
import android.database.CursorWindow;
import androidx.annotation.NonNull;
import androidx.multidex.MultiDexApplication;
+import app.comm.android.fbjni.CommSecureStore;
+import app.comm.android.fbjni.DatabaseInitializer;
+import app.comm.android.fbjni.GlobalDBSingleton;
import app.comm.android.newarchitecture.MainApplicationReactNativeHost;
import app.comm.android.notifications.CommAndroidNotificationsPackage;
import com.facebook.react.PackageList;
@@ -18,6 +21,7 @@
import com.wix.reactnativekeyboardinput.KeyboardInputPackage;
import expo.modules.ApplicationLifecycleDispatcher;
import expo.modules.ReactNativeHostWrapper;
+import java.io.File;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.security.Security;
@@ -81,6 +85,7 @@
Security.insertProviderAt(new org.conscrypt.OpenSSLProvider(), 1);
SoLoader.init(this, /* native exopackage */ false);
+ this.initializeDatabase();
ApplicationLifecycleDispatcher.onApplicationCreate(this);
try {
Field field = CursorWindow.class.getDeclaredField("sCursorWindowSize");
@@ -98,4 +103,15 @@
super.onConfigurationChanged(newConfig);
ApplicationLifecycleDispatcher.onConfigurationChanged(this, newConfig);
}
+
+ private void initializeDatabase() {
+ File sqliteFile =
+ this.getApplicationContext().getDatabasePath("comm.sqlite");
+ CommSecureStore.getInstance().initialize(
+ ExpoUtils.createExpoSecureStoreSupplier(this.getApplicationContext()));
+
+ GlobalDBSingleton.scheduleOrRun(() -> {
+ DatabaseInitializer.initializeDatabaseManager(sqliteFile.getPath());
+ });
+ }
}
diff --git a/native/android/app/src/main/java/app/comm/android/fbjni/DatabaseInitializer.java b/native/android/app/src/main/java/app/comm/android/fbjni/DatabaseInitializer.java
new file mode 100644
--- /dev/null
+++ b/native/android/app/src/main/java/app/comm/android/fbjni/DatabaseInitializer.java
@@ -0,0 +1,5 @@
+package app.comm.android.fbjni;
+
+public class DatabaseInitializer {
+ public static native void initializeDatabaseManager(String sqliteFilePath);
+}
diff --git a/native/cpp/CommonCpp/NativeModules/InternalModules/DatabaseInitializerJNIHelper.h b/native/cpp/CommonCpp/NativeModules/InternalModules/DatabaseInitializerJNIHelper.h
new file mode 100644
--- /dev/null
+++ b/native/cpp/CommonCpp/NativeModules/InternalModules/DatabaseInitializerJNIHelper.h
@@ -0,0 +1,16 @@
+#pragma once
+
+#include <fbjni/fbjni.h>
+
+namespace comm {
+class DatabaseInitializerJNIHelper
+ : public facebook::jni::JavaClass<DatabaseInitializerJNIHelper> {
+public:
+ static auto constexpr kJavaDescriptor =
+ "Lapp/comm/android/fbjni/DatabaseInitializer;";
+ static void initializeDatabaseManager(
+ facebook::jni::alias_ref<DatabaseInitializerJNIHelper> jThis,
+ std::string sqliteFilePath);
+ static void registerNatives();
+};
+} // namespace comm
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Dec 19, 3:56 AM (13 h, 47 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2675189
Default Alt Text
D6210.id21607.diff (6 KB)
Attached To
Mode
D6210: [native/Android] initialize database on app start
Attached
Detach File
Event Timeline
Log In to Comment