ソースを参照

lpac-jni: Implement confirmation code support

Peter Cai 2 年 前
コミット
bea5aa0dcf

+ 7 - 3
app/src/main/java/im/angry/openeuicc/ui/ProfileDownloadFragment.kt

@@ -31,6 +31,7 @@ class ProfileDownloadFragment : DialogFragment(), EuiccFragmentMarker, Toolbar.O
     private lateinit var toolbar: Toolbar
     private lateinit var profileDownloadServer: TextInputLayout
     private lateinit var profileDownloadCode: TextInputLayout
+    private lateinit var profileDownloadConfirmationCode: TextInputLayout
     private lateinit var progress: ProgressBar
 
     private var downloading = false
@@ -55,6 +56,7 @@ class ProfileDownloadFragment : DialogFragment(), EuiccFragmentMarker, Toolbar.O
         toolbar = view.findViewById(R.id.toolbar)
         profileDownloadServer = view.findViewById(R.id.profile_download_server)
         profileDownloadCode = view.findViewById(R.id.profile_download_code)
+        profileDownloadConfirmationCode = view.findViewById(R.id.profile_download_confirmation_code)
         progress = view.findViewById(R.id.progress)
 
         toolbar.inflateMenu(R.menu.fragment_profile_download)
@@ -112,6 +114,8 @@ class ProfileDownloadFragment : DialogFragment(), EuiccFragmentMarker, Toolbar.O
         }
 
         val code = profileDownloadCode.editText!!.text.toString().trim()
+        val confirmationCode = profileDownloadConfirmationCode.editText!!.text.toString().trim()
+            .ifBlank { null }
 
         downloading = true
 
@@ -123,7 +127,7 @@ class ProfileDownloadFragment : DialogFragment(), EuiccFragmentMarker, Toolbar.O
 
         lifecycleScope.launch {
             try {
-                doDownloadProfile(server, code)
+                doDownloadProfile(server, code, confirmationCode)
             } catch (e: Exception) {
                 Log.d(TAG, "Error downloading profile")
                 Log.d(TAG, Log.getStackTraceString(e))
@@ -137,8 +141,8 @@ class ProfileDownloadFragment : DialogFragment(), EuiccFragmentMarker, Toolbar.O
         }
     }
 
-    private suspend fun doDownloadProfile(server: String, code: String) = withContext(Dispatchers.IO) {
-        channel.lpa.downloadProfile(server, code, channel.imei, object : ProfileDownloadCallback {
+    private suspend fun doDownloadProfile(server: String, code: String, confirmationCode: String?) = withContext(Dispatchers.IO) {
+        channel.lpa.downloadProfile(server, code, channel.imei, confirmationCode, object : ProfileDownloadCallback {
             override fun onStateUpdate(state: ProfileDownloadCallback.DownloadState) {
                 lifecycleScope.launch(Dispatchers.Main) {
                     progress.isIndeterminate = false

+ 19 - 0
app/src/main/res/layout/fragment_profile_download.xml

@@ -66,6 +66,25 @@
         app:layout_constraintTop_toBottomOf="@id/profile_download_server"
         app:layout_constraintLeft_toLeftOf="parent"
         app:layout_constraintRight_toRightOf="parent"
+        app:layout_constraintWidth_percent=".8">
+
+        <com.google.android.material.textfield.TextInputEditText
+            android:layout_width="match_parent"
+            android:layout_height="match_parent"
+            android:theme="@style/Theme.OpenEUICC.Input.Cursor"/>
+
+    </com.google.android.material.textfield.TextInputLayout>
+
+    <com.google.android.material.textfield.TextInputLayout
+        android:id="@+id/profile_download_confirmation_code"
+        android:layout_width="0dp"
+        android:layout_height="wrap_content"
+        android:layout_marginVertical="15dp"
+        android:hint="@string/profile_download_confirmation_code"
+        style="@style/Widget.OpenEUICC.Input"
+        app:layout_constraintTop_toBottomOf="@id/profile_download_code"
+        app:layout_constraintLeft_toLeftOf="parent"
+        app:layout_constraintRight_toRightOf="parent"
         app:layout_constraintBottom_toBottomOf="parent"
         app:layout_constraintWidth_percent=".8">
 

+ 1 - 0
app/src/main/res/values/strings.xml

@@ -23,6 +23,7 @@
     <string name="profile_download">New eSIM</string>
     <string name="profile_download_server">Server (RSP / SM-DP+)</string>
     <string name="profile_download_code">Activation Code</string>
+    <string name="profile_download_confirmation_code">Confirmation Code (Optional)</string>
     <string name="profile_download_scan">Scan QR Code</string>
     <string name="profile_download_ok">Download</string>
     <string name="profile_download_failed">Failed to download eSIM. Check your activation / QR code.</string>

+ 2 - 1
libs/lpac-jni/src/main/java/net/typeblog/lpac_jni/LocalProfileAssistant.kt

@@ -8,7 +8,8 @@ interface LocalProfileAssistant {
     fun disableProfile(iccid: String): Boolean
     fun deleteProfile(iccid: String): Boolean
 
-    fun downloadProfile(smdp: String, matchingId: String, imei: String, callback: ProfileDownloadCallback): Boolean
+    fun downloadProfile(smdp: String, matchingId: String, imei: String,
+                        confirmationCode: String?, callback: ProfileDownloadCallback): Boolean
 
     fun setNickname(
         iccid: String, nickname: String

+ 2 - 1
libs/lpac-jni/src/main/java/net/typeblog/lpac_jni/LpacJni.kt

@@ -23,5 +23,6 @@ internal object LpacJni {
 
     // es9p + es10b
     // We do not expose all of the functions because of tediousness :)
-    external fun downloadProfile(handle: Long, smdp: String, matchingId: String, imei: String, callback: ProfileDownloadCallback): Int
+    external fun downloadProfile(handle: Long, smdp: String, matchingId: String, imei: String,
+                                 confirmationCode: String?, callback: ProfileDownloadCallback): Int
 }

+ 3 - 2
libs/lpac-jni/src/main/java/net/typeblog/lpac_jni/impl/LocalProfileAssistantImpl.kt

@@ -37,8 +37,9 @@ class LocalProfileAssistantImpl(
         return LpacJni.es10cDeleteProfile(contextHandle, iccid) == 0
     }
 
-    override fun downloadProfile(smdp: String, matchingId: String, imei: String, callback: ProfileDownloadCallback): Boolean {
-        return LpacJni.downloadProfile(contextHandle, smdp, matchingId, imei, callback) == 0
+    override fun downloadProfile(smdp: String, matchingId: String, imei: String,
+                                 confirmationCode: String?, callback: ProfileDownloadCallback): Boolean {
+        return LpacJni.downloadProfile(contextHandle, smdp, matchingId, imei, confirmationCode, callback) == 0
     }
 
     override fun setNickname(iccid: String, nickname: String): Boolean {

+ 9 - 2
libs/lpac-jni/src/main/jni/lpac-jni/lpac-download.c

@@ -38,7 +38,8 @@ void lpac_download_init() {
 
 JNIEXPORT jint JNICALL
 Java_net_typeblog_lpac_1jni_LpacJni_downloadProfile(JNIEnv *env, jobject thiz, jlong handle,
-                                                    jstring smdp, jstring matching_id, jstring imei,
+                                                    jstring smdp, jstring matching_id,
+                                                    jstring imei, jstring confirmation_code,
                                                     jobject callback) {
     struct euicc_ctx *ctx = (struct euicc_ctx *) handle;
     struct es9p_get_bound_profile_package_resp es9p_get_bound_profile_package_resp;
@@ -51,11 +52,14 @@ Java_net_typeblog_lpac_1jni_LpacJni_downloadProfile(JNIEnv *env, jobject thiz, j
     char *b64_euicc_challenge = NULL;
     char *b64_euicc_info_1 = NULL;
     char *transaction_id = NULL;
+    const char *_confirmation_code = NULL;
     const char *_matching_id = NULL;
     const char *_smdp = NULL;
     const char *_imei = NULL;
     int ret;
 
+    if (confirmation_code != NULL)
+        _confirmation_code = (*env)->GetStringUTFChars(env, confirmation_code, NULL);
     _matching_id = (*env)->GetStringUTFChars(env, matching_id, NULL);
     _smdp = (*env)->GetStringUTFChars(env, smdp, NULL);
     _imei = (*env)->GetStringUTFChars(env, imei, NULL);
@@ -95,7 +99,8 @@ Java_net_typeblog_lpac_1jni_LpacJni_downloadProfile(JNIEnv *env, jobject thiz, j
     es10b_prepare_download_param.b64_smdp_signed_2 = es9p_authenticate_client_resp.b64_smdp_signed_2;
     es10b_prepare_download_param.b64_smdp_signature_2 = es9p_authenticate_client_resp.b64_smdp_signature_2;
     es10b_prepare_download_param.b64_smdp_certificate = es9p_authenticate_client_resp.b64_smdp_certificate;
-    es10b_prepare_download_param.str_checkcode = NULL; // TODO: Support confirmation code
+    es10b_prepare_download_param.hexstr_transcation_id = transaction_id;
+    es10b_prepare_download_param.str_checkcode = _confirmation_code;
 
     (*env)->CallVoidMethod(env, callback, on_state_update, download_state_downloading);
     ret = es10b_prepare_download(ctx, &b64_prepare_download_response, &es10b_prepare_download_param);
@@ -115,6 +120,8 @@ out:
     free(b64_euicc_info_1);
     free(b64_euicc_challenge);
     free(transaction_id);
+    if (_confirmation_code != NULL)
+        (*env)->ReleaseStringUTFChars(env, confirmation_code, _confirmation_code);
     (*env)->ReleaseStringUTFChars(env, matching_id, _matching_id);
     (*env)->ReleaseStringUTFChars(env, smdp, _smdp);
     (*env)->ReleaseStringUTFChars(env, imei, _imei);