Compare commits

...

1 commit

Author SHA1 Message Date
48b7f0bfef
feat: stricted imei checking 2025-03-07 05:18:55 +08:00

View file

@ -48,9 +48,8 @@ class DownloadWizardDetailsFragment : DownloadWizardActivity.DownloadWizardStepF
matchingId = view.requireViewById(R.id.profile_download_code)
confirmationCode = view.requireViewById(R.id.profile_download_confirmation_code)
imei = view.requireViewById(R.id.profile_download_imei)
smdp.editText!!.addTextChangedListener {
updateInputCompleteness()
}
smdp.editText!!.addTextChangedListener { updateInputCompleteness() }
imei.editText!!.addTextChangedListener { updateInputCompleteness() }
return view
}
@ -69,7 +68,28 @@ class DownloadWizardDetailsFragment : DownloadWizardActivity.DownloadWizardStepF
}
private fun updateInputCompleteness() {
inputComplete = Patterns.DOMAIN_NAME.matcher(smdp.editText!!.text).matches()
inputComplete = runCatching(::validate).isSuccess
refreshButtons()
}
}
private fun validate() {
check(Patterns.DOMAIN_NAME.matcher(smdp.editText!!.text).matches()) {
"Invalid SM-DP+ address"
}
check(imei.editText!!.text.let { it.isEmpty() || isValidIMEI(it) }) {
"Invalid IMEI"
}
}
}
private fun isValidIMEI(input: CharSequence): Boolean {
if (input.length != 15 || !input.all(Char::isDigit)) return false
fun sumOfDigits(input: Int): Int {
if (input % 2 == 0) return input
return (input * 2).toString().map(Char::digitToInt).sum()
}
val sum = input.dropLast(1).map(Char::digitToInt).sumOf(::sumOfDigits)
return (sum * 9) % 10 == input.last().digitToInt()
}