From c6de599db0825b0ed15c4ce6702639ecd6cbba7f Mon Sep 17 00:00:00 2001 From: Peter Cai Date: Sun, 1 Dec 2024 17:08:09 -0500 Subject: [PATCH 1/4] lpac-jni: Cancel es9p/10b sessions on download failure --- .idea/compiler.xml | 12 +----------- .../src/main/java/net/typeblog/lpac_jni/LpacJni.kt | 2 ++ .../lpac_jni/impl/LocalProfileAssistantImpl.kt | 8 +++++++- libs/lpac-jni/src/main/jni/lpac-jni/lpac-download.c | 12 +++++++++++- 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/.idea/compiler.xml b/.idea/compiler.xml index 61f4db4..1c5ab05 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -1,16 +1,6 @@ - - - - - - - - - - - + \ No newline at end of file diff --git a/libs/lpac-jni/src/main/java/net/typeblog/lpac_jni/LpacJni.kt b/libs/lpac-jni/src/main/java/net/typeblog/lpac_jni/LpacJni.kt index f9a2f90..1e64c69 100644 --- a/libs/lpac-jni/src/main/java/net/typeblog/lpac_jni/LpacJni.kt +++ b/libs/lpac-jni/src/main/java/net/typeblog/lpac_jni/LpacJni.kt @@ -30,6 +30,8 @@ internal object LpacJni { external fun downloadProfile(handle: Long, smdp: String, matchingId: String?, imei: String?, confirmationCode: String?, callback: ProfileDownloadCallback): Int external fun handleNotification(handle: Long, seqNumber: Long): Int + // Cancel any ongoing es9p and/or es10b sessions + external fun cancelSessions(handle: Long) // es10cex (actually part of es10b) external fun es10cexGetEuiccInfo2(handle: Long): Long diff --git a/libs/lpac-jni/src/main/java/net/typeblog/lpac_jni/impl/LocalProfileAssistantImpl.kt b/libs/lpac-jni/src/main/java/net/typeblog/lpac_jni/impl/LocalProfileAssistantImpl.kt index 70606d9..4dbb181 100644 --- a/libs/lpac-jni/src/main/java/net/typeblog/lpac_jni/impl/LocalProfileAssistantImpl.kt +++ b/libs/lpac-jni/src/main/java/net/typeblog/lpac_jni/impl/LocalProfileAssistantImpl.kt @@ -212,12 +212,18 @@ class LocalProfileAssistantImpl( ) if (res != 0) { - throw LocalProfileAssistant.ProfileDownloadException( + // Construct the error now to store any error information we _can_ access + val err = LocalProfileAssistant.ProfileDownloadException( httpInterface.lastHttpResponse, httpInterface.lastHttpException, apduInterface.lastApduResponse, apduInterface.lastApduException, ) + + // Cancel sessions if possible. This will overwrite recorded errors from HTTP and APDU interfaces. + LpacJni.cancelSessions(contextHandle) + + throw err } } 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 91676da..8910170 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 @@ -117,7 +117,8 @@ Java_net_typeblog_lpac_1jni_LpacJni_downloadProfile(JNIEnv *env, jobject thiz, j syslog(LOG_INFO, "es10b_load_bound_profile_package %d, reason %d", ret, es10b_load_bound_profile_package_result.errorReason); out: - euicc_http_cleanup(ctx); + // 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. if (_confirmation_code != NULL) (*env)->ReleaseStringUTFChars(env, confirmation_code, _confirmation_code); if (_matching_id != NULL) @@ -127,3 +128,12 @@ Java_net_typeblog_lpac_1jni_LpacJni_downloadProfile(JNIEnv *env, jobject thiz, j (*env)->ReleaseStringUTFChars(env, imei, _imei); return ret; } + + +JNIEXPORT void JNICALL +Java_net_typeblog_lpac_1jni_LpacJni_cancelSessions(JNIEnv *env, jobject thiz, jlong handle) { + struct euicc_ctx *ctx = (struct euicc_ctx *) handle; + es9p_cancel_session(ctx); + es10b_cancel_session(ctx, ES10B_CANCEL_SESSION_REASON_UNDEFINED); + euicc_http_cleanup(ctx); +} \ No newline at end of file From f74145d0b770d2f93d4fcdc4a41957216b607851 Mon Sep 17 00:00:00 2001 From: Peter Cai Date: Sun, 1 Dec 2024 17:15:51 -0500 Subject: [PATCH 2/4] i18n: Update new strings --- app-common/src/main/res/values-ja/strings.xml | 4 ++++ app-common/src/main/res/values/strings.xml | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app-common/src/main/res/values-ja/strings.xml b/app-common/src/main/res/values-ja/strings.xml index 72b88a8..de9465f 100644 --- a/app-common/src/main/res/values-ja/strings.xml +++ b/app-common/src/main/res/values-ja/strings.xml @@ -136,4 +136,8 @@ 情報 アプリバージョン ソースコード + 言語 + アプリの言語を選択 + すべてのプロファイルを表示 + プロダクション以外のプロファイルも表示する diff --git a/app-common/src/main/res/values/strings.xml b/app-common/src/main/res/values/strings.xml index 174b18c..d0813d2 100644 --- a/app-common/src/main/res/values/strings.xml +++ b/app-common/src/main/res/values/strings.xml @@ -147,14 +147,14 @@ Verbose Logging Enable verbose logs, which may contain sensitive information. Only share your logs with someone you trust after turning this on. Language - Select current language + Select app language Logs View recent debug logs of the application Developer Options Experimental Download Wizard Enable the experimental new download wizard. Note that it is not fully working yet. Show unfiltered profile list - Display any profile class in the list + Include non-production profiles in the list Ignore SM-DP+ TLS certificate Ignore SM-DP+ TLS certificate, allow any RSP Info From afeb5c52827477f891f7c5f1413cf5dc67155b79 Mon Sep 17 00:00:00 2001 From: Peter Cai Date: Sun, 1 Dec 2024 17:22:58 -0500 Subject: [PATCH 3/4] i18n: Fixup Japanese translation for notification types ~ing in the en text means the action itself, not the process. --- app-common/src/main/res/values-ja/strings.xml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app-common/src/main/res/values-ja/strings.xml b/app-common/src/main/res/values-ja/strings.xml index de9465f..925a5a2 100644 --- a/app-common/src/main/res/values-ja/strings.xml +++ b/app-common/src/main/res/values-ja/strings.xml @@ -114,13 +114,13 @@ あなたは開発者になりました! 設定 通知 - eSIM のプロファイル操作により、通信事業者に通知が送信されます。必要に応じてこの動作を微調整できます。 + eSIM のプロファイル操作により、通信事業者に通知が送信されます。ここでは、どのタイプの通知を送信するのかを微調整できます。 ダウンロード - プロファイルをダウンロード中の通知を送信します + プロファイルのダウンロード済みの通知を送信します 削除 - プロファイルを削除中の通知を送信します - 切り替え中 - プロファイルを切り替え中の通知を送信します\nこのタイプの通知は信頼できないことに注意してください。 + プロファイルの削除済みの通知を送信します + 切り替え + プロファイルの切り替え済みの通知を送信します\nこのタイプの通知は有効化しても必ず送信するとは限らないことに注意してください。 高度な設定 有効なプロファイルの無効化と削除を許可する デフォルトでは、このアプリでデバイスに挿入された取り外し可能な eSIM の有効なプロファイルを無効化することを防いでいます。なぜなのかというと時々アクセスができなくなるからです。\nこのチェックボックスを ON にすることで、この保護機能を解除します。 From 78bf3612eeb5aebd5525979ea4d23e1f23064de0 Mon Sep 17 00:00:00 2001 From: Peter Cai Date: Sun, 1 Dec 2024 18:47:58 -0500 Subject: [PATCH 4/4] lpac-jni: Expose error reason as return value --- .../src/main/jni/lpac-jni/lpac-download.c | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) 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 8910170..f63585a 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 @@ -82,39 +82,51 @@ Java_net_typeblog_lpac_1jni_LpacJni_downloadProfile(JNIEnv *env, jobject thiz, j (*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); - if (ret < 0) + if (ret < 0) { + ret = -ES10B_ERROR_REASON_UNDEFINED; goto out; + } (*env)->CallVoidMethod(env, callback, on_state_update, download_state_connecting); ret = es9p_initiate_authentication(ctx); syslog(LOG_INFO, "es9p_initiate_authentication %d", ret); - if (ret < 0) + if (ret < 0) { + ret = -ES10B_ERROR_REASON_UNDEFINED; goto out; + } (*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); - if (ret < 0) + if (ret < 0) { + ret = -ES10B_ERROR_REASON_UNDEFINED; goto out; + } ret = es9p_authenticate_client(ctx); - if (ret < 0) + if (ret < 0) { + ret = -ES10B_ERROR_REASON_UNDEFINED; goto out; + } (*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); - if (ret < 0) + if (ret < 0) { + ret = -ES10B_ERROR_REASON_UNDEFINED; goto out; + } ret = es9p_get_bound_profile_package(ctx); if (ret < 0) goto out; (*env)->CallVoidMethod(env, callback, on_state_update, download_state_finalizing); - // TODO: Expose error code as Java-side exceptions? 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); + if (ret < 0) { + ret = - (int) es10b_load_bound_profile_package_result.errorReason; + } out: // We expect Java side to call cancelSessions after any error -- thus, `euicc_http_cleanup` is done there