Skip to content

DocsViewer and BackupWebView crash when no app handles a tapped link #75

Description

@jim-daf

Both WebView screens send tapped links to the system browser without protection:

DocsViewerActivity.kt:69:

override fun shouldOverrideUrlLoading(
    view: WebView?,
    request: WebResourceRequest?
): Boolean {
    request?.url?.let { url ->
        val intent = Intent(Intent.ACTION_VIEW, url)
        context.startActivity(intent)
        return true
    }
    return false
}

BackupWebView.kt:75:

override fun shouldOverrideUrlLoading(
    view: WebView?,
    request: WebResourceRequest?
): Boolean {
    request?.url?.let { url ->
        coroutineScope.launch(Dispatchers.IO) {
            val intent = Intent(Intent.ACTION_VIEW, url)
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
            context.startActivity(intent)
        }
        return true
    }
    return false
}

If the device has no app that can handle the URL (no browser at all, an unusual scheme, etc.) startActivity raises ActivityNotFoundException. In DocsViewerActivity the exception propagates back through shouldOverrideUrlLoading and the docs viewer crashes. In BackupWebView the exception happens on a background coroutine and brings the process down even more abruptly.

Suggested fix

Wrap both calls in try { ... } catch (ActivityNotFoundException) { ... } and fall back to a short Toast (no_app_to_open_link). On the BackupWebView side switch to Main for the Toast since it's launched from Dispatchers.IO.

A PR with the two guards and the matching string is open at #76.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions