feat: Diagnosedaten senden (Opt-out, Zahnrad-Knopf, einmaliger Hinweis)

Eigenes kleines Log (Abstuerze per UncaughtExceptionHandler, Jam- und
PC-Verbindungsfehler), gefiltert an POST /api/diag des Playtube-Dienstes,
kurz nach dem Start hoechstens alle 6 Stunden. Einstellungsdialog mit
Schalter, "Jetzt senden" und Installations-Kennung. Unit-Tests DiagReportTest.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-11-12 22:34:30 +01:00
co-authored by Claude Opus 5.5
parent d8d6ef4196
commit 9bab0d6a24
10 changed files with 421 additions and 4 deletions
@@ -0,0 +1,59 @@
package de.fojadrachi.playtube
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test
class DiagReportTest {
@Test
fun removesPrivateData() {
val cases = mapOf(
"Cookie: SAPISID=abc; HSID=def" to "cookie [entfernt]",
"jam: lade dQw4w9WgXcQ" to "jam: lade [video]",
"GET https://music.youtube.com/search?q=lieblingssong ok" to "GET https://music.youtube.com/search?[…] ok",
"token=abcdef123 weiter" to "token=[entfernt] weiter",
"{\"last_token\":\"xyz\"}" to "{\"last_token\":\"[entfernt]\"}",
"Mail [email protected]" to "Mail [e-mail]",
"Playlist PLabcdefghij1234567890XYZ" to "Playlist [id]",
"Sende Bearer eyJhbGciOiJIUzI1NiJ9" to "Sende Bearer [entfernt]",
)
for ((input, expected) in cases) assertEquals(input, expected, DiagReport.sanitize(input))
assertEquals("Jam: Verbindung fehlgeschlagen", DiagReport.sanitize("Jam: Verbindung fehlgeschlagen"))
assertEquals("a b", DiagReport.sanitize("a\u0000b"))
}
@Test
fun recognizesVideoIds() {
assertTrue(DiagReport.looksLikeVideoId("dQw4w9WgXcQ"))
assertFalse(DiagReport.looksLikeVideoId("Verbindunge"))
assertFalse(DiagReport.looksLikeVideoId("12345678901"))
}
@Test
fun collectsOnlyNewLines() {
val log = "[100] alt\n[200] Jam: Verbindung fehlgeschlagen\nkaputt\n[202] neu\n"
val collected = DiagReport.collect(log, 100)
assertEquals(listOf("[200] Jam: Verbindung fehlgeschlagen", "[202] neu"), collected.lines)
assertEquals(202L, collected.latest)
assertTrue(DiagReport.collect(log, 202).lines.isEmpty())
}
@Test
fun keepsTheNewestLines() {
val log = (1..1000).joinToString("\n") { "[$it] Zeile $it" }
val lines = DiagReport.collect(log, 0).lines
assertEquals(DiagReport.MAX_LINES, lines.size)
assertEquals("[701] Zeile 701", lines.first())
}
@Test
fun buildsReport() {
val lines = listOf("[1] Absturz in main: java.lang.IllegalStateException", "[2] ok")
val report = DiagReport.build("abc123abc123", "1.6.0", "15", "Google Pixel 9", lines)
assertEquals("android", report.getString("app"))
assertEquals("android-15", report.getString("platform"))
assertEquals(1, report.getJSONArray("errors").length())
assertFalse(report.getBoolean("includesTitles"))
}
}