From 804bfcb9b98433ab9f601f2f7018e24784bf6838 Mon Sep 17 00:00:00 2001 From: Noah Godel Date: Tue, 3 Mar 2026 14:55:43 +0100 Subject: [PATCH] Fix unhandled exceptions in route decision handlers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit BrowserTabRouteDecisionHandler: catch ActivityNotFoundException when no browser with Custom Tabs support is installed on the device. SystemNavigationRouteDecisionHandler: catch SecurityException in addition to the existing ActivityNotFoundException — thrown when the target activity is found but not accessible, e.g. android:exported="false" or a permission requirement the calling app does not satisfy. --- .../routing/BrowserTabRouteDecisionHandler.kt | 20 ++++++++++++------- .../SystemNavigationRouteDecisionHandler.kt | 2 ++ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/navigation-fragments/src/main/java/dev/hotwire/navigation/routing/BrowserTabRouteDecisionHandler.kt b/navigation-fragments/src/main/java/dev/hotwire/navigation/routing/BrowserTabRouteDecisionHandler.kt index dc9d1888..eae3fd1a 100644 --- a/navigation-fragments/src/main/java/dev/hotwire/navigation/routing/BrowserTabRouteDecisionHandler.kt +++ b/navigation-fragments/src/main/java/dev/hotwire/navigation/routing/BrowserTabRouteDecisionHandler.kt @@ -1,10 +1,12 @@ package dev.hotwire.navigation.routing +import android.content.ActivityNotFoundException import androidx.browser.customtabs.CustomTabColorSchemeParams import androidx.browser.customtabs.CustomTabsIntent import androidx.core.net.toUri import com.google.android.material.R import dev.hotwire.navigation.activities.HotwireActivity +import dev.hotwire.navigation.logging.logError import dev.hotwire.navigation.navigator.NavigatorConfiguration import dev.hotwire.navigation.util.colorFromThemeAttr @@ -39,13 +41,17 @@ class BrowserTabRouteDecisionHandler : Router.RouteDecisionHandler { .setNavigationBarColor(color) .build() - CustomTabsIntent.Builder() - .setShowTitle(true) - .setShareState(CustomTabsIntent.SHARE_STATE_ON) - .setUrlBarHidingEnabled(false) - .setDefaultColorSchemeParams(colorParams) - .build() - .launchUrl(activity, location.toUri()) + try { + CustomTabsIntent.Builder() + .setShowTitle(true) + .setShareState(CustomTabsIntent.SHARE_STATE_ON) + .setUrlBarHidingEnabled(false) + .setDefaultColorSchemeParams(colorParams) + .build() + .launchUrl(activity, location.toUri()) + } catch (e: ActivityNotFoundException) { + logError("BrowserTabRouteDecisionHandler", e) + } return Router.Decision.CANCEL } diff --git a/navigation-fragments/src/main/java/dev/hotwire/navigation/routing/SystemNavigationRouteDecisionHandler.kt b/navigation-fragments/src/main/java/dev/hotwire/navigation/routing/SystemNavigationRouteDecisionHandler.kt index 7b5198f0..603ac673 100644 --- a/navigation-fragments/src/main/java/dev/hotwire/navigation/routing/SystemNavigationRouteDecisionHandler.kt +++ b/navigation-fragments/src/main/java/dev/hotwire/navigation/routing/SystemNavigationRouteDecisionHandler.kt @@ -31,6 +31,8 @@ class SystemNavigationRouteDecisionHandler : Router.RouteDecisionHandler { activity.startActivity(intent) } catch (e: ActivityNotFoundException) { logError("SystemNavigationRouteDecisionHandler", e) + } catch (e: SecurityException) { + logError("SystemNavigationRouteDecisionHandler", e) } return Router.Decision.CANCEL