Compare commits

..

1 commit

Author SHA1 Message Date
abde69ea5c
refactor: profile list 2025-03-10 23:02:09 +08:00
3 changed files with 57 additions and 80 deletions

View file

@ -1,57 +0,0 @@
#include "lpac-convertor.h"
jobject profile_state_enabled;
jobject profile_state_disabled;
jobject profile_class_operational;
jobject profile_class_provisioning;
jobject profile_class_testing;
static jobject bind_static_field(JNIEnv *env, jclass clazz, const char *name, const char *sig) {
jfieldID field = (*env)->GetStaticFieldID(env, clazz, name, sig);
jobject bound = (*env)->GetStaticObjectField(env, clazz, field);
return (*env)->NewGlobalRef(env, bound);
}
#define BIND_PROFILE_STATE_STATIC_FIELD(NAME, FIELD) \
profile_state_##NAME = bind_static_field(env, profile_state_class, FIELD, "L" PROFILE_STATE_CLASS ";")
#define BIND_PROFILE_CLASS_STATIC_FIELD(NAME, FIELD) \
profile_class_##NAME = bind_static_field(env, profile_class_class, FIELD, "L" PROFILE_CLASS_CLASS ";")
void lpac_convertor_init(JNIEnv *env) {
jclass profile_state_class = (*env)->FindClass(env, PROFILE_STATE_CLASS);
BIND_PROFILE_STATE_STATIC_FIELD(enabled, "Enabled");
BIND_PROFILE_STATE_STATIC_FIELD(disabled, "Disabled");
jclass profile_class_class = (*env)->FindClass(env, PROFILE_CLASS_CLASS);
BIND_PROFILE_CLASS_STATIC_FIELD(operational, "Operational");
BIND_PROFILE_CLASS_STATIC_FIELD(provisioning, "Provisioning");
BIND_PROFILE_CLASS_STATIC_FIELD(testing, "Testing");
}
#undef BIND_PROFILE_STATE_STATIC_FIELD
#undef BIND_PROFILE_CLASS_STATIC_FIELD
jobject to_profile_state(enum es10c_profile_state profile_state) {
switch (profile_state) {
case ES10C_PROFILE_STATE_ENABLED:
return profile_state_enabled;
case ES10C_PROFILE_STATE_DISABLED:
return profile_state_disabled;
default:
return NULL;
}
}
jobject to_profile_class(enum es10c_profile_class profile_class) {
switch (profile_class) {
case ES10C_PROFILE_CLASS_OPERATIONAL:
return profile_class_operational;
case ES10C_PROFILE_CLASS_PROVISIONING:
return profile_class_provisioning;
case ES10C_PROFILE_CLASS_TEST:
return profile_class_testing;
default:
return NULL;
}
}

View file

@ -1,19 +0,0 @@
#pragma once
#include <jni.h>
#include <euicc/es10c.h>
jobject profile_state_enabled;
jobject profile_state_disabled;
jobject profile_class_operational;
jobject profile_class_provisioning;
jobject profile_class_testing;
#define PROFILE_STATE_CLASS "net/typeblog/lpac_jni/ProfileState"
#define PROFILE_CLASS_CLASS "net/typeblog/lpac_jni/ProfileClass"
void lpac_convertor_init(JNIEnv *env);
jobject to_profile_state(enum es10c_profile_state profile_state);
jobject to_profile_class(enum es10c_profile_class profile_class);

View file

@ -9,7 +9,6 @@
#include "lpac-download.h"
#include "lpac-notifications.h"
#include "interface-wrapper.h"
#include "lpac-convertor.h"
JavaVM *jvm = NULL;
@ -18,18 +17,25 @@ jstring empty_string;
jclass string_class;
jmethodID string_constructor;
#define LOCAL_PROFILE_INFO_CLASS "net/typeblog/lpac_jni/LocalProfileInfo"
jobject profile_state_enabled;
jobject profile_state_disabled;
jobject profile_class_operational;
jobject profile_class_provisioning;
jobject profile_class_testing;
#define LOCAL_PROFILE_INFO_CLASS "net/typeblog/lpac_jni/LocalProfileInfo"
#define PROFILE_STATE_CLASS "net/typeblog/lpac_jni/ProfileState"
#define PROFILE_CLASS_CLASS "net/typeblog/lpac_jni/ProfileClass"
jint JNI_OnLoad(JavaVM *vm, void *reserved) {
jvm = vm;
LPAC_JNI_SETUP_ENV;
interface_wrapper_init();
lpac_convertor_init(env);
lpac_download_init();
lpac_profile_init(env);
string_class = (*env)->FindClass(env, "java/lang/String");
string_class = (*env)->NewGlobalRef(env, string_class);
string_constructor = (*env)->GetMethodID(env, string_class, "<init>",
@ -42,9 +48,32 @@ jint JNI_OnLoad(JavaVM *vm, void *reserved) {
return JNI_VERSION_1_6;
}
void lpac_profile_init(JNIEnv *env) {
static jobject bind_static_field(JNIEnv *env, jclass clazz, const char *name, const char *sig) {
jfieldID field = (*env)->GetStaticFieldID(env, clazz, name, sig);
jobject bound = (*env)->GetStaticObjectField(env, clazz, field);
return (*env)->NewGlobalRef(env, bound);
}
#define BIND_PROFILE_STATE_STATIC_FIELD(NAME, FIELD) \
profile_state_##NAME = bind_static_field(env, profile_state_class, FIELD, "L" PROFILE_STATE_CLASS ";")
#define BIND_PROFILE_CLASS_STATIC_FIELD(NAME, FIELD) \
profile_class_##NAME = bind_static_field(env, profile_class_class, FIELD, "L" PROFILE_CLASS_CLASS ";")
void lpac_profile_init(JNIEnv *env) {
jclass profile_state_class = (*env)->FindClass(env, PROFILE_STATE_CLASS);
BIND_PROFILE_STATE_STATIC_FIELD(enabled, "Enabled");
BIND_PROFILE_STATE_STATIC_FIELD(disabled, "Disabled");
jclass profile_class_class = (*env)->FindClass(env, PROFILE_CLASS_CLASS);
BIND_PROFILE_CLASS_STATIC_FIELD(operational, "Operational");
BIND_PROFILE_CLASS_STATIC_FIELD(provisioning, "Provisioning");
BIND_PROFILE_CLASS_STATIC_FIELD(testing, "Testing");
}
#undef BIND_PROFILE_STATE_STATIC_FIELD
#undef BIND_PROFILE_CLASS_STATIC_FIELD
JNIEXPORT jlong JNICALL
Java_net_typeblog_lpac_1jni_LpacJni_createContext(JNIEnv *env, jobject thiz,
jbyteArray isdr_aid,
@ -139,6 +168,30 @@ Java_net_typeblog_lpac_1jni_LpacJni_es10cGetEid(JNIEnv *env, jobject thiz, jlong
return ret;
}
static jobject to_profile_state(enum es10c_profile_state profile_state) {
switch (profile_state) {
case ES10C_PROFILE_STATE_ENABLED:
return profile_state_enabled;
case ES10C_PROFILE_STATE_DISABLED:
return profile_state_disabled;
default:
return NULL;
}
}
static jobject to_profile_class(enum es10c_profile_class profile_class) {
switch (profile_class) {
case ES10C_PROFILE_CLASS_OPERATIONAL:
return profile_class_operational;
case ES10C_PROFILE_CLASS_PROVISIONING:
return profile_class_provisioning;
case ES10C_PROFILE_CLASS_TEST:
return profile_class_testing;
default:
return NULL;
}
}
JNIEXPORT jlong JNICALL
Java_net_typeblog_lpac_1jni_LpacJni_es10cGetProfilesInfo(
JNIEnv *env,