Skip to content

CustomWebView can crash on link tap when no app handles the URL #484

@jim-daf

Description

@jim-daf

CustomWebView (app/src/main/java/app/simple/inure/decorations/views/CustomWebView.kt) routes off-asset URLs out via startActivity inside shouldOverrideUrlLoading:

override fun shouldOverrideUrlLoading(view: WebView, request: WebResourceRequest): Boolean {
    val url = request.url.toString()
    if (url.contains("asset/")) {
        view.loadUrl(url)
    } else {
        val intent = Intent(Intent.ACTION_VIEW, request.url)
        context.startActivity(intent)
    }
    return true
}

If nothing on the device can handle Intent.ACTION_VIEW for the URL, startActivity raises ActivityNotFoundException and whichever activity is hosting the CustomWebView (the Changelog / Credits / Trackers / preference web pages, etc.) crashes. There is no catch-all around this path - the exception just propagates out of WebViewClient.

This is easiest to hit when the user follows a mailto: link from the Credits screen on a device with no mail app installed, or any external link on a ROM that has the default browser disabled.

Suggested fix

Wrap context.startActivity(intent) in a try / catch for ActivityNotFoundException and log a warning. The link click becomes a no-op instead of a crash, which matches what a missing handler usually does on Android.

A small PR with that change is at #485.

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