ソースを参照

feat: alert when confirmation code is required by QR code

Closes #136

Co-authored-by: septs <github@septs.pw>
septs 1 年間 前
コミット
f5074acae2

+ 16 - 7
app-common/src/main/java/im/angry/openeuicc/ui/wizard/DownloadWizardMethodSelectFragment.kt

@@ -124,9 +124,22 @@ class DownloadWizardMethodSelectFragment : DownloadWizardActivity.DownloadWizard
         processLpaString(text.toString())
         processLpaString(text.toString())
     }
     }
 
 
-    private fun processLpaString(s: String) {
-        val components = s.split("$")
-        if (components.size < 3 || components[0] != "LPA:1") {
+    private fun processLpaString(input: String) {
+        try {
+            val parsed = ActivationCode.fromString(input)
+            state.smdp = parsed.address
+            state.matchingId = parsed.matchingId
+            if (parsed.confirmationCodeRequired) {
+                AlertDialog.Builder(requireContext()).apply {
+                    setTitle(R.string.profile_download_required_confirmation_code)
+                    setMessage(R.string.profile_download_required_confirmation_code_message)
+                    setCancelable(true)
+                    setPositiveButton(android.R.string.ok, null)
+                    show()
+                }
+            }
+            gotoNextFragment(DownloadWizardDetailsFragment())
+        } catch (e: IllegalArgumentException) {
             AlertDialog.Builder(requireContext()).apply {
             AlertDialog.Builder(requireContext()).apply {
                 setTitle(R.string.profile_download_incorrect_lpa_string)
                 setTitle(R.string.profile_download_incorrect_lpa_string)
                 setMessage(R.string.profile_download_incorrect_lpa_string_message)
                 setMessage(R.string.profile_download_incorrect_lpa_string_message)
@@ -134,11 +147,7 @@ class DownloadWizardMethodSelectFragment : DownloadWizardActivity.DownloadWizard
                 setNegativeButton(android.R.string.cancel, null)
                 setNegativeButton(android.R.string.cancel, null)
                 show()
                 show()
             }
             }
-            return
         }
         }
-        state.smdp = components[1]
-        state.matchingId = components[2]
-        gotoNextFragment(DownloadWizardDetailsFragment())
     }
     }
 
 
     private class DownloadMethodViewHolder(private val root: View) : ViewHolder(root) {
     private class DownloadMethodViewHolder(private val root: View) : ViewHolder(root) {

+ 23 - 0
app-common/src/main/java/im/angry/openeuicc/util/ActivationCode.kt

@@ -0,0 +1,23 @@
+package im.angry.openeuicc.util
+
+data class ActivationCode(
+    val address: String,
+    val matchingId: String? = null,
+    val oid: String? = null,
+    val confirmationCodeRequired: Boolean = false,
+) {
+    companion object {
+        fun fromString(input: String): ActivationCode {
+            val components = input.removePrefix("LPA:").split('$')
+            if (components.size < 2 || components[0] != "1") {
+                throw IllegalArgumentException("Invalid activation code format")
+            }
+            return ActivationCode(
+                address = components[1].trim(),
+                matchingId = components.getOrNull(2)?.trim()?.ifBlank { null },
+                oid = components.getOrNull(3)?.trim()?.ifBlank { null },
+                confirmationCodeRequired = components.getOrNull(4)?.trim() == "1"
+            )
+        }
+    }
+}

+ 2 - 0
app-common/src/main/res/values-ja/strings.xml

@@ -144,4 +144,6 @@
     <string name="profile_class_testing">テスティング</string>
     <string name="profile_class_testing">テスティング</string>
     <string name="profile_class_provisioning">準備中</string>
     <string name="profile_class_provisioning">準備中</string>
     <string name="profile_class_operational">動作中</string>
     <string name="profile_class_operational">動作中</string>
+    <string name="profile_download_required_confirmation_code">要確認コード</string>
+    <string name="profile_download_required_confirmation_code_message">スキャンされた QR コード、又はクリップボードからペーストされた LPA コードには、確認コードの必要が表示されています。</string>
 </resources>
 </resources>

+ 2 - 0
app-common/src/main/res/values-zh-rCN/strings.xml

@@ -144,4 +144,6 @@
     <string name="pref_developer_ignore_tls_certificate">无视 SM-DP+ 的 TLS 证书</string>
     <string name="pref_developer_ignore_tls_certificate">无视 SM-DP+ 的 TLS 证书</string>
     <string name="pref_developer_ignore_tls_certificate_desc">允许 RSP 服务器使用任意证书</string>
     <string name="pref_developer_ignore_tls_certificate_desc">允许 RSP 服务器使用任意证书</string>
     <string name="information_unavailable">无信息</string>
     <string name="information_unavailable">无信息</string>
+    <string name="profile_download_required_confirmation_code">需要确认码</string>
+    <string name="profile_download_required_confirmation_code_message">您扫描的二维码或粘贴的 LPA 码需要一个额外的确认码</string>
 </resources>
 </resources>

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

@@ -57,6 +57,8 @@
     <string name="profile_download_low_nvram_title">This download may fail</string>
     <string name="profile_download_low_nvram_title">This download may fail</string>
     <string name="profile_download_low_nvram_message">This download may fail due to low remaining capacity.</string>
     <string name="profile_download_low_nvram_message">This download may fail due to low remaining capacity.</string>
     <string name="profile_download_no_lpa_string">No LPA code found in clipboard</string>
     <string name="profile_download_no_lpa_string">No LPA code found in clipboard</string>
+    <string name="profile_download_required_confirmation_code">Confirmation Code Required</string>
+    <string name="profile_download_required_confirmation_code_message">Please provide a confirmation code as required by the scanned QR code or LPA code from clipboard.</string>
     <string name="profile_download_incorrect_lpa_string">Unable to parse</string>
     <string name="profile_download_incorrect_lpa_string">Unable to parse</string>
     <string name="profile_download_incorrect_lpa_string_message">Could not parse QR code or clipboard content as a LPA code.</string>
     <string name="profile_download_incorrect_lpa_string_message">Could not parse QR code or clipboard content as a LPA code.</string>