瀏覽代碼

lpac-jni: Make most argumengts to downloadProfile optional

Peter Cai 2 年之前
父節點
當前提交
3ae1e0015f

+ 2 - 1
app/src/main/java/im/angry/openeuicc/ui/ProfileDownloadFragment.kt

@@ -114,6 +114,7 @@ class ProfileDownloadFragment : DialogFragment(), EuiccFragmentMarker, Toolbar.O
         }
 
         val code = profileDownloadCode.editText!!.text.toString().trim()
+            .ifBlank { null }
         val confirmationCode = profileDownloadConfirmationCode.editText!!.text.toString().trim()
             .ifBlank { null }
 
@@ -141,7 +142,7 @@ class ProfileDownloadFragment : DialogFragment(), EuiccFragmentMarker, Toolbar.O
         }
     }
 
-    private suspend fun doDownloadProfile(server: String, code: String, confirmationCode: String?) = withContext(Dispatchers.IO) {
+    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) {

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

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

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

@@ -23,6 +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,
+    external fun downloadProfile(handle: Long, smdp: String, matchingId: String?, imei: String?,
                                  confirmationCode: String?, callback: ProfileDownloadCallback): Int
 }

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

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

+ 8 - 4
libs/lpac-jni/src/main/jni/lpac-jni/lpac-download.c

@@ -60,9 +60,11 @@ Java_net_typeblog_lpac_1jni_LpacJni_downloadProfile(JNIEnv *env, jobject thiz, j
 
     if (confirmation_code != NULL)
         _confirmation_code = (*env)->GetStringUTFChars(env, confirmation_code, NULL);
-    _matching_id = (*env)->GetStringUTFChars(env, matching_id, NULL);
+    if (matching_id != NULL)
+        _matching_id = (*env)->GetStringUTFChars(env, matching_id, NULL);
     _smdp = (*env)->GetStringUTFChars(env, smdp, NULL);
-    _imei = (*env)->GetStringUTFChars(env, imei, NULL);
+    if (imei != NULL)
+        _imei = (*env)->GetStringUTFChars(env, imei, NULL);
 
     (*env)->CallVoidMethod(env, callback, on_state_update, download_state_preparing);
     ret = es10b_get_euicc_challenge(ctx, &b64_euicc_challenge);
@@ -122,8 +124,10 @@ out:
     free(transaction_id);
     if (_confirmation_code != NULL)
         (*env)->ReleaseStringUTFChars(env, confirmation_code, _confirmation_code);
-    (*env)->ReleaseStringUTFChars(env, matching_id, _matching_id);
+    if (_matching_id != NULL)
+        (*env)->ReleaseStringUTFChars(env, matching_id, _matching_id);
     (*env)->ReleaseStringUTFChars(env, smdp, _smdp);
-    (*env)->ReleaseStringUTFChars(env, imei, _imei);
+    if (_imei != NULL)
+        (*env)->ReleaseStringUTFChars(env, imei, _imei);
     return ret;
 }