Modern Apps git

← Modern-Apps.git

logviewer: Assert filtering uses logcat's F, not the display letter A

Commit
b5ce9d9b1df359c27b5ce6509d983ce7623c382c
Author
Vayun Mathur <[email protected]>
When
2026-12-01 09:45 UTC (5 days ago)
Parents
8181e3b
LogLevel.letter conflated the display letter (title 'A+',
dropdown) with the logcat wire letter. They coincide for
V/D/I/W/E but diverge at priority 7 (ANDROID_LOG_FATAL),
which logcat spells F and nothing else accepts. Selecting
Assert therefore emitted '*:A', logcat exited non-zero with
'Invalid filter expression', read() mapped that to a silent
Unavailable, and the page called finishAndRemoveTask() —
picking Assert closed the viewer with no message.

LogLevel gains filterLetter (Assert -> F, else the display
letter) and the reader passes it; display strings and the
'level: assert' header are unchanged. Regression tests pin
the [V,D,I,W,E,F] mapping and that an Assert request issues
'*:F', loads, and keeps its display rendering (captured
'*:A' pre-fix). Verified: :logviewer:testDevUnitTest 164
tests pass; lint error is pre-existing on an untouched file.

Diff

logviewer/src/main/java/com/vayunmathur/logviewer/domain/LogLevel.kt
diff --git a/logviewer/src/main/java/com/vayunmathur/logviewer/domain/LogLevel.kt b/logviewer/src/main/java/com/vayunmathur/logviewer/domain/LogLevel.ktindex e27ed688c6..14189769f0 100644--- a/logviewer/src/main/java/com/vayunmathur/logviewer/domain/LogLevel.kt+++ b/logviewer/src/main/java/com/vayunmathur/logviewer/domain/LogLevel.kt@@ -4,9 +4,9 @@ package com.vayunmathur.logviewer.domain  * A logcat severity, and the two textual forms of it the app emits.  *  * [label] and [letter] are **wire format, not UI text**: [label] lowercased is the `level:` header- * line, and [letter] is both the `*:V` argument passed to `logcat` and the ` | E+` suffix in the- * title. They are deliberately not localised, so a report shared from a French phone reads the same- * as one shared from an English one. The dialog shows a translated name alongside.+ * line, and [letter] is the ` | E+` suffix in the title and the level dropdown's trigger. They are+ * deliberately not localised, so a report shared from a French phone reads the same as one shared+ * from an English one. The dialog shows a translated name alongside.  */ enum class LogLevel(val priority: Int, val label: String) {     Verbose(2, "Verbose"),@@ -19,6 +19,17 @@ enum class LogLevel(val priority: Int, val label: String) {      val letter: Char get() = label[0] +    /**+     * The `*:V` argument passed to `logcat`. The same as [letter] except at [Assert]: priority 7+     * is `ANDROID_LOG_FATAL` natively, whose filter letter is `F`, and `logcat` rejects an+     * unrecognised priority letter outright (it exits non-zero, which the reader maps to an+     * unavailable log) - so `*:A` could never show anything.+     */+    val filterLetter: Char get() = when (this) {+        Assert -> 'F'+        else -> letter+    }+     val headerValue: String get() = label.lowercase()      /** Shared constants and helpers for LogLevel. */
logviewer/src/main/java/com/vayunmathur/logviewer/platform/LogcatReader.kt
diff --git a/logviewer/src/main/java/com/vayunmathur/logviewer/platform/LogcatReader.kt b/logviewer/src/main/java/com/vayunmathur/logviewer/platform/LogcatReader.ktindex 70ca52a6ca..25c6bff384 100644--- a/logviewer/src/main/java/com/vayunmathur/logviewer/platform/LogcatReader.kt+++ b/logviewer/src/main/java/com/vayunmathur/logviewer/platform/LogcatReader.kt@@ -104,7 +104,7 @@ internal object LogcatReader {         command += "--format=" + format.joinToString(",")          if (request.filterRegex.isNotEmpty()) command += "--regex=" + request.filterRegex-        command += "*:${request.level.letter}"+        command += "*:${request.level.filterLetter}"          var targetAppInfo: ApplicationInfo? = null         if (request.targetPackage != null) {
logviewer/src/test/java/com/vayunmathur/logviewer/domain/LogLevelFilterLetterTest.kt
diff --git a/logviewer/src/test/java/com/vayunmathur/logviewer/domain/LogLevelFilterLetterTest.kt b/logviewer/src/test/java/com/vayunmathur/logviewer/domain/LogLevelFilterLetterTest.ktnew file mode 100644index 0000000000..32a68c8828--- /dev/null+++ b/logviewer/src/test/java/com/vayunmathur/logviewer/domain/LogLevelFilterLetterTest.kt@@ -0,0 +1,25 @@+package com.vayunmathur.logviewer.domain++import kotlin.test.Test+import kotlin.test.assertEquals++class LogLevelFilterLetterTest {++    @Test+    fun `filter letter is the letter logcat accepts for every level`() {+        // logcat's filter grammar (FILTERSPEC in `logcat --help`, filterCharToPri in+        // liblog) accepts only V, D, I, W, E, F and S: priority 7 is ANDROID_LOG_FATAL,+        // spelled F. `*:A` is rejected and logcat exits non-zero.+        assertEquals(+            listOf('V', 'D', 'I', 'W', 'E', 'F'),+            LogLevel.entries.map { it.filterLetter },+        )+    }++    @Test+    fun `assert keeps its display letter while filtering as fatal`() {+        assertEquals('A', LogLevel.Assert.letter)+        assertEquals('F', LogLevel.Assert.filterLetter)+        assertEquals("assert", LogLevel.Assert.headerValue)+    }+}
logviewer/src/test/java/com/vayunmathur/logviewer/platform/LogcatReaderTest.kt
diff --git a/logviewer/src/test/java/com/vayunmathur/logviewer/platform/LogcatReaderTest.kt b/logviewer/src/test/java/com/vayunmathur/logviewer/platform/LogcatReaderTest.ktindex adae1dddea..72b0cb9a83 100644--- a/logviewer/src/test/java/com/vayunmathur/logviewer/platform/LogcatReaderTest.kt+++ b/logviewer/src/test/java/com/vayunmathur/logviewer/platform/LogcatReaderTest.kt@@ -69,6 +69,27 @@ class LogcatReaderTest {         assertEquals("System log | MR | E+ | Foo.*", doc.title)     } +    @Test+    fun `assert level filters as fatal, the only priority-7 letter logcat accepts`() {+        var captured: List<String>? = null+        LogcatReader.executeCommand = { command ->+            captured = command+            listOf("fatal line").asSequence()+        }+        val doc = loaded(+            LogcatReader.read(+                context,+                LogcatReader.Request(null, LogcatReader.DEFAULT_BUFFERS, LogLevel.Assert, ""),+            )+        )+        // `*:A` makes the real logcat exit non-zero ("Invalid filter expression"), which+        // read() maps to a silent Unavailable; `*:F` is priority 7 (ANDROID_LOG_FATAL).+        assertEquals("*:F", captured!!.last())+        assertEquals(listOf("fatal line"), doc.bodyLines)+        assertTrue(doc.headerLines.contains("level: assert"))+        assertEquals("System log | A+", doc.title)+    }+     @Test     fun `default buffers and verbose level leave the plain system title`() {         LogcatReader.executeCommand = { emptySequence() }