Skip to content

CodeWebView can crash mid-tap if the chosen Custom Tabs browser is uninstalled #445

Description

@jim-daf

CodeWebView (app/src/main/java/com/thirtydegreesray/openhub/ui/widget/webview/CodeWebView.java:203-220) routes any tapped link out of the code-preview WebView through its startActivity(Uri) helper, which delegates to AppOpener.launchUrl:

private class WebClientN extends WebViewClient {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
        startActivity(request.getUrl());
        return true;
    }
}

...

private void startActivity(Uri uri){
    if(uri == null) return;
    AppOpener.launchUrl(getContext(), uri);
}

AppOpener.launchUrl -> openInCustomTabsOrBrowser -> customTabsIntent.launchUrl(context, Uri.parse(url)) is the path that gets used when a Custom Tabs package is detected. If the user uninstalls that browser between CustomTabsHelper.INSTANCE.getBestPackageName(context) and the subsequent launchUrl, the latter raises ActivityNotFoundException. The exception then propagates all the way back through shouldOverrideUrlLoading, which is the U04 pattern from the WebView posture notes: the WebView's host activity crashes mid-tap.

openInBrowser (the non-Custom-Tabs path) already has a fallback Toast, but the Custom Tabs path does not.

Suggested fix

Wrap the helper's AppOpener.launchUrl call in a try { ... } catch (ActivityNotFoundException) { } so the WebView's host activity survives the rare uninstall-mid-tap case:

private void startActivity(Uri uri){
    if(uri == null) return;
    try {
        AppOpener.launchUrl(getContext(), uri);
    } catch (android.content.ActivityNotFoundException e) {
        // chosen custom-tabs / browser package disappeared between
        // selection and launch
    }
}

A PR with the small change is open at #446.

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