Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 30 additions & 4 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,49 @@ on:
- opened
- synchronize

# Limit to one concurrent run per PR
concurrency:
group: "check-pr-${{ github.event.pull_request.number }}"
cancel-in-progress: true

jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
pull-requests: write

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v5
with:
submodules: 'recursive'
submodules: "recursive"
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
java-version: "17"
distribution: "temurin"
cache: gradle

- name: Verify build for PR
run: ./gradlew check

post_version:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
with:
fetch-tags: true
fetch-depth: 0

- name: Extract version
id: extract_version
run: |
VERSION=$(git describe --tags --dirty)
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Posting comment about the build
uses: marocchino/sticky-pull-request-comment@v2
with:
header: version
message: |
The build version for this PR will be: `${{ steps.extract_version.outputs.version }}`
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ junit = { module = "junit:junit", version = "4.13.2" }
androidx-test-runner = { module = "androidx.test:runner", version = "1.7.0" }
androidx-test-rules = { module = "androidx.test:rules", version = "1.7.0" }
androidx-test-ext = { module = "androidx.test.ext:junit", version = "1.3.0" }
androidx-annotations = { module = "androidx.annotation:annotation", version = "1.9.1" }

[plugins]
android-library = { id = "com.android.library", version.ref = "agp" }
Expand Down
4 changes: 3 additions & 1 deletion library/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ android {
compileSdk = 35

defaultConfig {
minSdk = 24
minSdk = 26

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"

Expand Down Expand Up @@ -117,4 +117,6 @@ dependencies {
androidTestImplementation(libs.androidx.test.runner)
androidTestImplementation(libs.androidx.test.rules)
androidTestImplementation(libs.androidx.test.ext)

implementation(libs.androidx.annotations)
}
1 change: 1 addition & 0 deletions library/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ set(SOURCES
ed25519.cpp
curve25519.cpp
hash.cpp
protocol.cpp
attachments.cpp
webp_utils.cpp
gif_utils.cpp
Expand Down
7 changes: 7 additions & 0 deletions library/src/main/cpp/group_keys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,13 @@ Java_network_loki_messenger_libsession_1util_GroupKeysConfig_keys(JNIEnv *env, j
return jni_utils::jlist_from_collection(env, ptr->group_keys(), util::bytes_from_span);
}

extern "C"
JNIEXPORT jobject JNICALL
Java_network_loki_messenger_libsession_1util_GroupKeysConfig_groupEncKey(JNIEnv *env, jobject thiz) {
auto ptr = ptrToKeys(env, thiz);
return util::bytes_from_span(env, ptr->group_enc_key());
}

extern "C"
JNIEXPORT jobject JNICALL
Java_network_loki_messenger_libsession_1util_GroupKeysConfig_activeHashes(JNIEnv *env,
Expand Down
38 changes: 37 additions & 1 deletion library/src/main/cpp/jni_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ namespace jni_utils {
env_->DeleteLocalRef(ref_);
}
}
JavaLocalRef(JavaLocalRef&& other) : env_(other.env_), ref_(other.ref_) {
other.ref_ = nullptr;
}

JavaLocalRef(const JavaLocalRef&) = delete;

void reset(JNIType new_ref) {
if (ref_ != new_ref) {
Expand All @@ -82,6 +87,7 @@ namespace jni_utils {
}
};


/**
* Create a Java List from an iterator.
*
Expand Down Expand Up @@ -169,6 +175,8 @@ namespace jni_utils {
data = std::span<char>(const_cast<char *>(c_str), env->GetStringUTFLength(s));
}

JavaStringRef(const JavaStringRef &) = delete;

~JavaStringRef() {
env->ReleaseStringUTFChars(s, data.data());
}
Expand Down Expand Up @@ -202,8 +210,18 @@ namespace jni_utils {
data = std::span<unsigned char>(reinterpret_cast<unsigned char *>(env->GetByteArrayElements(byte_array, nullptr)), length);
}

JavaByteArrayRef(const JavaByteArrayRef &) = delete;

JavaByteArrayRef(JavaByteArrayRef&& other) : env(other.env), byte_array(other.byte_array), data(other.data) {
other.byte_array = nullptr;
other.data = {};
}

~JavaByteArrayRef() {
env->ReleaseByteArrayElements(byte_array, reinterpret_cast<jbyte *>(data.data()), 0);
if (byte_array) {
env->ReleaseByteArrayElements(byte_array,
reinterpret_cast<jbyte *>(data.data()), 0);
}
}

jbyteArray java_array() const {
Expand Down Expand Up @@ -235,6 +253,24 @@ namespace jni_utils {
return std::vector(data.begin(), data.end());
}
};

template <size_t N>
static std::optional<std::array<unsigned char, N>> java_to_cpp_array(JNIEnv *env, jbyteArray array) {
if (!array) {
return std::nullopt;
}

JavaByteArrayRef bytes(env, array);
auto span = bytes.get();
if (span.size() != N) {
throw std::runtime_error("Invalid byte array length from java, expecting " + std::to_string(N) + " got " + std::to_string(span.size()));
}

std::array<unsigned char, N> out;
std::copy(span.begin(), span.end(), out.begin());
return out;
}

}

#endif //SESSION_ANDROID_JNI_UTILS_H
Loading