lpac-jni: Fixup channel validity detection
This commit is contained in:
parent
f9e7d0ed8d
commit
c5a5701c03
|
@ -12,15 +12,7 @@ abstract class EuiccChannel(
|
||||||
|
|
||||||
abstract val lpa: LocalProfileAssistant
|
abstract val lpa: LocalProfileAssistant
|
||||||
val valid: Boolean
|
val valid: Boolean
|
||||||
get() {
|
get() = lpa.valid
|
||||||
try {
|
|
||||||
// Try to ping the eUICC card by reading the EID
|
|
||||||
lpa.eID
|
|
||||||
} catch (e: Exception) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
fun close() = lpa.close()
|
fun close() = lpa.close()
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,16 @@ interface LocalProfileAssistant {
|
||||||
private const val TAG = "LocalProfileAssistant"
|
private const val TAG = "LocalProfileAssistant"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val valid: Boolean
|
||||||
|
get() = try {
|
||||||
|
// If we can read both eID and profiles properly, we are likely looking at
|
||||||
|
// a valid LocalProfileAssistant
|
||||||
|
eID
|
||||||
|
profiles
|
||||||
|
true
|
||||||
|
} catch (e: Exception) {
|
||||||
|
false
|
||||||
|
}
|
||||||
val profiles: List<LocalProfileInfo>
|
val profiles: List<LocalProfileInfo>
|
||||||
val notifications: List<LocalProfileNotification>
|
val notifications: List<LocalProfileNotification>
|
||||||
val eID: String
|
val eID: String
|
||||||
|
|
|
@ -49,8 +49,8 @@ class LocalProfileAssistantImpl(
|
||||||
apduInterface.connect()
|
apduInterface.connect()
|
||||||
contextHandle = LpacJni.createContext(apduInterface, httpInterface)
|
contextHandle = LpacJni.createContext(apduInterface, httpInterface)
|
||||||
check(LpacJni.es10xInit(contextHandle) >= 0) { "Reconnect attempt failed" }
|
check(LpacJni.es10xInit(contextHandle) >= 0) { "Reconnect attempt failed" }
|
||||||
// Validate that we can actually use the APDU channel by trying to read eID
|
// Validate that we can actually use the APDU channel by trying to read eID and profiles
|
||||||
eID
|
check(valid) { "Reconnected channel is invalid" }
|
||||||
break
|
break
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
|
|
Loading…
Reference in a new issue