Compare commits
No commits in common. "c5a5701c03fe6c25104e347e615ed2c438292a43" and "451b17d0a58a9a19687e0d8da79b23e66665069d" have entirely different histories.
c5a5701c03
...
451b17d0a5
3 changed files with 12 additions and 24 deletions
|
@ -12,7 +12,15 @@ abstract class EuiccChannel(
|
||||||
|
|
||||||
abstract val lpa: LocalProfileAssistant
|
abstract val lpa: LocalProfileAssistant
|
||||||
val valid: Boolean
|
val valid: Boolean
|
||||||
get() = lpa.valid
|
get() {
|
||||||
|
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,16 +9,6 @@ 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
|
||||||
|
|
|
@ -33,7 +33,6 @@ class LocalProfileAssistantImpl(
|
||||||
try {
|
try {
|
||||||
LpacJni.es10xFini(contextHandle)
|
LpacJni.es10xFini(contextHandle)
|
||||||
LpacJni.destroyContext(contextHandle)
|
LpacJni.destroyContext(contextHandle)
|
||||||
contextHandle = -1
|
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
// Ignored
|
// Ignored
|
||||||
}
|
}
|
||||||
|
@ -48,21 +47,12 @@ class LocalProfileAssistantImpl(
|
||||||
try {
|
try {
|
||||||
apduInterface.connect()
|
apduInterface.connect()
|
||||||
contextHandle = LpacJni.createContext(apduInterface, httpInterface)
|
contextHandle = LpacJni.createContext(apduInterface, httpInterface)
|
||||||
check(LpacJni.es10xInit(contextHandle) >= 0) { "Reconnect attempt failed" }
|
val res = LpacJni.es10xInit(contextHandle)
|
||||||
// Validate that we can actually use the APDU channel by trying to read eID and profiles
|
Log.d(TAG, "$res")
|
||||||
check(valid) { "Reconnected channel is invalid" }
|
check(res >= 0) { "Reconnect attempt failed" }
|
||||||
break
|
break
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
if (contextHandle != -1L) {
|
|
||||||
try {
|
|
||||||
LpacJni.es10xFini(contextHandle)
|
|
||||||
LpacJni.destroyContext(contextHandle)
|
|
||||||
contextHandle = -1
|
|
||||||
} catch (e: Exception) {
|
|
||||||
// Ignored
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// continue retrying
|
// continue retrying
|
||||||
delay(1000)
|
delay(1000)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue