diff --git a/server-openid4vci/src/main/java/com/android/identity/server/openid4vci/AuthorizeServlet.kt b/server-openid4vci/src/main/java/com/android/identity/server/openid4vci/AuthorizeServlet.kt index 49e06dcfd..34732cd9b 100644 --- a/server-openid4vci/src/main/java/com/android/identity/server/openid4vci/AuthorizeServlet.kt +++ b/server-openid4vci/src/main/java/com/android/identity/server/openid4vci/AuthorizeServlet.kt @@ -93,7 +93,6 @@ class AuthorizeServlet : BaseServlet() { override fun doPost(req: HttpServletRequest, resp: HttpServletResponse) { val code = req.getParameter("authorizationCode") val pidData = req.getParameter("pidData") - val extraInfo = req.getParameter("extraInfo") val id = codeToId(OpaqueIdType.AUTHORIZATION_STATE, code) val storage = environment.getInterface(Storage::class)!! val baseUri = URI(this.baseUrl) @@ -130,7 +129,6 @@ class AuthorizeServlet : BaseServlet() { } } - data.putEntry("com.android.identity.server.openid4vci", "extraInfo", Cbor.encode(Tstr(extraInfo))) state.credentialData = data.build() storage.update("IssuanceState", "", id, ByteString(state.toCbor())) } diff --git a/server/src/main/resources/resources/openid4vci/authorize.html b/server/src/main/resources/resources/openid4vci/authorize.html index 50bb9be1d..c935d82af 100644 --- a/server/src/main/resources/resources/openid4vci/authorize.html +++ b/server/src/main/resources/resources/openid4vci/authorize.html @@ -11,8 +11,6 @@

(mDoc format only currently)


- - diff --git a/wallet/src/main/java/com/android/identity_credential/wallet/MainActivity.kt b/wallet/src/main/java/com/android/identity_credential/wallet/MainActivity.kt index 9f272a8a9..a0dbef74b 100644 --- a/wallet/src/main/java/com/android/identity_credential/wallet/MainActivity.kt +++ b/wallet/src/main/java/com/android/identity_credential/wallet/MainActivity.kt @@ -81,6 +81,11 @@ class MainActivity : FragmentActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) application = getApplication() as WalletApplication + provisioningViewModel.init( + walletServerProvider = application.walletServerProvider, + documentStore = application.documentStore, + settingsModel = application.settingsModel + ) permissionTracker.updatePermissions() // handle intents with schema openid-credential-offer:// handleOid4vciCredentialOfferIntent(intent) @@ -106,7 +111,6 @@ class MainActivity : FragmentActivity() { application = application, provisioningViewModel = provisioningViewModel, permissionTracker = permissionTracker, - sharedPreferences = application.sharedPreferences, qrEngagementViewModel = qrEngagementViewModel, documentModel = application.documentModel, readerModel = application.readerModel, @@ -143,14 +147,11 @@ class MainActivity : FragmentActivity() { val query = getUrlQueryFromCustomSchemeUrl(intent.dataString!!) val offer = extractCredentialIssuerData(query) if (offer != null) { + routeRequest.value = WalletDestination.ProvisionDocument.route provisioningViewModel.start( - walletServerProvider = application.walletServerProvider, - documentStore = application.documentStore, - settingsModel = application.settingsModel, issuerIdentifier = null, openid4VciCredentialOffer = offer ) - routeRequest.value = WalletDestination.ProvisionDocument.route } } } diff --git a/wallet/src/main/java/com/android/identity_credential/wallet/ProvisioningViewModel.kt b/wallet/src/main/java/com/android/identity_credential/wallet/ProvisioningViewModel.kt index 6c6ed0444..d58104635 100644 --- a/wallet/src/main/java/com/android/identity_credential/wallet/ProvisioningViewModel.kt +++ b/wallet/src/main/java/com/android/identity_credential/wallet/ProvisioningViewModel.kt @@ -13,7 +13,6 @@ import com.android.identity.issuance.DocumentExtensions.documentIdentifier import com.android.identity.issuance.DocumentExtensions.issuingAuthorityConfiguration import com.android.identity.issuance.DocumentExtensions.issuingAuthorityIdentifier import com.android.identity.issuance.DocumentExtensions.refreshState -import com.android.identity.issuance.IssuingAuthority import com.android.identity.issuance.ProofingFlow import com.android.identity.issuance.RegistrationResponse import com.android.identity.issuance.evidence.EvidenceRequest @@ -27,11 +26,13 @@ import com.android.identity.issuance.remote.WalletServerProvider import com.android.identity.util.Logger import com.android.identity.util.fromBase64Url import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.Job import kotlinx.coroutines.launch import kotlinx.coroutines.runBlocking import kotlinx.datetime.Clock import kotlinx.io.bytestring.buildByteString import org.json.JSONObject +import kotlin.coroutines.cancellation.CancellationException class ProvisioningViewModel : ViewModel() { @@ -52,9 +53,21 @@ class ProvisioningViewModel : ViewModel() { var error: Throwable? = null - private lateinit var issuer: IssuingAuthority + private lateinit var walletServerProvider: WalletServerProvider + private lateinit var documentStore: DocumentStore + private lateinit var settingsModel: SettingsModel - var openid4VciCredentialOffer: Openid4VciCredentialOffer? = null + private var openid4VciCredentialOffer: Openid4VciCredentialOffer? = null + + fun init( + walletServerProvider: WalletServerProvider, + documentStore: DocumentStore, + settingsModel: SettingsModel, + ) { + this.walletServerProvider = walletServerProvider + this.documentStore = documentStore + this.settingsModel = settingsModel + } fun reset() { state.value = State.IDLE @@ -65,8 +78,6 @@ class ProvisioningViewModel : ViewModel() { currentEvidenceRequestIndex = 0 nextEvidenceRequest.value = null selectedOpenid4VpCredential.value = null - documentStore = null - settingsModel = null } private var proofingFlow: ProofingFlow? = null @@ -74,37 +85,39 @@ class ProvisioningViewModel : ViewModel() { var document: Document? = null private var evidenceRequests: List? = null private var currentEvidenceRequestIndex: Int = 0 - private var documentStore: DocumentStore? = null - private var settingsModel: SettingsModel? = null + private var job: Job? = null val nextEvidenceRequest = mutableStateOf(null) val selectedOpenid4VpCredential = mutableStateOf(null) fun start( - walletServerProvider: WalletServerProvider, - documentStore: DocumentStore, - settingsModel: SettingsModel, // PID-based mdoc or sd-jwt issuerIdentifier: String?, openid4VciCredentialOffer: Openid4VciCredentialOffer? = null, ) { - this.documentStore = documentStore - this.settingsModel = settingsModel - this.openid4VciCredentialOffer = openid4VciCredentialOffer - viewModelScope.launch(Dispatchers.IO) { + val lastJob = this.job + if (lastJob != null) { + this.job = null + lastJob.cancel(CancellationException("New provisioning started")) + } + this.job = viewModelScope.launch(Dispatchers.IO) { + lastJob?.join() + reset() + this@ProvisioningViewModel.openid4VciCredentialOffer = openid4VciCredentialOffer + state.value = State.IDLE try { - if (openid4VciCredentialOffer != null) { - issuer = walletServerProvider.createOpenid4VciIssuingAuthorityByUri( + val issuer = if (openid4VciCredentialOffer != null) { + walletServerProvider.createOpenid4VciIssuingAuthorityByUri( openid4VciCredentialOffer.issuerUri, openid4VciCredentialOffer.configurationId ) } else { - issuer = walletServerProvider.getIssuingAuthority(issuerIdentifier!!) + walletServerProvider.getIssuingAuthority(issuerIdentifier!!) } val issuerConfiguration = issuer.getConfiguration() state.value = State.CREDENTIAL_REGISTRATION - val createDocumentKeyFlow = this@ProvisioningViewModel.issuer.register() + val createDocumentKeyFlow = issuer.register() val documentRegistrationConfiguration = createDocumentKeyFlow.getDocumentRegistrationConfiguration() val issuerDocumentIdentifier = documentRegistrationConfiguration.documentId @@ -134,9 +147,7 @@ class ProvisioningViewModel : ViewModel() { if (evidenceRequests!!.size == 0) { state.value = State.PROOFING_COMPLETE - document!!.let { - it.refreshState(walletServerProvider) - } + document!!.refreshState(walletServerProvider) documentStore.addDocument(document!!) proofingFlow!!.complete() } else { @@ -156,10 +167,7 @@ class ProvisioningViewModel : ViewModel() { } fun evidenceCollectionFailed( - error: Throwable, - walletServerProvider: WalletServerProvider, - documentStore: DocumentStore - ) { + error: Throwable ) { if (document != null) { documentStore.deleteDocument(document!!.name) } @@ -168,11 +176,8 @@ class ProvisioningViewModel : ViewModel() { state.value = State.FAILED } - fun provideEvidence( - evidence: EvidenceResponse, - walletServerProvider: WalletServerProvider, - ) { - viewModelScope.launch(Dispatchers.IO) { + fun provideEvidence(evidence: EvidenceResponse) { + this.job = viewModelScope.launch(Dispatchers.IO) { try { state.value = State.SUBMITTING_EVIDENCE @@ -185,7 +190,7 @@ class ProvisioningViewModel : ViewModel() { if (evidenceRequests!!.isEmpty()) { state.value = State.PROOFING_COMPLETE document!!.refreshState(walletServerProvider) - documentStore!!.addDocument(document!!) + documentStore.addDocument(document!!) proofingFlow!!.complete() document!!.refreshState(walletServerProvider) } else { @@ -208,7 +213,7 @@ class ProvisioningViewModel : ViewModel() { } } catch (e: Throwable) { if (document != null) { - documentStore!!.deleteDocument(document!!.name) + documentStore.deleteDocument(document!!.name) } Logger.w(TAG, "Error submitting evidence", e) e.printStackTrace() @@ -330,17 +335,17 @@ class ProvisioningViewModel : ViewModel() { docType: String ): Document? { // prefer the credential which is on-screen if possible - val credentialIdFromPager: String? = settingsModel!!.focusedCardId.value + val credentialIdFromPager: String? = settingsModel.focusedCardId.value if (credentialIdFromPager != null && canDocumentSatisfyRequest(credentialIdFromPager, credentialFormat, docType) ) { - return documentStore!!.lookupDocument(credentialIdFromPager) + return documentStore.lookupDocument(credentialIdFromPager) } - val docId = documentStore!!.listDocuments().firstOrNull { credentialId -> + val docId = documentStore.listDocuments().firstOrNull { credentialId -> canDocumentSatisfyRequest(credentialId, credentialFormat, docType) } - return docId?.let { documentStore!!.lookupDocument(it) } + return docId?.let { documentStore.lookupDocument(it) } } private fun canDocumentSatisfyRequest( @@ -348,7 +353,7 @@ class ProvisioningViewModel : ViewModel() { credentialFormat: CredentialFormat, docType: String ): Boolean { - val document = documentStore!!.lookupDocument(credentialId) ?: return false + val document = documentStore.lookupDocument(credentialId) ?: return false val documentConfiguration = document.documentConfiguration return when (credentialFormat) { CredentialFormat.MDOC_MSO -> documentConfiguration.mdocConfiguration?.docType == docType diff --git a/wallet/src/main/java/com/android/identity_credential/wallet/navigation/WalletNavigation.kt b/wallet/src/main/java/com/android/identity_credential/wallet/navigation/WalletNavigation.kt index 673014a2a..1db00be65 100644 --- a/wallet/src/main/java/com/android/identity_credential/wallet/navigation/WalletNavigation.kt +++ b/wallet/src/main/java/com/android/identity_credential/wallet/navigation/WalletNavigation.kt @@ -1,6 +1,5 @@ package com.android.identity_credential.wallet.navigation -import android.content.SharedPreferences import androidx.compose.runtime.Composable import androidx.navigation.NavController import androidx.navigation.NavHostController @@ -65,13 +64,11 @@ fun WalletNavigation( application: WalletApplication, provisioningViewModel: ProvisioningViewModel, permissionTracker: PermissionTracker, - sharedPreferences: SharedPreferences, qrEngagementViewModel: QrEngagementViewModel, documentModel: DocumentModel, readerModel: ReaderModel, ) { val onNavigate = { routeWithArgs: String -> navigateTo(navController, routeWithArgs) } - val credentialStore = application.documentStore NavHost( navController = navController, startDestination = WalletDestination.Main.route @@ -123,12 +120,9 @@ fun WalletNavigation( */ composable(WalletDestination.AddToWallet.route) { AddToWalletScreen( - documentModel = documentModel, provisioningViewModel = provisioningViewModel, onNavigate = onNavigate, - documentStore = application.documentStore, - walletServerProvider = application.walletServerProvider, - settingsModel = application.settingsModel, + walletServerProvider = application.walletServerProvider ) } @@ -212,7 +206,6 @@ fun WalletNavigation( onNavigate = onNavigate, permissionTracker = permissionTracker, walletServerProvider = application.walletServerProvider, - documentStore = application.documentStore, developerMode = application.settingsModel.developerModeEnabled.value ?: false ) } diff --git a/wallet/src/main/java/com/android/identity_credential/wallet/ui/destination/addtowallet/AddToWalletScreen.kt b/wallet/src/main/java/com/android/identity_credential/wallet/ui/destination/addtowallet/AddToWalletScreen.kt index 68a77b9a4..d1980776f 100644 --- a/wallet/src/main/java/com/android/identity_credential/wallet/ui/destination/addtowallet/AddToWalletScreen.kt +++ b/wallet/src/main/java/com/android/identity_credential/wallet/ui/destination/addtowallet/AddToWalletScreen.kt @@ -29,14 +29,11 @@ import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.dp -import com.android.identity.document.DocumentStore import com.android.identity.issuance.IssuingAuthorityConfiguration import com.android.identity.issuance.remote.WalletServerProvider import com.android.identity.util.Logger -import com.android.identity_credential.wallet.DocumentModel import com.android.identity_credential.wallet.ProvisioningViewModel import com.android.identity_credential.wallet.R -import com.android.identity_credential.wallet.SettingsModel import com.android.identity_credential.wallet.WalletApplication import com.android.identity_credential.wallet.credentialoffer.extractCredentialIssuerData import com.android.identity_credential.wallet.navigation.WalletDestination @@ -76,12 +73,9 @@ private suspend fun getIssuerDisplayDatas( @Composable fun AddToWalletScreen( - documentModel: DocumentModel, provisioningViewModel: ProvisioningViewModel, onNavigate: (String) -> Unit, - documentStore: DocumentStore, walletServerProvider: WalletServerProvider, - settingsModel: SettingsModel, ) { val loadingIssuerDisplayDatas = remember { mutableStateOf(true) } val loadingIssuerDisplayError = remember { mutableStateOf(null) } @@ -144,9 +138,6 @@ fun AddToWalletScreen( if (offer != null) { // initiate getting issuing authority dynamically from specified Issuer Uri and Credential Id provisioningViewModel.start( - walletServerProvider = walletServerProvider, - settingsModel = settingsModel, - documentStore = documentStore, issuerIdentifier = null, openid4VciCredentialOffer = offer, ) @@ -161,9 +152,6 @@ fun AddToWalletScreen( AddToWalletScreenWithIssuerDisplayDatas( provisioningViewModel, onNavigate, - documentStore, - walletServerProvider, - settingsModel, issuerDisplayDatas, onShowScanQrDialog = { showQrScannerDialog.value = true @@ -221,9 +209,6 @@ private fun AddToWalletScreenLoading() { private fun AddToWalletScreenWithIssuerDisplayDatas( provisioningViewModel: ProvisioningViewModel, onNavigate: (String) -> Unit, - documentStore: DocumentStore, - walletServerProvider: WalletServerProvider, - settingsModel: SettingsModel, issuerDisplayDatas: SnapshotStateList, onShowScanQrDialog: () -> Unit, ) { @@ -248,10 +233,7 @@ private fun AddToWalletScreenWithIssuerDisplayDatas( onClick = { provisioningViewModel.reset() provisioningViewModel.start( - walletServerProvider = walletServerProvider, - documentStore = documentStore, issuerIdentifier = issuerDisplayData.configuration.identifier, - settingsModel = settingsModel, ) onNavigate(WalletDestination.ProvisionDocument.route) }) { 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 6c16efeef..e210032f7 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 @@ -68,7 +68,6 @@ import androidx.navigation.compose.composable import androidx.navigation.compose.rememberNavController import com.android.identity.android.securearea.cloud.CloudSecureArea import com.android.identity.appsupport.ui.PassphraseEntryField -import com.android.identity.document.DocumentStore import com.android.identity.issuance.ApplicationSupport import com.android.identity.issuance.LandingUrlUnknownException import com.android.identity.issuance.evidence.EvidenceRequestCompletionMessage @@ -104,6 +103,7 @@ import com.android.identity_credential.wallet.PermissionTracker import com.android.identity_credential.wallet.ProvisioningViewModel import com.android.identity_credential.wallet.R import com.android.identity_credential.wallet.WalletApplication +import com.android.identity_credential.wallet.presentation.UserCanceledPromptException import com.android.identity_credential.wallet.ui.RichTextSnippet import com.android.identity_credential.wallet.ui.SelfieRecorder import com.android.identity_credential.wallet.util.inverse @@ -123,9 +123,7 @@ private const val TAG = "EvidenceRequest" @Composable fun EvidenceRequestMessageView( evidenceRequest: EvidenceRequestMessage, - provisioningViewModel: ProvisioningViewModel, - walletServerProvider: WalletServerProvider, - documentStore: DocumentStore + provisioningViewModel: ProvisioningViewModel ) { Row( modifier = Modifier.fillMaxWidth(), @@ -147,8 +145,7 @@ fun EvidenceRequestMessageView( modifier = Modifier.padding(8.dp), onClick = { provisioningViewModel.provideEvidence( - evidence = EvidenceResponseMessage(false), - walletServerProvider = walletServerProvider + evidence = EvidenceResponseMessage(false) ) }) { Text(rejectButtonText) @@ -158,8 +155,7 @@ fun EvidenceRequestMessageView( modifier = Modifier.padding(8.dp), onClick = { provisioningViewModel.provideEvidence( - evidence = EvidenceResponseMessage(true), - walletServerProvider = walletServerProvider + evidence = EvidenceResponseMessage(true) ) }) { Text(evidenceRequest.acceptButtonText) @@ -176,9 +172,7 @@ fun EvidenceRequestMessageView( @Composable fun EvidenceRequestCompletedScreen( evidenceRequest: EvidenceRequestCompletionMessage, - provisioningViewModel: ProvisioningViewModel, - walletServerProvider: WalletServerProvider, - documentStore: DocumentStore + provisioningViewModel: ProvisioningViewModel ) { Column( modifier = Modifier @@ -242,8 +236,7 @@ fun EvidenceRequestCompletedScreen( modifier = Modifier.padding(8.dp), onClick = { provisioningViewModel.provideEvidence( - evidence = EvidenceResponseMessage(true), - walletServerProvider = walletServerProvider, + evidence = EvidenceResponseMessage(true) ) }) { Text(evidenceRequest.acceptButtonText) @@ -256,9 +249,7 @@ fun EvidenceRequestCompletedScreen( @Composable fun EvidenceRequestNotificationPermissionView( evidenceRequest: EvidenceRequestNotificationPermission, - provisioningViewModel: ProvisioningViewModel, - walletServerProvider: WalletServerProvider, - documentStore: DocumentStore + provisioningViewModel: ProvisioningViewModel ) { // Only need to request POST_NOTIFICATIONS permission if on Android 13 (Tiramisu) or later. @@ -266,8 +257,7 @@ fun EvidenceRequestNotificationPermissionView( // TODO: This is a hack, this check should be done in the model instead of here. SideEffect { provisioningViewModel.provideEvidence( - evidence = EvidenceResponseNotificationPermission(true), - walletServerProvider = walletServerProvider + evidence = EvidenceResponseNotificationPermission(true) ) } return @@ -276,8 +266,7 @@ fun EvidenceRequestNotificationPermissionView( val postNotificationsPermissionState = rememberPermissionState(Manifest.permission.POST_NOTIFICATIONS) if (postNotificationsPermissionState.status.isGranted) { provisioningViewModel.provideEvidence( - evidence = EvidenceResponseNotificationPermission(true), - walletServerProvider = walletServerProvider + evidence = EvidenceResponseNotificationPermission(true) ) } else { Column { @@ -304,8 +293,7 @@ fun EvidenceRequestNotificationPermissionView( modifier = Modifier.padding(8.dp), onClick = { provisioningViewModel.provideEvidence( - evidence = EvidenceResponseNotificationPermission(false), - walletServerProvider = walletServerProvider + evidence = EvidenceResponseNotificationPermission(false) ) }) { Text(evidenceRequest.continueWithoutPermissionButtonText) @@ -732,8 +720,6 @@ fun EvidenceRequestQuestionMultipleChoiceView( fun EvidenceRequestIcaoPassiveAuthenticationView( evidenceRequest: EvidenceRequestIcaoPassiveAuthentication, provisioningViewModel: ProvisioningViewModel, - walletServerProvider: WalletServerProvider, - documentStore: DocumentStore, permissionTracker: PermissionTracker ) { EvidenceRequestIcaoView( @@ -742,8 +728,7 @@ fun EvidenceRequestIcaoPassiveAuthenticationView( IcaoMrtdCommunicationModel.Route.CAMERA_SCAN ) { nfcData -> provisioningViewModel.provideEvidence( - evidence = EvidenceResponseIcaoPassiveAuthentication(nfcData.dataGroups, nfcData.sod), - walletServerProvider = walletServerProvider + evidence = EvidenceResponseIcaoPassiveAuthentication(nfcData.dataGroups, nfcData.sod) ) } } @@ -1192,9 +1177,7 @@ fun NfcHeartbeatAnimation(nfcAnimationStatus: NfcAnimationStatus) { fun EvidenceRequestSelfieVideoView( evidenceRequest: EvidenceRequestSelfieVideo, provisioningViewModel: ProvisioningViewModel, - permissionTracker: PermissionTracker, - walletServerProvider: WalletServerProvider, - documentStore: DocumentStore + permissionTracker: PermissionTracker ) { if (evidenceRequest.poseSequence.isEmpty()) { throw IllegalArgumentException("Pose sequence must not be empty.") @@ -1244,8 +1227,7 @@ fun EvidenceRequestSelfieVideoView( return@SelfieRecorder } else { provisioningViewModel.provideEvidence( - evidence = EvidenceResponseSelfieVideo(selfieResult), - walletServerProvider = walletServerProvider + evidence = EvidenceResponseSelfieVideo(selfieResult) ) } }, @@ -1420,19 +1402,14 @@ fun EvidenceRequestSelfieVideoView( @Composable fun EvidenceRequestEIdView( evidenceRequest: EvidenceRequestGermanEid, - provisioningViewModel: ProvisioningViewModel, - walletServerProvider: WalletServerProvider, - documentStore: DocumentStore, - permissionTracker: PermissionTracker + provisioningViewModel: ProvisioningViewModel ) { AusweisView( evidenceRequest.tcTokenUrl, - evidenceRequest.optionalComponents, - permissionTracker + evidenceRequest.optionalComponents ) { evidence -> provisioningViewModel.provideEvidence( - evidence = evidence, - walletServerProvider = walletServerProvider + evidence = evidence ) } } @@ -1441,7 +1418,6 @@ fun EvidenceRequestEIdView( fun AusweisView( tcTokenUrl: String, requiredComponents: List, - permissionTracker: PermissionTracker, onResult: (evidence: EvidenceResponseGermanEid) -> Unit ) { val navController = rememberNavController() @@ -1642,8 +1618,7 @@ fun AusweisView( fun EvidenceRequestWebView( evidenceRequest: EvidenceRequestWeb, provisioningViewModel: ProvisioningViewModel, - walletServerProvider: WalletServerProvider, - documentStore: DocumentStore + walletServerProvider: WalletServerProvider ) { val context = LocalContext.current val url = Uri.parse(evidenceRequest.url) @@ -1656,8 +1631,7 @@ fun EvidenceRequestWebView( // Wait for notifications appSupport.notifications.collectLatest { notification -> if (notification.baseUrl == redirectUri) { - handleLanding(appSupport, redirectUri, provisioningViewModel, - walletServerProvider, documentStore) + handleLanding(appSupport, redirectUri, provisioningViewModel) } } } @@ -1670,8 +1644,7 @@ fun EvidenceRequestWebView( // Poll as a fallback do { delay(10.seconds) - } while(handleLanding(appSupport, redirectUri, provisioningViewModel, - walletServerProvider, documentStore)) + } while(handleLanding(appSupport, redirectUri, provisioningViewModel)) } Column { Row( @@ -1694,7 +1667,6 @@ fun EvidenceRequestWebView( fun EvidenceRequestOpenid4Vp( evidenceRequest: EvidenceRequestOpenid4Vp, provisioningViewModel: ProvisioningViewModel, - walletServerProvider: WalletServerProvider, application: WalletApplication ) { val cx = LocalContext.current @@ -1722,17 +1694,22 @@ fun EvidenceRequestOpenid4Vp( onClick = { val activity = getFragmentActivity(cx) CoroutineScope(Dispatchers.Main).launch { - val response = openid4VpPresentation( - credential, - application, - activity, - evidenceRequest.originUri, - evidenceRequest.request - ) - provisioningViewModel.provideEvidence( - evidence = EvidenceResponseOpenid4Vp(response), - walletServerProvider = walletServerProvider - ) + try { + val response = openid4VpPresentation( + credential, + application, + activity, + evidenceRequest.originUri, + evidenceRequest.request + ) + provisioningViewModel.provideEvidence( + evidence = EvidenceResponseOpenid4Vp(response) + ) + } catch (cancelled: UserCanceledPromptException) { + provisioningViewModel.evidenceCollectionFailed( + error = cancelled + ) + } } }) { Text(text = stringResource(id = R.string.presentation_evidence_ok)) @@ -1750,9 +1727,7 @@ fun EvidenceRequestOpenid4Vp( private suspend fun handleLanding( appSupport: ApplicationSupport, redirectUri: String, - provisioningViewModel: ProvisioningViewModel, - walletServerProvider: WalletServerProvider, - documentStore: DocumentStore + provisioningViewModel: ProvisioningViewModel ): Boolean { val resp = try { appSupport.getLandingUrlStatus(redirectUri) @@ -1762,8 +1737,7 @@ private suspend fun handleLanding( "landing: $redirectUri unknown: $err" ) provisioningViewModel.provideEvidence( - evidence = EvidenceResponseWeb(""), - walletServerProvider = walletServerProvider + evidence = EvidenceResponseWeb("") ) return false } @@ -1776,8 +1750,7 @@ private suspend fun handleLanding( return true } provisioningViewModel.provideEvidence( - evidence = EvidenceResponseWeb(resp), - walletServerProvider = walletServerProvider + evidence = EvidenceResponseWeb(resp) ) return false } diff --git a/wallet/src/main/java/com/android/identity_credential/wallet/ui/destination/provisioncredential/ProvisionCredentialScreen.kt b/wallet/src/main/java/com/android/identity_credential/wallet/ui/destination/provisioncredential/ProvisionCredentialScreen.kt index 1e3e1b563..be1e3d006 100644 --- a/wallet/src/main/java/com/android/identity_credential/wallet/ui/destination/provisioncredential/ProvisionCredentialScreen.kt +++ b/wallet/src/main/java/com/android/identity_credential/wallet/ui/destination/provisioncredential/ProvisionCredentialScreen.kt @@ -92,7 +92,6 @@ fun ProvisionDocumentScreen( onNavigate: (String) -> Unit, permissionTracker: PermissionTracker, walletServerProvider: WalletServerProvider, - documentStore: DocumentStore, developerMode: Boolean = false ) { val context = application.applicationContext @@ -147,8 +146,7 @@ fun ProvisionDocumentScreen( evidenceRequest, onAccept = { inputString -> provisioningViewModel.provideEvidence( - evidence = EvidenceResponseQuestionString(inputString), - walletServerProvider = walletServerProvider + evidence = EvidenceResponseQuestionString(inputString) ) } ) @@ -160,8 +158,7 @@ fun ProvisionDocumentScreen( evidenceRequest, onAccept = { inputString -> provisioningViewModel.provideEvidence( - evidence = EvidenceResponseCreatePassphrase(inputString), - walletServerProvider = walletServerProvider + evidence = EvidenceResponseCreatePassphrase(inputString) ) } ) @@ -175,15 +172,12 @@ fun ProvisionDocumentScreen( onAccept = { provisioningViewModel.provideEvidence( evidence = EvidenceResponseSetupCloudSecureArea( - evidenceRequest.cloudSecureAreaIdentifier), - walletServerProvider = walletServerProvider + evidenceRequest.cloudSecureAreaIdentifier) ) }, onError = { error -> provisioningViewModel.evidenceCollectionFailed( - error = error, - walletServerProvider = walletServerProvider, - documentStore = documentStore + error = error ) } ) @@ -192,27 +186,21 @@ fun ProvisionDocumentScreen( is EvidenceRequestMessage -> { EvidenceRequestMessageView( evidenceRequest = evidenceRequest, - provisioningViewModel = provisioningViewModel, - walletServerProvider = walletServerProvider, - documentStore = documentStore + provisioningViewModel = provisioningViewModel ) } is EvidenceRequestCompletionMessage -> { EvidenceRequestCompletedScreen( evidenceRequest = evidenceRequest, - provisioningViewModel = provisioningViewModel, - walletServerProvider = walletServerProvider, - documentStore = documentStore + provisioningViewModel = provisioningViewModel ) } is EvidenceRequestNotificationPermission -> { EvidenceRequestNotificationPermissionView( evidenceRequest, - provisioningViewModel = provisioningViewModel, - walletServerProvider = walletServerProvider, - documentStore = documentStore + provisioningViewModel = provisioningViewModel ) } @@ -221,8 +209,7 @@ fun ProvisionDocumentScreen( evidenceRequest, onAccept = { selectedOption -> provisioningViewModel.provideEvidence( - evidence = EvidenceResponseQuestionMultipleChoice(selectedOption), - walletServerProvider = walletServerProvider + evidence = EvidenceResponseQuestionMultipleChoice(selectedOption) ) } ) @@ -232,8 +219,6 @@ fun ProvisionDocumentScreen( EvidenceRequestIcaoPassiveAuthenticationView( evidenceRequest = evidenceRequest, provisioningViewModel = provisioningViewModel, - walletServerProvider = walletServerProvider, - documentStore = documentStore, permissionTracker = permissionTracker ) } @@ -252,19 +237,14 @@ fun ProvisionDocumentScreen( EvidenceRequestSelfieVideoView( evidenceRequest, provisioningViewModel = provisioningViewModel, - permissionTracker = permissionTracker, - walletServerProvider = walletServerProvider, - documentStore = documentStore + permissionTracker = permissionTracker ) } is EvidenceRequestGermanEid -> { EvidenceRequestEIdView( evidenceRequest = evidenceRequest, - provisioningViewModel = provisioningViewModel, - walletServerProvider = walletServerProvider, - documentStore = documentStore, - permissionTracker = permissionTracker + provisioningViewModel = provisioningViewModel ) } @@ -272,8 +252,7 @@ fun ProvisionDocumentScreen( EvidenceRequestWebView( evidenceRequest = evidenceRequest, provisioningViewModel = provisioningViewModel, - walletServerProvider = walletServerProvider, - documentStore = documentStore + walletServerProvider = walletServerProvider ) } @@ -281,7 +260,6 @@ fun ProvisionDocumentScreen( EvidenceRequestOpenid4Vp( evidenceRequest = evidenceRequest, provisioningViewModel = provisioningViewModel, - walletServerProvider = walletServerProvider, application = application ) }