Compare commits

..

11 commits

Author SHA1 Message Date
1ca48699a8
chore: detect connection reset 2025-07-17 13:56:51 +08:00
2667e2340b
chore: enhance error handling 2025-07-17 13:28:04 +08:00
1e8f782ca9
chore: improve http resposne handling 2025-07-17 13:14:01 +08:00
52e24fb321
chore: add strings 2025-07-16 23:17:22 +08:00
b2a9ee65c5
chore: add strings 2025-07-16 23:16:28 +08:00
e5693d80cf
chore: add strings 2025-07-16 22:45:19 +08:00
2f1efffe31
chore: improve error handling 2025-07-16 17:41:49 +08:00
fe7b5300e3
chore: add strings 2025-07-16 13:04:39 +08:00
7a1eeca65a
fix: http exc handling 2025-07-16 01:50:36 +08:00
f21577a377
fix: comment 2025-07-16 01:32:16 +08:00
54d546665f
feat: simplified error handling 2025-07-16 01:31:06 +08:00
2 changed files with 71 additions and 3 deletions

View file

@ -8,7 +8,6 @@ import android.view.ViewGroup
import android.widget.TextView import android.widget.TextView
import im.angry.openeuicc.common.R import im.angry.openeuicc.common.R
import im.angry.openeuicc.util.* import im.angry.openeuicc.util.*
import org.json.JSONObject
import java.util.Date import java.util.Date
class DownloadWizardDiagnosticsFragment : DownloadWizardActivity.DownloadWizardStepFragment() { class DownloadWizardDiagnosticsFragment : DownloadWizardActivity.DownloadWizardStepFragment() {
@ -87,10 +86,9 @@ class DownloadWizardDiagnosticsFragment : DownloadWizardActivity.DownloadWizardS
ret.appendLine() ret.appendLine()
val str = resp.data.decodeToString(throwOnInvalidSequence = false) val str = resp.data.decodeToString(throwOnInvalidSequence = false)
ret.appendLine( ret.appendLine(
if (str.startsWith('{')) { if (str.startsWith('{')) {
JSONObject(str).toString(2) str.prettyPrintJson()
} else { } else {
str str
} }

View file

@ -41,3 +41,73 @@ fun parseIsdrAidList(s: String): List<ByteArray> =
.filter(String::isNotEmpty) .filter(String::isNotEmpty)
.mapNotNull { runCatching(it::decodeHex).getOrNull() } .mapNotNull { runCatching(it::decodeHex).getOrNull() }
.ifEmpty { listOf(EUICC_DEFAULT_ISDR_AID.decodeHex()) } .ifEmpty { listOf(EUICC_DEFAULT_ISDR_AID.decodeHex()) }
fun String.prettyPrintJson(): String {
val ret = StringBuilder()
var inQuotes = false
var escaped = false
val indentSymbolStack = ArrayDeque<Char>()
val addNewLine = {
ret.append('\n')
repeat(indentSymbolStack.size) {
ret.append('\t')
}
}
var lastChar = ' '
for (c in this) {
when {
!inQuotes && (c == '{' || c == '[') -> {
ret.append(c)
indentSymbolStack.addLast(c)
addNewLine()
}
!inQuotes && (c == '}' || c == ']') -> {
indentSymbolStack.removeLast()
if (lastChar != ',') {
addNewLine()
}
ret.append(c)
}
!inQuotes && c == ',' -> {
ret.append(c)
addNewLine()
}
!inQuotes && c == ':' -> {
ret.append(c)
ret.append(' ')
}
inQuotes && c == '\\' -> {
ret.append(c)
escaped = true
continue
}
!escaped && c == '"' -> {
ret.append(c)
inQuotes = !inQuotes
}
!inQuotes && c == ' ' -> {
// Do nothing -- we ignore spaces outside of quotes by default
// This is to ensure predictable formatting
}
else -> ret.append(c)
}
if (escaped) {
escaped = false
}
lastChar = c
}
return ret.toString()
}