lpac-jni: Validate reconnected APDU channel
This commit is contained in:
parent
451b17d0a5
commit
f9e7d0ed8d
|
@ -33,6 +33,7 @@ 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
|
||||||
}
|
}
|
||||||
|
@ -47,12 +48,21 @@ class LocalProfileAssistantImpl(
|
||||||
try {
|
try {
|
||||||
apduInterface.connect()
|
apduInterface.connect()
|
||||||
contextHandle = LpacJni.createContext(apduInterface, httpInterface)
|
contextHandle = LpacJni.createContext(apduInterface, httpInterface)
|
||||||
val res = LpacJni.es10xInit(contextHandle)
|
check(LpacJni.es10xInit(contextHandle) >= 0) { "Reconnect attempt failed" }
|
||||||
Log.d(TAG, "$res")
|
// Validate that we can actually use the APDU channel by trying to read eID
|
||||||
check(res >= 0) { "Reconnect attempt failed" }
|
eID
|
||||||
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…
Reference in a new issue