diff --git a/app/src/main/java/com/tangem/tap/MainActivity.kt b/app/src/main/java/com/tangem/tap/MainActivity.kt index 9e44bb3dc2..8a5266c470 100644 --- a/app/src/main/java/com/tangem/tap/MainActivity.kt +++ b/app/src/main/java/com/tangem/tap/MainActivity.kt @@ -33,7 +33,9 @@ import com.tangem.core.decompose.context.AppComponentContext import com.tangem.core.decompose.di.RootAppComponentContext import com.tangem.core.deeplink.DEEPLINK_KEY import com.tangem.core.deeplink.DeepLinksRegistry +import com.tangem.core.deeplink.WEBLINK_KEY import com.tangem.core.navigation.email.EmailSender +import com.tangem.core.navigation.url.UrlOpener import com.tangem.core.ui.UiDependencies import com.tangem.data.balancehiding.DefaultDeviceFlipDetector import com.tangem.data.card.sdk.CardSdkOwner @@ -74,6 +76,7 @@ import com.tangem.tap.routing.configurator.AppRouterConfig import com.tangem.tap.routing.utils.DeepLinkFactory import com.tangem.utils.coroutines.CoroutineDispatcherProvider import com.tangem.utils.coroutines.FeatureCoroutineExceptionHandler +import com.tangem.utils.extensions.validate import dagger.hilt.android.AndroidEntryPoint import kotlinx.coroutines.* import kotlinx.coroutines.flow.* @@ -185,6 +188,9 @@ class MainActivity : AppCompatActivity(), ActivityResultCallbackHolder { @Inject internal lateinit var walletConnectFeatureToggles: WalletConnectFeatureToggles + @Inject + internal lateinit var urlOpener: UrlOpener + internal val viewModel: MainViewModel by viewModels() private lateinit var appThemeModeFlow: SharedFlow @@ -482,9 +488,18 @@ class MainActivity : AppCompatActivity(), ActivityResultCallbackHolder { private fun handleDeepLink(intent: Intent) { if (routingFeatureToggle.isDeepLinkNavigationEnabled) { val deepLinkExtras = intent.getStringExtra(DEEPLINK_KEY)?.toUri() - val receivedDeepLink = intent.data ?: deepLinkExtras ?: return + val webLink = intent.getStringExtra(WEBLINK_KEY) - deeplinkFactory.handleDeeplink(deeplinkUri = receivedDeepLink, coroutineScope = lifecycleScope) + val receivedDeepLink = intent.data ?: deepLinkExtras + + when { + receivedDeepLink != null -> { + deeplinkFactory.handleDeeplink(deeplinkUri = receivedDeepLink, coroutineScope = lifecycleScope) + } + webLink?.validate() == true -> { + urlOpener.openUrl(webLink) + } + } } else { deepLinksRegistry.launch(intent) } diff --git a/app/src/main/java/com/tangem/tap/common/pushes/TangemPushNotificationService.kt b/app/src/main/java/com/tangem/tap/common/pushes/TangemPushNotificationService.kt index 8f984c76f0..23a6725255 100644 --- a/app/src/main/java/com/tangem/tap/common/pushes/TangemPushNotificationService.kt +++ b/app/src/main/java/com/tangem/tap/common/pushes/TangemPushNotificationService.kt @@ -16,6 +16,7 @@ import coil.request.ImageRequest import com.google.firebase.messaging.FirebaseMessagingService import com.google.firebase.messaging.RemoteMessage import com.tangem.core.deeplink.DEEPLINK_KEY +import com.tangem.core.deeplink.WEBLINK_KEY import com.tangem.domain.common.LogConfig import com.tangem.tap.MainActivity import com.tangem.tap.common.images.createCoilImageLoader @@ -39,6 +40,7 @@ internal class TangemPushNotificationService : FirebaseMessagingService() { val intent = Intent(applicationContext, MainActivity::class.java).apply { putExtra(DEEPLINK_KEY, message.data[DEEPLINK_KEY]) + putExtra(WEBLINK_KEY, message.data[WEBLINK_KEY]) putExtra(OnPushClickedIntentHandler.OPENED_FROM_GCM_PUSH, true) addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) } diff --git a/app/src/main/java/com/tangem/tap/routing/utils/DeepLinkFactory.kt b/app/src/main/java/com/tangem/tap/routing/utils/DeepLinkFactory.kt index 45bde26900..7c69a01577 100644 --- a/app/src/main/java/com/tangem/tap/routing/utils/DeepLinkFactory.kt +++ b/app/src/main/java/com/tangem/tap/routing/utils/DeepLinkFactory.kt @@ -126,17 +126,4 @@ internal class DeepLinkFactory @Inject constructor( return params } - - /** - * Check for malicious symbol in uri part - */ - private fun String.validate(): Boolean { - val regex = DEEPLINK_VALIDATION_REGEX.toRegex() - - return !regex.containsMatchIn(this) - } - - private companion object { - const val DEEPLINK_VALIDATION_REGEX = "['\";<>()+\\\\]" - } } \ No newline at end of file diff --git a/core/deep-links/src/main/kotlin/com/tangem/core/deeplink/DeepLinksRegistry.kt b/core/deep-links/src/main/kotlin/com/tangem/core/deeplink/DeepLinksRegistry.kt index 1d3ceb8718..3fa3e28ef8 100644 --- a/core/deep-links/src/main/kotlin/com/tangem/core/deeplink/DeepLinksRegistry.kt +++ b/core/deep-links/src/main/kotlin/com/tangem/core/deeplink/DeepLinksRegistry.kt @@ -6,6 +6,7 @@ import android.content.Intent * Key to pass deeplink via intent */ const val DEEPLINK_KEY = "deeplink" +const val WEBLINK_KEY = "link" // TODO: Add tests /** diff --git a/core/utils/src/main/java/com/tangem/utils/extensions/StringExt.kt b/core/utils/src/main/java/com/tangem/utils/extensions/StringExt.kt new file mode 100644 index 0000000000..07624b12c0 --- /dev/null +++ b/core/utils/src/main/java/com/tangem/utils/extensions/StringExt.kt @@ -0,0 +1,12 @@ +package com.tangem.utils.extensions + +private const val DEEPLINK_VALIDATION_REGEX = "['\";<>()+\\\\]" + +/** + * Check for malicious symbol in uri part + */ +fun String.validate(): Boolean { + val regex = DEEPLINK_VALIDATION_REGEX.toRegex() + + return !regex.containsMatchIn(this) +} \ No newline at end of file