diff --git a/native/android/app/CMakeLists.txt b/native/android/app/CMakeLists.txt index 8fe99eea0..f5b750dd6 100644 --- a/native/android/app/CMakeLists.txt +++ b/native/android/app/CMakeLists.txt @@ -1,228 +1,229 @@ # For more information about using CMake with Android Studio, read the # documentation: https://d.android.com/studio/projects/add-native-code.html -project(comm) +project(comm CXX C) set (CMAKE_CXX_STANDARD 14) # C0103 is a naming convention, but the variable names which need to be set # are determined by the upstream project # cmake-lint: disable=C0103 # Disable line length as some paths are hard to reduce without becoming cryptic # cmake-lint: disable=C0301 # Sets the minimum version of CMake required to build the native library. cmake_minimum_required(VERSION 3.4.1) # Creates and names a library, sets it as either STATIC # or SHARED, and provides the relative paths to its source code. # You can define multiple libraries, and CMake builds them for you. # Gradle automatically packages shared libraries with your APK. set(PACKAGE_NAME "comm_jni_module") find_package(fbjni REQUIRED CONFIG) set(BUILD_TESTING OFF) set(HAVE_SYMBOLIZE OFF) set(WITH_GTEST OFF CACHE BOOL "Use googletest" FORCE) set(WITH_GFLAGS OFF CACHE BOOL "Use gflags" FORCE) # General set(_third_party_dir ${CMAKE_CURRENT_SOURCE_DIR}/build/third-party-ndk) set(_android_build_dir build/${CMAKE_ANDROID_ARCH_ABI}) # Protobuf set(protobuf_BUILD_TESTS OFF) # gRPC building parameters set(gRPC_BUILD_CSHARP_EXT OFF) set(gRPC_SSL_PROVIDER "package" CACHE STRING "SSL library provider") # Disable unused plugins set(gRPC_BUILD_GRPC_PHP_PLUGIN OFF) set(gRPC_BUILD_GRPC_RUBY_PLUGIN OFF) set(gRPC_BUILD_GRPC_PYTHON_PLUGIN OFF) set(gRPC_BUILD_GRPC_CSHARP_PLUGIN OFF) # We're updating parameters below for Cmake's find_OpenSSL() function set(OPENSSL_ROOT_DIR "${_third_party_dir}/openssl/openssl-${OPENSSL_VERSION}/${_android_build_dir}" ) list(APPEND CMAKE_FIND_ROOT_PATH "${OPENSSL_ROOT_DIR}") add_subdirectory(${_third_party_dir}/grpc/grpc-${GRPC_VERSION}/ ${CMAKE_CURRENT_BINARY_DIR}/grpc/ EXCLUDE_FROM_ALL ) add_subdirectory(${_third_party_dir}/glog/glog-${GLOG_VERSION}/) add_subdirectory(../../node_modules/olm ./build) set(_node_modules_dir ${CMAKE_CURRENT_SOURCE_DIR}/../../node_modules) set(_react_native_dir ${_node_modules_dir}/react-native) include_directories( ${_react_native_dir}/React ${_react_native_dir}/React/Base ${_react_native_dir}/ReactCommon ${_react_native_dir}/ReactCommon/jsi ${_react_native_dir}/ReactCommon/callinvoker ${_react_native_dir}/ReactAndroid/src/main/java/com/facebook/react/turbomodule/core/jni/ReactCommon # OpenSSL ${_third_party_dir}/openssl/openssl-${OPENSSL_VERSION}/build/${CMAKE_ANDROID_ARCH_ABI}/include # SQLCipher amalgamation ${_node_modules_dir}/@commapp/sqlcipher-amalgamation/src # SQLite ORM ../../cpp/lib/sqlite_orm # symlinked React Native headers ../headers # external libs ${_third_party_dir}/folly ${_third_party_dir}/boost/boost ${_third_party_dir}/double-conversion # comm android specific code ./src/cpp # comm native mutual code + ../../cpp/CommonCpp/ ../../cpp/CommonCpp/NativeModules ../../cpp/CommonCpp/NativeModules/InternalModules ../../cpp/CommonCpp/NativeModules/PersistentStorageUtilities ../../cpp/CommonCpp/NativeModules/PersistentStorageUtilities/ThreadOperationsUtilities ../../cpp/CommonCpp/NativeModules/PersistentStorageUtilities/MessageOperationsUtilities ../../cpp/CommonCpp/NativeModules/PersistentStorageUtilities/MessageOperationsUtilities/MessageSpecs ../../cpp/CommonCpp/DatabaseManagers ../../cpp/CommonCpp/Tools ../../cpp/CommonCpp/grpc/_generated ../../cpp/CommonCpp/grpc ) # search for all cpp files in this directory file(GLOB SQLCIPHER "${_node_modules_dir}/@commapp/sqlcipher-amalgamation/src/*.c" ) file(GLOB_RECURSE COMMON_NATIVE_CODE "../../cpp/CommonCpp/**/*.cpp") file(GLOB ANDROID_NATIVE_CODE "./src/cpp/*.cpp") file(GLOB DOUBLE_CONVERSION_SOURCES "${_third_party_dir}/double-conversion/double-conversion/*.cc" ) file(GLOB GRPC_CODE "../../cpp/CommonCpp/grpc/_generated/*.cc") add_library( # Sets the name of the library. ${PACKAGE_NAME} # Sets the library as a shared library. SHARED # Provides a relative path to your source file(s). ${_react_native_dir}/ReactCommon/jsi/jsi/jsi.cpp ${_react_native_dir}/ReactAndroid/src/main/java/com/facebook/react/turbomodule/core/jni/ReactCommon/CallInvokerHolder.cpp ${_react_native_dir}/ReactCommon/react/nativemodule/core/ReactCommon/TurboModule.cpp ${_react_native_dir}/ReactCommon/react/nativemodule/core/ReactCommon/LongLivedObject.cpp ${_react_native_dir}/ReactCommon/react/nativemodule/core/ReactCommon/TurboModuleUtils.cpp # SQLCipher ${SQLCIPHER} # folly ${_third_party_dir}/folly/folly/detail/Futex.cpp ${_third_party_dir}/folly/folly/synchronization/ParkingLot.cpp ${_third_party_dir}/folly/folly/lang/SafeAssert.cpp ${_third_party_dir}/folly/folly/FileUtil.cpp ${_third_party_dir}/folly/folly/Subprocess.cpp ${_third_party_dir}/folly/folly/File.cpp ${_third_party_dir}/folly/folly/Format.cpp ${_third_party_dir}/folly/folly/Conv.cpp ${_third_party_dir}/folly/folly/io/IOBuf.cpp ${_third_party_dir}/folly/folly/memory/detail/MallocImpl.cpp ${_third_party_dir}/folly/folly/ScopeGuard.cpp ${_third_party_dir}/folly/folly/hash/SpookyHashV2.cpp ${_third_party_dir}/folly/folly/io/IOBufQueue.cpp ${_third_party_dir}/folly/folly/lang/Assume.cpp ${_third_party_dir}/folly/folly/String.cpp ${_third_party_dir}/folly/folly/portability/SysUio.cpp ${_third_party_dir}/folly/folly/net/NetOps.cpp ${_third_party_dir}/folly/folly/dynamic.cpp ${_third_party_dir}/folly/folly/json.cpp ${_third_party_dir}/folly/folly/json_pointer.cpp ${_third_party_dir}/folly/folly/Unicode.cpp # double-conversion ${DOUBLE_CONVERSION_SOURCES} ${GRPC_CODE} # comm code ${ANDROID_NATIVE_CODE} ${COMMON_NATIVE_CODE} ) add_definitions( ## Folly -DFOLLY_NO_CONFIG=1 -DFOLLY_HAVE_CLOCK_GETTIME=1 -DFOLLY_HAVE_MEMRCHR=1 -DFOLLY_USE_LIBCPP=1 -DFOLLY_MOBILE=1 ## SQLCipher -DSQLITE_THREADSAFE=0 -DSQLITE_HAS_CODEC -DSQLITE_TEMP_STORE=2 -DSQLCIPHER_CRYPTO_OPENSSL ) find_library(log-lib log) add_library( # OpenSSL Crypto lib openssl-crypto STATIC IMPORTED ) set_target_properties( # OpenSSL Crypto lib openssl-crypto PROPERTIES IMPORTED_LOCATION "${_third_party_dir}/openssl/openssl-${OPENSSL_VERSION}/build/${CMAKE_ANDROID_ARCH_ABI}/lib/libcrypto.a" ) add_library( # OpenSSL SSL lib openssl-ssl STATIC IMPORTED ) set_target_properties( # OpenSSL SSL lib openssl-ssl PROPERTIES IMPORTED_LOCATION "${_third_party_dir}/openssl/openssl-${OPENSSL_VERSION}/build/${CMAKE_ANDROID_ARCH_ABI}/lib/libssl.a" ) target_link_libraries( ${PACKAGE_NAME} fbjni::fbjni android ${log-lib} glog::glog olm openssl-crypto openssl-ssl grpc++ libprotobuf ) # add a dummy library which is required by CallInvokerHolderImpl.java add_library( turbomodulejsijni # Sets the library as a shared library. SHARED # Provides a relative path to your source file(s). ./src/cpp/dummy.cpp ) diff --git a/native/android/app/src/cpp/CommSecureStore.cpp b/native/android/app/src/cpp/CommSecureStore.cpp index 71987e96a..c751177d3 100644 --- a/native/android/app/src/cpp/CommSecureStore.cpp +++ b/native/android/app/src/cpp/CommSecureStore.cpp @@ -1,39 +1,39 @@ -#include "CommSecureStore.h" +#include #include using namespace facebook::jni; class CommSecureStoreJavaClass : public JavaClass { public: static auto constexpr kJavaDescriptor = "Lapp/comm/android/fbjni/CommSecureStore;"; static void set(std::string key, std::string value) { static const auto cls = javaClassStatic(); static auto method = cls->getStaticMethod("set"); method(cls, key, value); } static folly::Optional get(std::string key) { static const auto cls = javaClassStatic(); static auto method = cls->getStaticMethod("get"); const auto result = method(cls, key); return (result) ? folly::Optional(result->toStdString()) : folly::none; } }; namespace comm { void CommSecureStore::set(const std::string key, const std::string value) const { CommSecureStoreJavaClass::set(key, value); } folly::Optional CommSecureStore::get(const std::string key) const { return CommSecureStoreJavaClass::get(key); } } // namespace comm diff --git a/native/android/app/src/cpp/GlobalNetworkSingletonJNIHelper.cpp b/native/android/app/src/cpp/GlobalNetworkSingletonJNIHelper.cpp index 0e718bd16..3ced9a252 100644 --- a/native/android/app/src/cpp/GlobalNetworkSingletonJNIHelper.cpp +++ b/native/android/app/src/cpp/GlobalNetworkSingletonJNIHelper.cpp @@ -1,17 +1,17 @@ -#include "GlobalNetworkSingletonJNIHelper.h" -#include "GlobalNetworkSingleton.h" +#include +#include namespace comm { void GlobalNetworkSingletonJNIHelper::sendPong( facebook::jni::alias_ref jThis) { GlobalNetworkSingleton::instance.scheduleOrRun( [](NetworkModule &networkModule) { networkModule.sendPong(); }); } void GlobalNetworkSingletonJNIHelper::registerNatives() { javaClassStatic()->registerNatives({ makeNativeMethod("sendPong", GlobalNetworkSingletonJNIHelper::sendPong), }); } } // namespace comm diff --git a/native/android/app/src/cpp/Logger.cpp b/native/android/app/src/cpp/Logger.cpp index ee253ec9f..edcf975da 100644 --- a/native/android/app/src/cpp/Logger.cpp +++ b/native/android/app/src/cpp/Logger.cpp @@ -1,11 +1,11 @@ -#include "Logger.h" +#include #include namespace comm { void Logger::log(const std::string str) { __android_log_print(ANDROID_LOG_VERBOSE, "COMM", "%s", str.c_str()); }; } // namespace comm diff --git a/native/android/app/src/cpp/MessageOperationsUtilitiesJNIHelper.cpp b/native/android/app/src/cpp/MessageOperationsUtilitiesJNIHelper.cpp index cf51cb2e4..25cee3430 100644 --- a/native/android/app/src/cpp/MessageOperationsUtilitiesJNIHelper.cpp +++ b/native/android/app/src/cpp/MessageOperationsUtilitiesJNIHelper.cpp @@ -1,23 +1,23 @@ -#include "MessageOperationsUtilitiesJNIHelper.h" -#include "MessageOperationsUtilities.h" -#include "SQLiteQueryExecutor.h" +#include +#include +#include namespace comm { void MessageOperationsUtilitiesJNIHelper::storeMessageInfos( facebook::jni::alias_ref jThis, facebook::jni::JString sqliteFilePath, facebook::jni::JString rawMessageInfosString) { std::string sqliteFilePathCpp = sqliteFilePath.toStdString(); std::string rawMessageInfosStringCpp = rawMessageInfosString.toStdString(); SQLiteQueryExecutor::initialize(sqliteFilePathCpp); MessageOperationsUtilities::storeMessageInfos(rawMessageInfosStringCpp); } void MessageOperationsUtilitiesJNIHelper::registerNatives() { javaClassStatic()->registerNatives({ makeNativeMethod( "storeMessageInfos", MessageOperationsUtilitiesJNIHelper::storeMessageInfos), }); } } // namespace comm diff --git a/native/android/app/src/cpp/PlatformSpecificTools.cpp b/native/android/app/src/cpp/PlatformSpecificTools.cpp index d3f1dc58c..2341df959 100644 --- a/native/android/app/src/cpp/PlatformSpecificTools.cpp +++ b/native/android/app/src/cpp/PlatformSpecificTools.cpp @@ -1,40 +1,40 @@ -#include "PlatformSpecificTools.h" -#include "Logger.h" +#include +#include #include using namespace facebook::jni; class PlatformSpecificToolsJavaClass : public JavaClass { public: static auto constexpr kJavaDescriptor = "Lapp/comm/android/fbjni/PlatformSpecificTools;"; static comm::crypto::OlmBuffer generateSecureRandomBytes(size_t size) { static const auto cls = javaClassStatic(); static auto method = cls->getStaticMethod("generateSecureRandomBytes"); auto methodResult = method(cls, (int)size); comm::crypto::OlmBuffer result(size); std::vector bytes(size); methodResult->getRegion(0, size, bytes.data()); for (size_t i = 0; i < size; ++i) { result[i] = bytes[i]; } return result; } }; namespace comm { void PlatformSpecificTools::generateSecureRandomBytes( crypto::OlmBuffer &buffer, size_t size) { buffer = PlatformSpecificToolsJavaClass::generateSecureRandomBytes(size); } std::string PlatformSpecificTools::getDeviceOS() { return std::string{"android"}; } } // namespace comm diff --git a/native/android/app/src/cpp/ThreadOperationsJNIHelper.cpp b/native/android/app/src/cpp/ThreadOperationsJNIHelper.cpp index bdeede4b8..ab8d8c9f1 100644 --- a/native/android/app/src/cpp/ThreadOperationsJNIHelper.cpp +++ b/native/android/app/src/cpp/ThreadOperationsJNIHelper.cpp @@ -1,22 +1,22 @@ -#include "ThreadOperationsJNIHelper.h" -#include "SQLiteQueryExecutor.h" -#include "ThreadOperations.h" +#include +#include +#include namespace comm { void ThreadOperationsJNIHelper::updateSQLiteUnreadStatus( facebook::jni::alias_ref jThis, std::string sqliteFilePath, std::string threadID, bool unread) { SQLiteQueryExecutor::initialize(sqliteFilePath); ThreadOperations::updateSQLiteUnreadStatus(threadID, unread); } void ThreadOperationsJNIHelper::registerNatives() { javaClassStatic()->registerNatives({ makeNativeMethod( "updateSQLiteUnreadStatus", ThreadOperationsJNIHelper::updateSQLiteUnreadStatus), }); } } // namespace comm diff --git a/native/android/app/src/cpp/jsiInstaller.cpp b/native/android/app/src/cpp/jsiInstaller.cpp index bda2c6c98..c8b77dd79 100644 --- a/native/android/app/src/cpp/jsiInstaller.cpp +++ b/native/android/app/src/cpp/jsiInstaller.cpp @@ -1,60 +1,61 @@ -#include "CommCoreModule.h" -#include "GlobalNetworkSingletonJNIHelper.h" -#include "MessageOperationsUtilitiesJNIHelper.h" -#include "SQLiteQueryExecutor.h" -#include "ThreadOperationsJNIHelper.h" #include "jniHelpers.h" #include #include #include +#include +#include +#include +#include +#include + namespace jni = facebook::jni; namespace jsi = facebook::jsi; namespace react = facebook::react; class CommHybrid : public jni::HybridClass { public: static auto constexpr kJavaDescriptor = "Lapp/comm/android/fbjni/CommHybrid;"; static void initHybrid( jni::alias_ref jThis, jlong jsContext, jni::alias_ref jsCallInvokerHolder, comm::HashMap additionalParameters) { jsi::Runtime *rt = (jsi::Runtime *)jsContext; auto jsCallInvoker = jsCallInvokerHolder->cthis()->getCallInvoker(); std::shared_ptr nativeModule = std::make_shared(jsCallInvoker); if (rt != nullptr) { rt->global().setProperty( *rt, jsi::PropNameID::forAscii(*rt, "CommCoreModule"), jsi::Object::createFromHostObject(*rt, nativeModule)); } jni::local_ref sqliteFilePathObj = additionalParameters.get("sqliteFilePath"); std::string sqliteFilePath = sqliteFilePathObj->toString(); comm::SQLiteQueryExecutor::initialize(sqliteFilePath); } static void registerNatives() { javaClassStatic()->registerNatives({ makeNativeMethod("initHybrid", CommHybrid::initHybrid), }); } private: friend HybridBase; }; JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *) { return jni::initialize(vm, [] { CommHybrid::registerNatives(); comm::GlobalNetworkSingletonJNIHelper::registerNatives(); comm::ThreadOperationsJNIHelper::registerNatives(); comm::MessageOperationsUtilitiesJNIHelper::registerNatives(); }); }