mirror of
https://github.com/oxen-io/session-android.git
synced 2025-10-21 15:08:42 +00:00
feat: start libsession-util integration and experimentation
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
package network.loki.messenger.libsession_util
|
||||
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
import org.junit.Assert.*
|
||||
|
||||
/**
|
||||
* Instrumented test, which will execute on an Android device.
|
||||
*
|
||||
* See [testing documentation](http://d.android.com/tools/testing).
|
||||
*/
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class ExampleInstrumentedTest {
|
||||
@Test
|
||||
fun useAppContext() {
|
||||
// Context of the app under test.
|
||||
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
|
||||
assertEquals("network.loki.messenger.libsession_util.test", appContext.packageName)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun jni_accessible() {
|
||||
assertEquals("Hello from C++", NativeLib().stringFromJNI())
|
||||
}
|
||||
|
||||
}
|
5
libsession-util/src/main/AndroidManifest.xml
Normal file
5
libsession-util/src/main/AndroidManifest.xml
Normal 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>
|
57
libsession-util/src/main/cpp/CMakeLists.txt
Normal file
57
libsession-util/src/main/cpp/CMakeLists.txt
Normal 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})
|
19
libsession-util/src/main/cpp/session_util.cpp
Normal file
19
libsession-util/src/main/cpp/session_util.cpp
Normal 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;
|
||||
}
|
@@ -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
|
||||
|
||||
|
||||
|
||||
}
|
@@ -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")
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,14 @@
|
||||
package network.loki.messenger.libsession_util
|
||||
|
||||
import org.junit.Test
|
||||
|
||||
import org.junit.Assert.*
|
||||
|
||||
/**
|
||||
* Example local unit test, which will execute on the development machine (host).
|
||||
*
|
||||
* See [testing documentation](http://d.android.com/tools/testing).
|
||||
*/
|
||||
class ExampleUnitTest {
|
||||
|
||||
}
|
Reference in New Issue
Block a user