This commit is contained in:
septs 2024-12-18 21:10:01 +08:00
parent 5988d57735
commit 77a46d5ac6
Signed by: septs
SSH key fingerprint: SHA256:ElK0p6DNkbsqYUdJ3I9QHDVf21SQD0c2r+hd7s/r5Co
8 changed files with 25 additions and 16 deletions

View file

@ -26,12 +26,12 @@ class OmapiApduInterface(
override val valid: Boolean
get() = service.isConnected && (this::session.isInitialized && !session.isClosed)
override var atr: ByteArray? = null
private set
override fun readATR(): ByteArray {
return session.atr?.clone() ?: throw IllegalStateException("atr unavailable")
}
override fun connect() {
session = service.getUiccReaderCompat(port.logicalSlotIndex + 1).openSession()
atr = session.atr?.clone()
}
override fun disconnect() {

View file

@ -101,7 +101,11 @@ class UsbApduInterface(
override val valid: Boolean
get() = channelId != -1
override var atr: ByteArray? = null
private var atr: ByteArray? = null
override fun readATR(): ByteArray {
return atr?.clone() ?: throw IllegalStateException("atr unavailable")
}
private fun isSuccessResponse(resp: ByteArray): Boolean =
resp.size >= 2 && resp[resp.size - 2] == 0x90.toByte() && resp[resp.size - 1] == 0x00.toByte()

View file

@ -43,7 +43,6 @@ class EuiccInfoActivity : BaseEuiccAccessActivity(), OpenEuiccContextMarker {
val titleResId: Int,
val content: String?,
val copiedToastResId: Int? = null,
val isEnabled: Boolean = true,
)
override fun onCreate(savedInstanceState: Bundle?) {
@ -95,13 +94,12 @@ class EuiccInfoActivity : BaseEuiccAccessActivity(), OpenEuiccContextMarker {
lifecycleScope.launch {
(infoList.adapter!! as EuiccInfoAdapter).euiccInfoItems =
euiccChannelManager.withEuiccChannel(logicalSlotId, ::buildEuiccInfoItems)
.filter { it.isEnabled }
swipeRefresh.isRefreshing = false
}
}
private suspend fun buildEuiccInfoItems(channel: EuiccChannel) = buildList {
private fun buildEuiccInfoItems(channel: EuiccChannel) = buildList {
add(Item(R.string.euicc_info_access_mode, channel.type))
add(
Item(
@ -136,12 +134,16 @@ class EuiccInfoActivity : BaseEuiccAccessActivity(), OpenEuiccContextMarker {
}
add(Item(R.string.euicc_info_ci_type, getString(resId)))
}
val atr = try {
channel.lpa.readATR().encodeHex()
} catch (e: Exception) {
getString(R.string.euicc_info_atr_unavailable)
}
add(
Item(
R.string.euicc_info_atr,
channel.lpa.atr?.encodeHex(),
atr,
copiedToastResId = R.string.toast_atr_copied,
isEnabled = preferenceRepository.developerOptionsEnabledFlow.first()
)
)
}

View file

@ -132,6 +132,7 @@
<string name="euicc_info_ci_gsma_test">GSMA Test CI</string>
<string name="euicc_info_ci_unknown">Unknown eSIM CI</string>
<string name="euicc_info_atr">ATR (Answer To Reset)</string>
<string name="euicc_info_atr_unavailable">ATR unavailable</string>
<string name="yes">Yes</string>
<string name="no">No</string>

View file

@ -25,7 +25,9 @@ class TelephonyManagerApduInterface(
// just that transactions might return errors or nonsense
get() = lastChannel != -1
override val atr: ByteArray? = null
override fun readATR(): ByteArray {
throw IllegalStateException("atr unavailable")
}
override fun connect() {
// Do nothing

View file

@ -18,7 +18,7 @@ interface ApduInterface {
val valid: Boolean
/**
* Answer To Reset
* Read Answer To Reset
*/
val atr: ByteArray?
fun readATR(): ByteArray
}

View file

@ -17,13 +17,14 @@ interface LocalProfileAssistant {
class ProfileNameIsInvalidUTF8Exception() : Exception("Profile name is invalid UTF-8")
val valid: Boolean
val atr: ByteArray?
val profiles: List<LocalProfileInfo>
val notifications: List<LocalProfileNotification>
val eID: String
// Extended EuiccInfo for use with LUIs, containing information such as firmware version
val euiccInfo2: EuiccInfo2?
fun readATR(): ByteArray
/**
* Set the max segment size (mss) for all es10x commands. This can help with removable
* eUICCs that may run at a baud rate too fast for the modem.

View file

@ -102,9 +102,6 @@ class LocalProfileAssistantImpl(
false
}
override val atr: ByteArray?
get() = apduInterface.atr
override val profiles: List<LocalProfileInfo>
@Synchronized
get() {
@ -190,6 +187,8 @@ class LocalProfileAssistantImpl(
return ret
}
override fun readATR() = apduInterface.readATR()
@Synchronized
override fun enableProfile(iccid: String, refresh: Boolean): Boolean =
LpacJni.es10cEnableProfile(contextHandle, iccid, refresh) == 0