Compare commits
No commits in common. "d7214141e681350c4d61809c3945343769775f53" and "26d037048d96e3a0bb9dd4c7eadb40f427c0d605" have entirely different histories.
d7214141e6
...
26d037048d
4 changed files with 2 additions and 62 deletions
|
@ -81,35 +81,6 @@ class DownloadWizardDiagnosticsFragment : DownloadWizardActivity.DownloadWizardS
|
||||||
ret.appendLine()
|
ret.appendLine()
|
||||||
}
|
}
|
||||||
|
|
||||||
err.lastApduResponse?.let { resp ->
|
|
||||||
val isSuccess =
|
|
||||||
resp.size >= 2 && resp[resp.size - 2] == 0x90.toByte() && resp[resp.size - 1] == 0x00.toByte()
|
|
||||||
|
|
||||||
if (isSuccess) {
|
|
||||||
ret.appendLine(getString(R.string.download_wizard_diagnostics_last_apdu_response_success))
|
|
||||||
} else {
|
|
||||||
// Only show the full APDU response when it's a failure
|
|
||||||
// Otherwise it's going to get very crammed
|
|
||||||
ret.appendLine(
|
|
||||||
getString(
|
|
||||||
R.string.download_wizard_diagnostics_last_apdu_response,
|
|
||||||
resp.encodeHex()
|
|
||||||
)
|
|
||||||
)
|
|
||||||
ret.appendLine()
|
|
||||||
|
|
||||||
ret.appendLine(getString(R.string.download_wizard_diagnostics_last_apdu_response_fail))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
err.lastApduException?.let { e ->
|
|
||||||
ret.appendLine(getString(R.string.download_wizard_diagnostics_last_apdu_exception))
|
|
||||||
ret.appendLine()
|
|
||||||
ret.appendLine("${e.javaClass.name}: ${e.message}")
|
|
||||||
ret.appendLine(e.stackTrace.joinToString("\n"))
|
|
||||||
ret.appendLine()
|
|
||||||
}
|
|
||||||
|
|
||||||
ret.toString()
|
ret.toString()
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -85,10 +85,6 @@
|
||||||
<string name="download_wizard_diagnostics_last_http_status">Last HTTP status: %d</string>
|
<string name="download_wizard_diagnostics_last_http_status">Last HTTP status: %d</string>
|
||||||
<string name="download_wizard_diagnostics_last_http_response">Last HTTP response:</string>
|
<string name="download_wizard_diagnostics_last_http_response">Last HTTP response:</string>
|
||||||
<string name="download_wizard_diagnostics_last_http_exception">Last HTTP exception:</string>
|
<string name="download_wizard_diagnostics_last_http_exception">Last HTTP exception:</string>
|
||||||
<string name="download_wizard_diagnostics_last_apdu_response">Last APDU response: %s</string>
|
|
||||||
<string name="download_wizard_diagnostics_last_apdu_response_success">Last APDU response is successful</string>
|
|
||||||
<string name="download_wizard_diagnostics_last_apdu_response_fail">Last APDU response is a failure</string>
|
|
||||||
<string name="download_wizard_diagnostics_last_apdu_exception">Last APDU exception:</string>
|
|
||||||
|
|
||||||
<string name="profile_rename_new_name">New nickname</string>
|
<string name="profile_rename_new_name">New nickname</string>
|
||||||
|
|
||||||
|
|
|
@ -3,12 +3,9 @@ package net.typeblog.lpac_jni
|
||||||
import net.typeblog.lpac_jni.HttpInterface.HttpResponse
|
import net.typeblog.lpac_jni.HttpInterface.HttpResponse
|
||||||
|
|
||||||
interface LocalProfileAssistant {
|
interface LocalProfileAssistant {
|
||||||
@Suppress("ArrayInDataClass")
|
|
||||||
data class ProfileDownloadException(
|
data class ProfileDownloadException(
|
||||||
val lastHttpResponse: HttpResponse?,
|
val lastHttpResponse: HttpResponse?,
|
||||||
val lastHttpException: Exception?,
|
val lastHttpException: Exception?,
|
||||||
val lastApduResponse: ByteArray?,
|
|
||||||
val lastApduException: Exception?,
|
|
||||||
) : Exception("Failed to download profile")
|
) : Exception("Failed to download profile")
|
||||||
|
|
||||||
val valid: Boolean
|
val valid: Boolean
|
||||||
|
|
|
@ -11,35 +11,13 @@ import net.typeblog.lpac_jni.LocalProfileNotification
|
||||||
import net.typeblog.lpac_jni.ProfileDownloadCallback
|
import net.typeblog.lpac_jni.ProfileDownloadCallback
|
||||||
|
|
||||||
class LocalProfileAssistantImpl(
|
class LocalProfileAssistantImpl(
|
||||||
rawApduInterface: ApduInterface,
|
private val apduInterface: ApduInterface,
|
||||||
private val httpInterface: HttpInterface
|
private val httpInterface: HttpInterface
|
||||||
): LocalProfileAssistant {
|
): LocalProfileAssistant {
|
||||||
companion object {
|
companion object {
|
||||||
private const val TAG = "LocalProfileAssistantImpl"
|
private const val TAG = "LocalProfileAssistantImpl"
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* A thin wrapper over ApduInterface to acquire exceptions and errors transparently
|
|
||||||
*/
|
|
||||||
private class ApduInterfaceWrapper(val apduInterface: ApduInterface) :
|
|
||||||
ApduInterface by apduInterface {
|
|
||||||
var lastApduResponse: ByteArray? = null
|
|
||||||
var lastApduException: Exception? = null
|
|
||||||
|
|
||||||
override fun transmit(tx: ByteArray): ByteArray =
|
|
||||||
try {
|
|
||||||
apduInterface.transmit(tx).also {
|
|
||||||
lastApduResponse = it
|
|
||||||
}
|
|
||||||
} catch (e: Exception) {
|
|
||||||
lastApduResponse = null
|
|
||||||
lastApduException = e
|
|
||||||
throw e
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private val apduInterface = ApduInterfaceWrapper(rawApduInterface)
|
|
||||||
|
|
||||||
private var finalized = false
|
private var finalized = false
|
||||||
private var contextHandle: Long = LpacJni.createContext(apduInterface, httpInterface)
|
private var contextHandle: Long = LpacJni.createContext(apduInterface, httpInterface)
|
||||||
|
|
||||||
|
@ -179,9 +157,7 @@ class LocalProfileAssistantImpl(
|
||||||
if (res != 0) {
|
if (res != 0) {
|
||||||
throw LocalProfileAssistant.ProfileDownloadException(
|
throw LocalProfileAssistant.ProfileDownloadException(
|
||||||
httpInterface.lastHttpResponse,
|
httpInterface.lastHttpResponse,
|
||||||
httpInterface.lastHttpException,
|
httpInterface.lastHttpException
|
||||||
apduInterface.lastApduResponse,
|
|
||||||
apduInterface.lastApduException,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue