From afd8b84f26d7c6c6e172b4a10ce21f4572472049 Mon Sep 17 00:00:00 2001 From: Peter Sorotokin Date: Fri, 22 Nov 2024 10:47:38 -0800 Subject: [PATCH] Fix for unexpected Ausweis SDK responses. Signed-off-by: Peter Sorotokin --- .../provisioncredential/AusweisModel.kt | 20 ++++++++++++++++--- .../provisioncredential/EvidenceRequest.kt | 2 ++ wallet/src/main/res/values/strings.xml | 1 + 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/wallet/src/main/java/com/android/identity_credential/wallet/ui/destination/provisioncredential/AusweisModel.kt b/wallet/src/main/java/com/android/identity_credential/wallet/ui/destination/provisioncredential/AusweisModel.kt index 96e301b39..69ac38624 100644 --- a/wallet/src/main/java/com/android/identity_credential/wallet/ui/destination/provisioncredential/AusweisModel.kt +++ b/wallet/src/main/java/com/android/identity_credential/wallet/ui/destination/provisioncredential/AusweisModel.kt @@ -64,6 +64,7 @@ class AusweisModel( data class Auth(val progress: Int): Status() data object NetworkError: Status() data object GenericError: Status() + data object PinError: Status() private lateinit var sdk: IAusweisApp2Sdk private lateinit var sessionId: String @@ -122,7 +123,11 @@ class AusweisModel( fun startWorkflow(simulatedCard: Boolean) { useSimulatedCard = simulatedCard job = coroutineScope.launch { - runAusweisSdk() + try { + runAusweisSdk() + } catch (err: UnexpectedStateException) { + Logger.e(TAG, "Error communicating with the card", err) + } } } @@ -140,7 +145,7 @@ class AusweisModel( fun tryAgain() { status.value = null - navController.navigate(AusweisModel.Route.INITIAL.route) + navController.navigate(Route.INITIAL.route) initialize() } @@ -279,7 +284,13 @@ class AusweisModel( } else if (type == "READER") { // TODO: process READER } else { - throw IllegalStateException("Unexpected message type: $type") + if (type == "ENTER_CAN" || type == "ENTER_PUK") { + status.value = PinError + } else { + status.value = GenericError + } + navController.navigate(Route.ERROR.route) + throw UnexpectedStateException(type ?: "") } } } @@ -306,4 +317,7 @@ class AusweisModel( private fun disableCardScanning(nfcAdapter: NfcAdapter?) { nfcAdapter?.disableReaderMode(context.getActivity()) } + + class UnexpectedStateException(type: String): + IllegalStateException("Unexpected message type: $type") } \ No newline at end of file diff --git a/wallet/src/main/java/com/android/identity_credential/wallet/ui/destination/provisioncredential/EvidenceRequest.kt b/wallet/src/main/java/com/android/identity_credential/wallet/ui/destination/provisioncredential/EvidenceRequest.kt index e210032f7..8c523fcda 100644 --- a/wallet/src/main/java/com/android/identity_credential/wallet/ui/destination/provisioncredential/EvidenceRequest.kt +++ b/wallet/src/main/java/com/android/identity_credential/wallet/ui/destination/provisioncredential/EvidenceRequest.kt @@ -1593,6 +1593,8 @@ fun AusweisView( text = stringResource( if (status.value == AusweisModel.NetworkError) { R.string.eid_network_error + } else if (status.value == AusweisModel.PinError) { + R.string.eid_pin_error } else { R.string.eid_generic_error }), diff --git a/wallet/src/main/res/values/strings.xml b/wallet/src/main/res/values/strings.xml index a8fd818f4..a2f22284d 100644 --- a/wallet/src/main/res/values/strings.xml +++ b/wallet/src/main/res/values/strings.xml @@ -389,6 +389,7 @@ Scanning eID using NFC Enter your PIN Error establishing network connection + Incorrect PIN entered too many times. The card is locked. Use Ausweis App to unlock the card. Error scanning or processing the card Try again