feat: alert when confirmation code is required by QR code
All checks were successful
/ build-debug (push) Successful in 5m29s

Closes #136

Co-authored-by: septs <github@septs.pw>
This commit is contained in:
septs 2025-02-04 22:02:58 -05:00 committed by Peter Cai
parent bcd1295a18
commit f5074acae2
5 changed files with 45 additions and 7 deletions

View file

@ -124,9 +124,22 @@ class DownloadWizardMethodSelectFragment : DownloadWizardActivity.DownloadWizard
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 {
setTitle(R.string.profile_download_incorrect_lpa_string)
setMessage(R.string.profile_download_incorrect_lpa_string_message)
@ -134,11 +147,7 @@ class DownloadWizardMethodSelectFragment : DownloadWizardActivity.DownloadWizard
setNegativeButton(android.R.string.cancel, null)
show()
}
return
}
state.smdp = components[1]
state.matchingId = components[2]
gotoNextFragment(DownloadWizardDetailsFragment())
}
private class DownloadMethodViewHolder(private val root: View) : ViewHolder(root) {

View file

@ -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"
)
}
}
}

View file

@ -144,4 +144,6 @@
<string name="profile_class_testing">テスティング</string>
<string name="profile_class_provisioning">準備中</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>

View file

@ -144,4 +144,6 @@
<string name="pref_developer_ignore_tls_certificate">无视 SM-DP+ 的 TLS 证书</string>
<string name="pref_developer_ignore_tls_certificate_desc">允许 RSP 服务器使用任意证书</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>

View file

@ -57,6 +57,8 @@
<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_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_message">Could not parse QR code or clipboard content as a LPA code.</string>