Compare commits

..

1 commit

Author SHA1 Message Date
69dacb8024
refactor: lpac-jni bridge 2025-03-11 03:53:38 +08:00
8 changed files with 18 additions and 25 deletions

View file

@ -1,5 +1,5 @@
package net.typeblog.lpac_jni
interface ProfileDiscoveryCallback {
fun onDiscovered(servers: List<String>)
fun onDiscovered(servers: Set<String>)
}

View file

@ -1,7 +1,7 @@
#include <string.h>
#include <malloc.h>
#include "interface-wrapper.h"
#include "utils.h"
#include "lpac-convertor.h"
static jmethodID method_apdu_connect;
static jmethodID method_apdu_disconnect;
@ -95,7 +95,15 @@ http_interface_transmit(struct euicc_ctx *ctx, const char *url, uint32_t *rcode,
jbyteArray txArr = (*env)->NewByteArray(env, (jsize) tx_len);
(*env)->SetByteArrayRegion(env, txArr, 0, (jsize) tx_len, (const jbyte *) tx);
jobject header_list = to_string_list(env, (char **) headers);
jobject header_list = new_array_list(env);
jclass header_list_class = (*env)->GetObjectClass(env, header_list);
jmethodID add_header = (*env)->GetMethodID(env, header_list_class, "add", "(Ljava/lang/Object;)Z");
for (int i = 0; headers[i] != NULL; i++) {
jstring header = toJString(env, headers[i]);
(*env)->CallBooleanMethod(env, header_list, add_header, header);
(*env)->DeleteLocalRef(env, header);
}
jobject ret = (*env)->CallObjectMethod(env, LPAC_JNI_CTX(ctx)->http_interface,
method_http_transmit, jurl, txArr, header_list);

View file

@ -1,4 +1,4 @@
#include "utils.h"
#include "lpac-convertor.h"
#include <malloc.h>
#include <string.h>
#include <syslog.h>
@ -145,19 +145,6 @@ jobject to_string_set(JNIEnv *env, char **values) {
return elements;
}
jobject to_string_list(JNIEnv *env, char **values) {
jclass set_class = (*env)->FindClass(env, ARRAY_LIST_CLASS);
jmethodID set_constructor = (*env)->GetMethodID(env, set_class, "<init>", "()V");
jobject elements = (*env)->NewObject(env, set_class, set_constructor);
jmethodID add_element = (*env)->GetMethodID(env, set_class, "add", "(Ljava/lang/Object;)Z");
jstring element = NULL;
for (jsize index = 0; values[index] != NULL; index++) {
element = toJString(env, values[index]);
(*env)->CallBooleanMethod(env, elements, add_element, element);
}
return elements;
}
jobject build_profile_metadata(JNIEnv *env, struct es8p_metadata *metadata) {
if (metadata == NULL) return NULL;

View file

@ -31,8 +31,6 @@ jobject to_version(JNIEnv *env, const char *version);
jobject to_string_set(JNIEnv *env, char **values);
jobject to_string_list(JNIEnv *env, char **values);
jobject build_profile_metadata(JNIEnv *env, struct es8p_metadata *metadata);
jobject to_profile_management_operation(enum es10b_profile_management_operation operation);

View file

@ -4,7 +4,7 @@
#include <string.h>
#include <malloc.h>
#include <syslog.h>
#include "utils.h"
#include "lpac-convertor.h"
#include "lpac-discovery.h"
JNIEXPORT jobject JNICALL
@ -52,7 +52,7 @@ Java_net_typeblog_lpac_1jni_LpacJni_discoveryProfile(
jclass callback_class = (*env)->GetObjectClass(env, callback);
jmethodID on_discovered = (*env)->GetMethodID(env, callback_class, "onDiscovered",
"(Ljava/util/List;)V");
"(Ljava/util/Set;)V");
const char *_address = (*env)->GetStringUTFChars(env, address, NULL);
const char *_imei = NULL;
@ -95,7 +95,7 @@ Java_net_typeblog_lpac_1jni_LpacJni_discoveryProfile(
goto out;
}
(*env)->CallVoidMethod(env, callback, on_discovered, to_string_list(env, smdp_list));
(*env)->CallVoidMethod(env, callback, on_discovered, to_string_set(env, smdp_list));
out:

View file

@ -3,7 +3,7 @@
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
#include "utils.h"
#include "lpac-convertor.h"
#include "lpac-download.h"
static jobject download_state_preparing;

View file

@ -9,7 +9,7 @@
#include "lpac-download.h"
#include "lpac-notifications.h"
#include "lpac-discovery.h"
#include "utils.h"
#include "lpac-convertor.h"
#include "interface-wrapper.h"
JavaVM *jvm = NULL;

View file

@ -2,7 +2,7 @@
#include <euicc/es10b.h>
#include <malloc.h>
#include <syslog.h>
#include "utils.h"
#include "lpac-convertor.h"
#include "lpac-notifications.h"
JNIEXPORT jobject JNICALL