Compare commits

..

No commits in common. "96bc9865ff8362837f632ac37cc44ca41d66bf80" and "d7214141e681350c4d61809c3945343769775f53" have entirely different histories.

4 changed files with 31 additions and 42 deletions

View file

@ -82,12 +82,12 @@
<string name="download_wizard_progress_step_downloading">Downloading eSIM profile</string>
<string name="download_wizard_progress_step_finalizing">Loading eSIM profile into storage</string>
<string name="download_wizard_diagnostics">Error diagnostics</string>
<string name="download_wizard_diagnostics_last_http_status">Last HTTP status (from server): %d</string>
<string name="download_wizard_diagnostics_last_http_response">Last HTTP response (from server):</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_exception">Last HTTP exception:</string>
<string name="download_wizard_diagnostics_last_apdu_response">Last APDU response (from SIM): %s</string>
<string name="download_wizard_diagnostics_last_apdu_response_success">Last APDU response (from SIM) is successful</string>
<string name="download_wizard_diagnostics_last_apdu_response_fail">Last APDU response (from SIM) is a failure</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>

View file

@ -26,6 +26,20 @@ interface HttpInterface {
}
}
/**
* The last HTTP response we have received from the SM-DP+ server.
*
* This is intended for error diagnosis. However, note that most SM-DP+ servers
* respond with 200 even when there is an error. This needs to be taken into
* account when designing UI.
*/
val lastHttpResponse: HttpResponse?
/**
* The last exception that has been thrown during a HTTP connection
*/
val lastHttpException: Exception?
fun transmit(url: String, tx: ByteArray, headers: Array<String>): HttpResponse
// The LPA is supposed to pass in a list of pkIds supported by the eUICC.
// HttpInterface is responsible for providing TrustManager implementations that

View file

@ -23,6 +23,9 @@ class HttpInterfaceImpl(
private lateinit var trustManagers: Array<TrustManager>
override var lastHttpResponse: HttpInterface.HttpResponse? = null
override var lastHttpException: Exception? = null
override fun transmit(
url: String,
tx: ByteArray,
@ -73,9 +76,16 @@ class HttpInterfaceImpl(
}
}
return HttpInterface.HttpResponse(conn.responseCode, bytes)
return HttpInterface.HttpResponse(conn.responseCode, bytes).also {
lastHttpResponse = it
}
} catch (e: Exception) {
e.printStackTrace()
// Reset response to null because there's no response here
lastHttpResponse = null
lastHttpException = e
throw e
}
}

View file

@ -5,7 +5,6 @@ import net.typeblog.lpac_jni.LpacJni
import net.typeblog.lpac_jni.ApduInterface
import net.typeblog.lpac_jni.EuiccInfo2
import net.typeblog.lpac_jni.HttpInterface
import net.typeblog.lpac_jni.HttpInterface.HttpResponse
import net.typeblog.lpac_jni.LocalProfileAssistant
import net.typeblog.lpac_jni.LocalProfileInfo
import net.typeblog.lpac_jni.LocalProfileNotification
@ -13,7 +12,7 @@ import net.typeblog.lpac_jni.ProfileDownloadCallback
class LocalProfileAssistantImpl(
rawApduInterface: ApduInterface,
rawHttpInterface: HttpInterface
private val httpInterface: HttpInterface
): LocalProfileAssistant {
companion object {
private const val TAG = "LocalProfileAssistantImpl"
@ -30,7 +29,6 @@ class LocalProfileAssistantImpl(
override fun transmit(tx: ByteArray): ByteArray =
try {
apduInterface.transmit(tx).also {
lastApduException = null
lastApduResponse = it
}
} catch (e: Exception) {
@ -40,40 +38,7 @@ class LocalProfileAssistantImpl(
}
}
/**
* Same for HTTP for diagnostics
*/
private class HttpInterfaceWrapper(val httpInterface: HttpInterface) :
HttpInterface by httpInterface {
/**
* The last HTTP response we have received from the SM-DP+ server.
*
* This is intended for error diagnosis. However, note that most SM-DP+ servers
* respond with 200 even when there is an error. This needs to be taken into
* account when designing UI.
*/
var lastHttpResponse: HttpResponse? = null
/**
* The last exception that has been thrown during a HTTP connection
*/
var lastHttpException: Exception? = null
override fun transmit(url: String, tx: ByteArray, headers: Array<String>): HttpResponse =
try {
httpInterface.transmit(url, tx, headers).also {
lastHttpException = null
lastHttpResponse = it
}
} catch (e: Exception) {
lastHttpResponse = null
lastHttpException = e
throw e
}
}
private val apduInterface = ApduInterfaceWrapper(rawApduInterface)
private val httpInterface = HttpInterfaceWrapper(rawHttpInterface)
private var finalized = false
private var contextHandle: Long = LpacJni.createContext(apduInterface, httpInterface)