feat: start libsession-util integration and experimentation

This commit is contained in:
0x330a
2022-11-28 18:08:01 +11:00
parent 1dbcffe40b
commit 4045333dbc
37 changed files with 4393 additions and 1 deletions

View File

@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="network.loki.messenger.libsession_util">
</manifest>

View File

@@ -0,0 +1,57 @@
# For more information about using CMake with Android Studio, read the
# documentation: https://d.android.com/studio/projects/add-native-code.html
# Sets the minimum version of CMake required to build the native library.
cmake_minimum_required(VERSION 3.18.1)
# Declares and names the project.
project("session_util")
# 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.
add_library( # Sets the name of the library.
session_util
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
session_util.cpp)
# Searches for a specified prebuilt library and stores the path as a
# variable. Because CMake includes system libraries in the search path by
# default, you only need to specify the name of the public NDK library
# you want to add. CMake verifies that the library exists before
# completing its build.
find_library( # Sets the name of the path variable.
log-lib
# Specifies the name of the NDK library that
# you want CMake to locate.
log)
# Add the libsession-util library here
set(distribution_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../../distribution)
add_library(external-libsession-util STATIC IMPORTED)
set_target_properties(external-libsession-util PROPERTIES IMPORTED_LOCATION
${distribution_DIR}/libsession-util-android/lib/${ANDROID_ABI}/libsession-util.a)
target_include_directories(session_util PRIVATE
${distribution_DIR}/libsession-util-android/include)
# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in this
# build script, prebuilt third-party libraries, or system libraries.
target_link_libraries( # Specifies the target library.
session_util
external-libsession-util
# Links the target library to the log library
# included in the NDK.
${log-lib})

View File

@@ -0,0 +1,19 @@
#include <jni.h>
#include <string>
#include "session/config/user_profile.hpp"
extern "C" JNIEXPORT jobject JNICALL
Java_network_loki_messenger_libsession_1util_Config_00024Companion_newInstance(
JNIEnv* env,
jobject /*this*/) {
auto* profile = new session::config::UserProfile();
jclass configClass = env->FindClass("network/loki/messenger/libsession_util/Config");
jobject newConfig = env->AllocObject(configClass);
jfieldID pointerField = env->GetFieldID(configClass, "pointer", "J");
env->SetLongField(newConfig, pointerField, reinterpret_cast<jlong>(profile));
return newConfig;
}

View File

@@ -0,0 +1,13 @@
package network.loki.messenger.libsession_util
data class Config(private val /* yucky */ pointer: Long) {
companion object {
external fun newInstance(): Config
}
var lastError: String? = null
}

View File

@@ -0,0 +1,17 @@
package network.loki.messenger.libsession_util
class NativeLib {
/**
* A native method that is implemented by the 'libsession_util' native library,
* which is packaged with this application.
*/
external fun stringFromJNI(): String
companion object {
// Used to load the 'libsession_util' library on application startup.
init {
System.loadLibrary("session_util")
}
}
}