From f0e4921ebd2bfa67c4c37db7fe0bed819a483103 Mon Sep 17 00:00:00 2001 From: wized2 Date: Tue, 17 Nov 2026 19:06:24 +0500 Subject: [PATCH] fix: locale-safe CSV/markdown export; site 404 + headers; troubleshooting docs Co-authored-by: aariz-agent --- 404.html | 28 +++++++++++ CHANGELOG.md | 8 +++ README.md | 4 ++ .../com/endroid/fern/monitor/HistoryExport.kt | 36 +++++++------ .../endroid/fern/HistoryExportLocaleTest.kt | 50 +++++++++++++++++++ docs/TROUBLESHOOTING.md | 22 ++++++++ vercel.json | 17 +++++++ 7 files changed, 151 insertions(+), 14 deletions(-) create mode 100644 404.html create mode 100644 app/src/test/java/com/endroid/fern/HistoryExportLocaleTest.kt create mode 100644 docs/TROUBLESHOOTING.md create mode 100644 vercel.json diff --git a/404.html b/404.html new file mode 100644 index 0000000..c5b3362 --- /dev/null +++ b/404.html @@ -0,0 +1,28 @@ + + + + + + + + Page not found · Fern + + + +
+

404

+

That page does not exist. Fern is still here, though.

+ Back to Fern +
+ + diff --git a/CHANGELOG.md b/CHANGELOG.md index 43f9930..8003841 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,14 @@ All notable changes to Fern are listed here. Versions follow the Android `versio ## Unreleased +**Fixes** +* CSV and Markdown exports no longer change with the phone language (a decimal comma used to split CSV columns on German/Spanish devices) +* Device names containing `|` or line breaks no longer break the Markdown snapshot table + +**Website & docs** +* Custom 404 page, security headers and asset caching (`vercel.json`) +* New `docs/TROUBLESHOOTING.md` + **Accessibility** * Gauges, peak chips and spec rows are announced as one item by TalkBack (e.g. "CPU 42 percent, 8 cores") instead of separate fragments * Decorative icons no longer read out "Decorative" diff --git a/README.md b/README.md index 2b1f03e..4ee1b4d 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,10 @@ Enable **Advanced mode** in Settings → grant Fern in [Shizuku](https://shizuku.rikka.app/) (or use root). When connected: richer CPU sampling and per-app memory / CPU on Active apps. +## Troubleshooting + +See [docs/TROUBLESHOOTING.md](docs/TROUBLESHOOTING.md). + ## Privacy No analytics SDK. Metrics stay on your device. Elevated access only runs what you enable. diff --git a/app/src/main/java/com/endroid/fern/monitor/HistoryExport.kt b/app/src/main/java/com/endroid/fern/monitor/HistoryExport.kt index 4e9c8ab..42e4181 100644 --- a/app/src/main/java/com/endroid/fern/monitor/HistoryExport.kt +++ b/app/src/main/java/com/endroid/fern/monitor/HistoryExport.kt @@ -1,10 +1,18 @@ package com.endroid.fern.monitor +import java.util.Locale + /** * Build CSV / markdown for session metric history and live snapshots. * Pure functions — safe for unit tests and UI share sheets. */ object HistoryExport { + /** Always US-style numbers: a decimal comma would split CSV columns on de/es/fr devices. */ + private fun f(fmt: String, v: Number): String = String.format(Locale.US, fmt, v) + + /** Keep a value inside one markdown table cell. */ + private fun cell(v: String): String = v.replace("|", "\\|").replace("\n", " ").replace("\r", " ") + fun batteryCsv(samples: List, startEpochMs: Long = System.currentTimeMillis()): String { val sb = StringBuilder() sb.appendLine("index,epoch_ms,battery_percent") @@ -33,9 +41,9 @@ object HistoryExport { for (i in 0 until n) { sb.append(i).append(',') .append(startEpochMs + i.toLong() * intervalMs).append(',') - .append(cpu.getOrNull(i)?.let { "%.2f".format(it) } ?: "").append(',') - .append(ram.getOrNull(i)?.let { "%.2f".format(it) } ?: "").append(',') - .append(battery.getOrNull(i)?.let { "%.2f".format(it) } ?: "") + .append(cpu.getOrNull(i)?.let { f("%.2f", it) } ?: "").append(',') + .append(ram.getOrNull(i)?.let { f("%.2f", it) } ?: "").append(',') + .append(battery.getOrNull(i)?.let { f("%.2f", it) } ?: "") .append('\n') } return sb.toString() @@ -69,19 +77,19 @@ object HistoryExport { appendLine() appendLine("| Field | Value |") appendLine("| --- | --- |") - appendLine("| Device | $deviceModel |") - appendLine("| Android | $androidVersion (API $sdkInt) |") - appendLine("| CPU | ${"%.1f".format(cpuPercent)}% · $cpuCores cores · $cpuHardware |") - appendLine("| RAM | $ramUsedMb / $ramTotalMb MB (${"%.1f".format(ramPercent)}%) |") + appendLine("| Device | ${cell(deviceModel)} |") + appendLine("| Android | ${cell(androidVersion)} (API $sdkInt) |") + appendLine("| CPU | ${f("%.1f", cpuPercent)}% · $cpuCores cores · ${cell(cpuHardware)} |") + appendLine("| RAM | $ramUsedMb / $ramTotalMb MB (${f("%.1f", ramPercent)}%) |") appendLine( - "| Battery | $batteryPercent% · ${if (batteryCharging) "charging" else "discharging"} · $batteryHealth |" + "| Battery | $batteryPercent% · ${if (batteryCharging) "charging" else "discharging"} · ${cell(batteryHealth)} |" ) - batteryTempC?.let { appendLine("| Battery temp | ${"%.1f".format(it)}°C |") } - appendLine("| Thermal | $thermalLabel |") - appendLine("| Network | $networkLabel · ${"%.1f".format(networkKBps)} KB/s |") - appendLine("| Uptime | ${"%.1f".format(uptimeHours)} h |") - appendLine("| Session peak CPU / RAM | ${"%.1f".format(peakCpu)}% / ${"%.1f".format(peakRam)}% |") - appendLine("| Session avg CPU / RAM | ${"%.1f".format(avgCpu)}% / ${"%.1f".format(avgRam)}% |") + batteryTempC?.let { appendLine("| Battery temp | ${f("%.1f", it)}°C |") } + appendLine("| Thermal | ${cell(thermalLabel)} |") + appendLine("| Network | ${cell(networkLabel)} · ${f("%.1f", networkKBps)} KB/s |") + appendLine("| Uptime | ${f("%.1f", uptimeHours)} h |") + appendLine("| Session peak CPU / RAM | ${f("%.1f", peakCpu)}% / ${f("%.1f", peakRam)}% |") + appendLine("| Session avg CPU / RAM | ${f("%.1f", avgCpu)}% / ${f("%.1f", avgRam)}% |") appendLine() appendLine("_Exported offline from Fern. No account required._") } diff --git a/app/src/test/java/com/endroid/fern/HistoryExportLocaleTest.kt b/app/src/test/java/com/endroid/fern/HistoryExportLocaleTest.kt new file mode 100644 index 0000000..3a997ec --- /dev/null +++ b/app/src/test/java/com/endroid/fern/HistoryExportLocaleTest.kt @@ -0,0 +1,50 @@ +package com.endroid.fern + +import com.endroid.fern.monitor.HistoryExport +import org.junit.Assert.assertEquals +import org.junit.Assert.assertFalse +import org.junit.Assert.assertTrue +import org.junit.Test +import java.util.Locale + +/** Exports must not change with the device language (a decimal comma would split CSV columns). */ +class HistoryExportLocaleTest { + + private fun withLocale(l: Locale, block: () -> T): T { + val old = Locale.getDefault() + Locale.setDefault(l) + try { return block() } finally { Locale.setDefault(old) } + } + + @Test + fun sessionCsvUsesDotDecimalsInGerman() { + val csv = withLocale(Locale.GERMANY) { + HistoryExport.sessionCsv(listOf(10.5f), listOf(30.25f), listOf(90f), 1000, 0L) + } + val row = csv.lines()[1] + assertEquals("0,0,10.50,30.25,90.00", row) + assertEquals(5, row.split(',').size) + } + + @Test + fun markdownUsesDotDecimalsInSpanish() { + val md = withLocale(Locale("es", "ES")) { snapshot("Pixel") } + assertTrue(md.contains("12.5%")) + assertFalse(md.contains("12,5%")) + } + + @Test + fun markdownEscapesPipesInTextFields() { + val md = snapshot("Model | X\nline2") + assertTrue(md.contains("| Device | Model \\| X line2 |")) + } + + private fun snapshot(model: String) = HistoryExport.snapshotMarkdown( + deviceModel = model, androidVersion = "14", sdkInt = 34, + cpuPercent = 12.5f, cpuCores = 8, cpuHardware = "tensor", + ramUsedMb = 4000, ramTotalMb = 8000, ramPercent = 50f, + batteryPercent = 80, batteryCharging = false, batteryHealth = "Good", batteryTempC = 31.2f, + thermalLabel = "None", networkLabel = "Wi-Fi", networkKBps = 12f, + uptimeHours = 3.5f, peakCpu = 40f, peakRam = 60f, avgCpu = 15f, avgRam = 45f, + ) +} diff --git a/docs/TROUBLESHOOTING.md b/docs/TROUBLESHOOTING.md new file mode 100644 index 0000000..3bc178e --- /dev/null +++ b/docs/TROUBLESHOOTING.md @@ -0,0 +1,22 @@ +# Troubleshooting + +## Per-app CPU / RAM is empty on Active apps +Per-app numbers need elevated access. Turn on **Advanced mode** in Settings, then grant Fern in [Shizuku](https://shizuku.rikka.app/) (or allow root). Without it Android only shows Fern what a normal app may see. + +## Shizuku says Fern is not authorised +Open Shizuku, make sure it is running (restart it after a reboot unless you use root or wireless debugging auto-start), then open Fern and grant the permission again. + +## The overlay does not appear +The overlay needs the "Display over other apps" permission. Enable it for Fern in system settings, then switch the overlay on again in Fern. + +## Readings stop when the screen is off +Some vendors stop background work aggressively. Set Fern's battery usage to "Unrestricted" (wording varies by device) if you want continuous history. + +## CPU shows a different value than another monitor +Fern samples the whole device from kernel counters over a short window. Other apps may use a different interval or exclude some cores, so small differences are normal. + +## Exported CSV opens in one column +Fern writes comma-separated values with dot decimals. In your spreadsheet, choose "Comma" as the separator when importing. + +## Still stuck? +Open an issue with your device model, Android version, and whether Advanced mode is on: https://github.com/wized2/Fern/issues/new/choose diff --git a/vercel.json b/vercel.json new file mode 100644 index 0000000..bb91fa4 --- /dev/null +++ b/vercel.json @@ -0,0 +1,17 @@ +{ + "headers": [ + { + "source": "/(.*)", + "headers": [ + { "key": "X-Content-Type-Options", "value": "nosniff" }, + { "key": "Referrer-Policy", "value": "strict-origin-when-cross-origin" }, + { "key": "X-Frame-Options", "value": "DENY" }, + { "key": "Permissions-Policy", "value": "camera=(), microphone=(), geolocation=()" } + ] + }, + { + "source": "/assets/(.*)", + "headers": [{ "key": "Cache-Control", "value": "public, max-age=604800" }] + } + ] +}