logviewer: do not crash Report when no app handles web links
- Commit
cf8569583f39eda92bbf6ce38f13be661a613271- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-07 20:04 UTC (28 days ago)
- Parents
cafe233
Symptom: on a build with no browser (nothing resolves an https ACTION_VIEW), tapping Report - a primary action of the error report screen - threw ActivityNotFoundException out of LogViewerController.report() and crashed the viewer. Root cause: report() called startActivity on an implicit VIEW intent with no handler check and no catch. Every other intent this app fires is explicit (its own activities) or a system chooser, so this was the one unguarded implicit launch. Fix: catch ActivityNotFoundException and show a message instead. copy() has already run by then (deliberate ordering: file the issue by pasting), so the message tells the user the log was copied and they lose nothing. Verification: LogViewerControllerTest green, including the existing 'report copies then opens the issue tracker' happy path. A regression test for the missing-browser branch is not feasible under Robolectric, whose shadow activity records implicit starts instead of resolving them, so it cannot throw here.
Diff
logviewer/src/main/java/com/vayunmathur/logviewer/platform/LogViewerController.kt
diff --git a/logviewer/src/main/java/com/vayunmathur/logviewer/platform/LogViewerController.kt b/logviewer/src/main/java/com/vayunmathur/logviewer/platform/LogViewerController.ktindex 8b332b16c8..75970b5b37 100644--- a/logviewer/src/main/java/com/vayunmathur/logviewer/platform/LogViewerController.kt+++ b/logviewer/src/main/java/com/vayunmathur/logviewer/platform/LogViewerController.kt@@ -1,5 +1,6 @@ package com.vayunmathur.logviewer.platform +import android.content.ActivityNotFoundException import android.content.ClipData import android.content.ClipboardManager import android.content.Intent@@ -53,7 +54,14 @@ internal open class LogViewerController( */ override fun report() { copy()- activity.startActivity(Intent(Intent.ACTION_VIEW, ISSUES_URL.toUri()))+ try {+ activity.startActivity(Intent(Intent.ACTION_VIEW, ISSUES_URL.toUri()))+ } catch (e: ActivityNotFoundException) {+ // No browser (or anything else that handles https) on this build. The log is+ // already on the clipboard from copy() above, so say that instead of crashing+ // the viewer over its own Report button.+ AppMessages.show(activity.getString(R.string.error_no_app_opens_issue_tracker))+ } } override fun save(uri: Uri) = viewModel.save(uri)
logviewer/src/main/res/values/strings.xml
diff --git a/logviewer/src/main/res/values/strings.xml b/logviewer/src/main/res/values/strings.xmlindex 09d11bad29..f668b3462b 100644--- a/logviewer/src/main/res/values/strings.xml+++ b/logviewer/src/main/res/values/strings.xml@@ -32,6 +32,9 @@ <string name="action_more_info">More info</string> <!-- Message when the text tombstone backing "More info" could not be read. --> <string name="toast_unable_to_show_more_info">Unable to show more info</string>+ <!-- Message when Report cannot open the issue tracker because nothing on the device+ handles web links; the report has still been copied. -->+ <string name="error_no_app_opens_issue_tracker">No app found to open the issue tracker — the log was copied instead</string> <!-- Bottom button on the error report screen: opens the crashed app's log. --> <string name="action_show_log">Show log</string>