From ce40d2493050366a5f1701f8b9fd2cab3c372d5e Mon Sep 17 00:00:00 2001 From: "Tzouvaras, Stilianos" Date: Wed, 5 Jun 2024 17:34:54 +0300 Subject: [PATCH] Simplified and added support for deeplink handling with multiple schemas --- .../kotlin/AndroidLibraryConventionPlugin.kt | 2 + .../navigation/helper/DeepLinkHelper.kt | 39 +++++++++++++------ 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/build-logic/convention/src/main/kotlin/AndroidLibraryConventionPlugin.kt b/build-logic/convention/src/main/kotlin/AndroidLibraryConventionPlugin.kt index 5d1a2e71..5d27f28f 100644 --- a/build-logic/convention/src/main/kotlin/AndroidLibraryConventionPlugin.kt +++ b/build-logic/convention/src/main/kotlin/AndroidLibraryConventionPlugin.kt @@ -85,6 +85,8 @@ class AndroidLibraryConventionPlugin : Plugin { addConfigField("MDOC_OPENID4VP_SCHEME", mdocOpenId4VpScheme) addConfigField("OPENID4VP_SCHEME", openId4VpScheme) addConfigField("CREDENTIAL_OFFER_SCHEME", credentialOfferScheme) + addConfigField("ISSUE_AUTHORIZATION_SCHEME", openId4VciAuthorizationScheme) + addConfigField("ISSUE_AUTHORIZATION_HOST", openId4VciAuthorizationHost) addConfigField( "ISSUE_AUTHORIZATION_DEEPLINK", "$openId4VciAuthorizationScheme://$openId4VciAuthorizationHost" diff --git a/ui-logic/src/main/java/eu/europa/ec/uilogic/navigation/helper/DeepLinkHelper.kt b/ui-logic/src/main/java/eu/europa/ec/uilogic/navigation/helper/DeepLinkHelper.kt index 19e1a36e..f81fbe3c 100644 --- a/ui-logic/src/main/java/eu/europa/ec/uilogic/navigation/helper/DeepLinkHelper.kt +++ b/ui-logic/src/main/java/eu/europa/ec/uilogic/navigation/helper/DeepLinkHelper.kt @@ -21,6 +21,7 @@ import android.content.Intent import android.net.Uri import androidx.core.net.toUri import androidx.navigation.NavController +import eu.europa.ec.businesslogic.util.safeLet import eu.europa.ec.corelogic.util.CoreActions import eu.europa.ec.eudi.wallet.EudiWallet import eu.europa.ec.uilogic.BuildConfig @@ -79,8 +80,11 @@ fun generateNewTaskDeepLink( } fun hasDeepLink(deepLinkUri: Uri?): DeepLinkAction? { - return deepLinkUri?.let { uri -> - DeepLinkAction(link = uri, type = DeepLinkType.parse(uri)) + return safeLet( + deepLinkUri, + deepLinkUri?.scheme + ) { uri, scheme -> + DeepLinkAction(link = uri, type = DeepLinkType.parse(scheme, uri.host)) } } @@ -128,25 +132,36 @@ fun handleDeepLinkAction( } data class DeepLinkAction(val link: Uri, val type: DeepLinkType) -enum class DeepLinkType(val schema: String, val host: String? = null) { - - OPENID4VP(schema = "openid4vp"), - CREDENTIAL_OFFER(schema = "credential-offer"), - ISSUANCE(schema = "issuance", host = "authorization"), - EXTERNAL("external"); +enum class DeepLinkType(val schemas: List, val host: String? = null) { + + OPENID4VP( + schemas = listOf( + BuildConfig.OPENID4VP_SCHEME, + BuildConfig.EUDI_OPENID4VP_SCHEME, + BuildConfig.MDOC_OPENID4VP_SCHEME + ) + ), + CREDENTIAL_OFFER( + schemas = listOf(BuildConfig.CREDENTIAL_OFFER_SCHEME) + ), + ISSUANCE( + schemas = listOf(BuildConfig.ISSUE_AUTHORIZATION_SCHEME), + host = BuildConfig.ISSUE_AUTHORIZATION_HOST + ), + EXTERNAL(listOf("external")); companion object { - fun parse(uri: Uri): DeepLinkType = when { + fun parse(scheme: String, host: String? = null): DeepLinkType = when { - uri.scheme?.contains(OPENID4VP.schema) == true -> { + OPENID4VP.schemas.contains(scheme) -> { OPENID4VP } - uri.scheme?.contains(CREDENTIAL_OFFER.schema) == true -> { + CREDENTIAL_OFFER.schemas.contains(scheme) -> { CREDENTIAL_OFFER } - uri.scheme?.contains(ISSUANCE.schema) == true && uri.host == ISSUANCE.host -> { + ISSUANCE.schemas.contains(scheme) && host == ISSUANCE.host -> { ISSUANCE }