diff --git a/libs/lpac-jni/src/main/jni/lpac-jni/lpac-download.c b/libs/lpac-jni/src/main/jni/lpac-jni/lpac-download.c index 7753e15..364c7c8 100644 --- a/libs/lpac-jni/src/main/jni/lpac-jni/lpac-download.c +++ b/libs/lpac-jni/src/main/jni/lpac-jni/lpac-download.c @@ -60,19 +60,14 @@ void lpac_download_init() { set_cancelled = (*env)->GetMethodID(env, download_callback_class, "setCancelled", "(Z)V"); } -#define IS_CANCELLED (*env)->CallBooleanMethod(env, callback, is_cancelled) +#define IS_CANCELLED (*env)->CallBooleanMethod(env, callback, is_cancelled) == JNI_TRUE +#define SET_CANCELLED(VALUE) (*env)->CallVoidMethod(env, callback, set_cancelled, VALUE) JNIEXPORT jint JNICALL -Java_net_typeblog_lpac_1jni_LpacJni_downloadProfile( - JNIEnv *env, - __attribute__((unused)) jobject thiz, - jlong handle, - jstring smdp, - jstring matching_id, - jstring imei, - jstring confirmation_code, - jobject callback -) { +Java_net_typeblog_lpac_1jni_LpacJni_downloadProfile(JNIEnv *env, jobject thiz, jlong handle, + jstring smdp, jstring matching_id, + jstring imei, jstring confirmation_code, + jobject callback) { struct euicc_ctx *ctx = (struct euicc_ctx *) handle; struct es10b_load_bound_profile_package_result es10b_load_bound_profile_package_result; const char *_confirmation_code = NULL; @@ -91,11 +86,10 @@ Java_net_typeblog_lpac_1jni_LpacJni_downloadProfile( ctx->http.server_address = _smdp; - if (IS_CANCELLED) { // callback.isCancelled() + if (IS_CANCELLED) { ret = -ES10B_ERROR_REASON_UNDEFINED; goto out; } - // callback.onStateUpdate(DownloadState.Preparing) (*env)->CallVoidMethod(env, callback, on_state_update, download_state_preparing); ret = es10b_get_euicc_challenge_and_info(ctx); syslog(LOG_INFO, "es10b_get_euicc_challenge_and_info %d", ret); @@ -104,12 +98,10 @@ Java_net_typeblog_lpac_1jni_LpacJni_downloadProfile( goto out; } - - if (IS_CANCELLED) { // callback.isCancelled() + if (IS_CANCELLED) { ret = -ES10B_ERROR_REASON_UNDEFINED; goto out; } - // callback.onStateUpdate(DownloadState.Connecting) (*env)->CallVoidMethod(env, callback, on_state_update, download_state_connecting); ret = es9p_initiate_authentication(ctx); syslog(LOG_INFO, "es9p_initiate_authentication %d", ret); @@ -118,11 +110,10 @@ Java_net_typeblog_lpac_1jni_LpacJni_downloadProfile( goto out; } - if (IS_CANCELLED) { // callback.isCancelled() + if (IS_CANCELLED) { ret = -ES10B_ERROR_REASON_UNDEFINED; goto out; } - // callback.onStateUpdate(DownloadState.Authenticating) (*env)->CallVoidMethod(env, callback, on_state_update, download_state_authenticating); ret = es10b_authenticate_server(ctx, _matching_id, _imei); syslog(LOG_INFO, "es10b_authenticate_server %d", ret); @@ -131,7 +122,7 @@ Java_net_typeblog_lpac_1jni_LpacJni_downloadProfile( goto out; } - if (IS_CANCELLED) { // callback.isCancelled() + if (IS_CANCELLED) { ret = -ES10B_ERROR_REASON_UNDEFINED; goto out; } @@ -142,11 +133,10 @@ Java_net_typeblog_lpac_1jni_LpacJni_downloadProfile( goto out; } - if (IS_CANCELLED) { // callback.isCancelled() + if (IS_CANCELLED) { ret = -ES10B_ERROR_REASON_UNDEFINED; goto out; } - // callback.onStateUpdate(DownloadState.Downloading) (*env)->CallVoidMethod(env, callback, on_state_update, download_state_downloading); ret = es10b_prepare_download(ctx, _confirmation_code); syslog(LOG_INFO, "es10b_prepare_download %d", ret); @@ -155,7 +145,7 @@ Java_net_typeblog_lpac_1jni_LpacJni_downloadProfile( goto out; } - if (IS_CANCELLED) { // callback.isCancelled() + if (IS_CANCELLED) { ret = -ES10B_ERROR_REASON_UNDEFINED; goto out; } @@ -164,11 +154,10 @@ Java_net_typeblog_lpac_1jni_LpacJni_downloadProfile( if (ret < 0) goto out; - if (IS_CANCELLED) { // callback.isCancelled() + if (IS_CANCELLED) { ret = -ES10B_ERROR_REASON_UNDEFINED; goto out; } - // callback.onStateUpdate(DownloadState.Finalizing) (*env)->CallVoidMethod(env, callback, on_state_update, download_state_finalizing); ret = es10b_load_bound_profile_package(ctx, &es10b_load_bound_profile_package_result); syslog(LOG_INFO, "es10b_load_bound_profile_package %d, reason %d", ret, es10b_load_bound_profile_package_result.errorReason); @@ -181,7 +170,7 @@ Java_net_typeblog_lpac_1jni_LpacJni_downloadProfile( out: if (IS_CANCELLED == 0 && ret == -ES10B_ERROR_REASON_UNDEFINED) { - (*env)->CallVoidMethod(env, callback, set_cancelled, JNI_TRUE); + SET_CANCELLED(JNI_TRUE); } // We expect Java side to call cancelSessions after any error -- thus, `euicc_http_cleanup` is done there // This is so that Java side can access the last HTTP and/or APDU errors when we return.