diff --git a/CHANGELOG.md b/CHANGELOG.md index 003be9c..39aade7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,13 @@ Versions after 2.17 are `MAJOR.MINOR.PATCH` (2.17 is followed by 2.17.1 or 2.18. `docs/testing.md`, "Versions and releases"); the headings below keep the numbers as they were released. +## 2.29.1 — 2026-11-23 + +- The debug page in the brass 1.5.0 fonts of the brand (#304): headings and buttons in Brass + Serif (IBM Plex Serif Bold), the rest in Brass Mono (IBM Plex Mono). The app serves them + itself from its assets (`/fonts/.woff2`, cached for a year, asked with the app's + version); `OFL.txt` lies next to them. The Android menus and dialogs are unchanged. + ## 2.29.0 — 2026-11-23 - camex 6.2.0 in the tunnel (#302). Settings has a new optional **Network selector** field diff --git a/android/app/build.gradle b/android/app/build.gradle index f88c541..e01ba95 100755 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -26,8 +26,8 @@ android { applicationId "com.openipc.decoder" minSdk 21 targetSdk 36 - versionCode 70 - versionName "2.29.0" + versionCode 71 + versionName "2.29.1" // Keep only these locales of the libraries' resources, as in the other OpenIPC apps resourceConfigurations += ['en', 'ru', 'zh-rCN'] diff --git a/android/app/src/main/assets/fonts/BrassMono-Bold.woff2 b/android/app/src/main/assets/fonts/BrassMono-Bold.woff2 new file mode 100644 index 0000000..4ecb73b Binary files /dev/null and b/android/app/src/main/assets/fonts/BrassMono-Bold.woff2 differ diff --git a/android/app/src/main/assets/fonts/BrassMono-Regular.woff2 b/android/app/src/main/assets/fonts/BrassMono-Regular.woff2 new file mode 100644 index 0000000..a52c42e Binary files /dev/null and b/android/app/src/main/assets/fonts/BrassMono-Regular.woff2 differ diff --git a/android/app/src/main/assets/fonts/BrassSerif-Bold.woff2 b/android/app/src/main/assets/fonts/BrassSerif-Bold.woff2 new file mode 100644 index 0000000..b27bd0b Binary files /dev/null and b/android/app/src/main/assets/fonts/BrassSerif-Bold.woff2 differ diff --git a/android/app/src/main/assets/fonts/OFL.txt b/android/app/src/main/assets/fonts/OFL.txt new file mode 100644 index 0000000..c35c4c6 --- /dev/null +++ b/android/app/src/main/assets/fonts/OFL.txt @@ -0,0 +1,93 @@ +Copyright © 2017 IBM Corp. with Reserved Font Name "Plex" + +This Font Software is licensed under the SIL Open Font License, Version 1.1. + +This license is copied below, and is also available with a FAQ at: http://scripts.sil.org/OFL + + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/android/app/src/main/java/com/openipc/decoder/DebugServer.java b/android/app/src/main/java/com/openipc/decoder/DebugServer.java index 8216db1..456d355 100644 --- a/android/app/src/main/java/com/openipc/decoder/DebugServer.java +++ b/android/app/src/main/java/com/openipc/decoder/DebugServer.java @@ -18,11 +18,13 @@ import java.net.Socket; import java.nio.charset.StandardCharsets; import java.text.SimpleDateFormat; +import java.util.Arrays; import java.util.Date; import java.util.List; import java.util.Locale; import java.util.Map; import java.util.concurrent.ArrayBlockingQueue; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.RejectedExecutionException; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledThreadPoolExecutor; @@ -383,7 +385,49 @@ void serve(OutputStream out, String path, String query) throws IOException { + "\"\r\n"); break; default: - reply(out, 404, "text/plain", "Not found\n"); + // the page's fonts (brass 1.5.0, #304): a year in the cache, the page asks + // with ?v=, so a new version of the app gets them again + byte[] font = path.startsWith("/fonts/") ? font(path.substring(7)) : null; + if (font != null) { + reply(out, 200, "font/woff2", font, "", FONT_CACHE); + } else { + reply(out, 404, "text/plain", "Not found\n"); + } + } + } + + // ====================== Fonts (#304) ====================== + + /** The fonts the page asks for, from the brand's brass 1.5.0: nothing else is served. */ + static final String[] FONTS = {"BrassSerif-Bold.woff2", "BrassMono-Regular.woff2", + "BrassMono-Bold.woff2"}; + + static final String FONT_CACHE = "max-age=31536000, immutable"; + + /** Opens a file of the app's assets; the tests read the files of the source tree. */ + interface Assets { + InputStream open(String name) throws IOException; + } + + static Assets assets = name -> App.context.getAssets().open(name); + + private static final Map fontCache = new ConcurrentHashMap<>(); + + /** A font of {@link #FONTS} from assets/fonts/, read once; null for any other name. */ + static byte[] font(String name) { + if (!Arrays.asList(FONTS).contains(name)) return null; + byte[] cached = fontCache.get(name); + if (cached != null) return cached; + try (InputStream in = assets.open("fonts/" + name)) { + ByteArrayOutputStream b = new ByteArrayOutputStream(32 * 1024); + byte[] buf = new byte[8192]; + for (int n; (n = in.read(buf)) > 0; ) b.write(buf, 0, n); + byte[] data = b.toByteArray(); + fontCache.put(name, data); + return data; + } catch (IOException | RuntimeException e) { + Log.w(TAG, "Font " + name + " not readable", e); + return null; } } @@ -591,10 +635,15 @@ private static void reply(OutputStream out, int code, String type, byte[] data) /** {@code extra}: more header lines, each ending with \r\n. */ private static void reply(OutputStream out, int code, String type, byte[] data, String extra) throws IOException { + reply(out, code, type, data, extra, "no-store"); + } + + private static void reply(OutputStream out, int code, String type, byte[] data, String extra, + String cache) throws IOException { String head = "HTTP/1.1 " + code + " " + reason(code) + "\r\n" + "Content-Type: " + type + "\r\n" + "Content-Length: " + data.length + "\r\n" - + "Cache-Control: no-store\r\n" + + "Cache-Control: " + cache + "\r\n" + (code == 405 ? "Allow: GET\r\n" : "") + extra + "Connection: close\r\n\r\n"; @@ -734,7 +783,7 @@ private static void closeQuietly(Socket s) { + "" + "

Decoder

" + "
Elegant video player
" diff --git a/android/app/src/test/java/com/openipc/decoder/DebugServerTest.java b/android/app/src/test/java/com/openipc/decoder/DebugServerTest.java index b4767c5..9f24dac 100644 --- a/android/app/src/test/java/com/openipc/decoder/DebugServerTest.java +++ b/android/app/src/test/java/com/openipc/decoder/DebugServerTest.java @@ -290,6 +290,60 @@ public void pageLinksTheReport() throws IOException { assertFalse(page.substring(page.indexOf("\r\n\r\n") + 4).contains("\n")); } + // ====================== Fonts (#304) ====================== + + private static byte[] file(String path) throws IOException { + return java.nio.file.Files.readAllBytes(java.nio.file.Paths.get(path)); + } + + @Test + public void fontsAreServedFromTheAssetsWithAYearInTheCache() throws IOException { + DebugServer.Assets was = DebugServer.assets; + DebugServer.assets = name -> new java.io.FileInputStream("src/main/assets/" + name); + try { + for (String name : DebugServer.FONTS) { + ByteArrayOutputStream out = new ByteArrayOutputStream(); + new DebugServer().serve(out, "/fonts/" + name, "v=1"); + byte[] all = out.toByteArray(); + String text = new String(all, StandardCharsets.ISO_8859_1); + int body = text.indexOf("\r\n\r\n") + 4; + String head = text.substring(0, body); + assertTrue(head, head.startsWith("HTTP/1.1 200 ")); + assertTrue(head, head.contains("Content-Type: font/woff2\r\n")); + assertTrue(head, head.contains("Cache-Control: max-age=31536000, immutable\r\n")); + assertTrue(name, Arrays.equals(file("src/main/assets/fonts/" + name), + Arrays.copyOfRange(all, body, all.length))); + } + for (String other : new String[] {"/fonts/OFL.txt", "/fonts/../fonts/BrassMono-Bold.woff2", + "/fonts/", "/fonts/x.woff2"}) { + ByteArrayOutputStream out = new ByteArrayOutputStream(); + new DebugServer().serve(out, other, ""); + assertTrue(other, out.toString("UTF-8").startsWith("HTTP/1.1 404 ")); + } + } finally { + DebugServer.assets = was; + } + } + + @Test + public void pageUsesTheBrassFontsOnlyThroughTheTokens() throws IOException { + ByteArrayOutputStream out = new ByteArrayOutputStream(); + new DebugServer().serve(out, "/", ""); + String page = out.toString("UTF-8"); + for (String name : DebugServer.FONTS) { + assertTrue(name, page.contains("url(fonts/" + name + "?v=" + BuildConfig.VERSION_NAME + ")")); + } + assertTrue(page.contains("--serif:'Brass Serif',Georgia,'Times New Roman',serif;")); + assertTrue(page.contains("--mono:'Brass Mono','Courier New',monospace;")); + String rest = page.replace("--serif:'Brass Serif',Georgia,'Times New Roman',serif;", "") + .replace("--mono:'Brass Mono','Courier New',monospace;", ""); + for (String literal : new String[] {"Georgia", "Courier", "Times New Roman", "system-ui", + "sans-serif"}) { + assertFalse(literal, rest.contains(literal)); + } + assertTrue(page.contains(".brass h1,.brass h2,.brass h3{font-family:var(--serif)}")); + } + // ====================== Web page password ====================== private static String basic(String userPass) { diff --git a/docs/debug.md b/docs/debug.md index 74ecdea..5b4f710 100644 --- a/docs/debug.md +++ b/docs/debug.md @@ -22,6 +22,7 @@ While the app runs it serves its debug information over HTTP on port **8085**, f | `/log` | the last 500 lines of the app's log, see [Log](#log) | | `/report.txt` | a header, `/stats.json` and `/log` in one file, downloaded as `report-YYYYMMDD-HHMMSS.txt`, see [Save report](#save-report) | | `/jieli-frame.jpg`, `/jieli-dropped.bin` | the last JPEG of a `jieli://` slot in the single view as the toy sent it, and the last frame that could not be put together ([toys.md](toys.md#hf--jieli-toys)) | +| `/fonts/.woff2` | the page's fonts (brass 1.5.0: Brass Serif and Brass Mono), cached for a year; only these three files | - Only clients on the local network are answered; others get `403`. With a password set in **Network** (**Web page password**) the browser asks for it (any user name; `curl -u :`). The rule and what is hidden: [security.md](security.md#debug-server). - `GET` only (`405` otherwise), one request per connection, `Cache-Control: no-store`. @@ -42,7 +43,7 @@ The device's addresses are in `addresses` of `/stats.json`, and the [U cell](usa `http://:8085/` -- The page has the "brass" look of our apps' pages: the title **Decoder** with the version, a panel with the plate **Video wall**, the links **JSON**, **Log** and **Report** (`/report.txt`), the switches **Info** and **Snapshot**, a board of rows with lamps and the wall of frames below it. +- The page has the "brass" look of our apps' pages, in the brass fonts (headings and buttons in Brass Serif, the rest in Brass Mono, served by the app itself): the title **Decoder** with the version, a panel with the plate **Video wall**, the links **JSON**, **Log** and **Report** (`/report.txt`), the switches **Info** and **Snapshot**, a board of rows with lamps and the wall of frames below it. - The snapshot is laid out like the screen, with each cell's slot, camera host, transport, size, fps and losses (in red) drawn over it. A decoded rate below 90 % of the received one is shown in amber. The camera on screen has an amber frame. - **Info On / Off** hides the text over the cells (and the list below them on a narrow screen), leaving only the picture. It is **Off** until switched on; the choice is remembered in the browser. - **Snapshot 3 s / 5 s / 10 s**: how often the picture is refreshed (default 5 s). `/stats.json` is fetched every 1.5 s. Both only while the tab is visible. diff --git a/tests/e2e.sh b/tests/e2e.sh index 2a10607..1d3e19c 100755 --- a/tests/e2e.sh +++ b/tests/e2e.sh @@ -36,6 +36,10 @@ # NETEM_IMAGE image with tc, built from tests/netem when missing (default decoder-netem) # TRANSPORT the tunnel's transport in Network: UDP or TCP (default UDP); the hub takes # both on one port, the Linux edge stays on UDP +# PAGE_SHOTS 1: also the debug page in a headless Chromium (#304): the brass fonts loaded +# (document.fonts) and tests/out/page-1280.png, page-400.png +# CHROME_IMAGE headless Chromium for PAGE_SHOTS (default zenika/alpine-chrome:latest) +# NODE_IMAGE Node.js for PAGE_SHOTS's DevTools client (default node:24-slim) # SHOTS 1: slot 1 over TCP, a lighter camera stream and screenshots in tests/out/shots # (the picture through the tunnel, the menu, the Network dialog); the emulator's # software decoder still drops some frames: README pictures come from a TV box @@ -78,7 +82,7 @@ ok() { pass=$((pass + 1)); echo "PASS: $*"; } bad() { fail=$((fail + 1)); echo "FAIL: $*"; } cleanup() { - docker rm -f "$NAME" "$CAM" "$PEER" "$HUB" >/dev/null 2>&1 || true + docker rm -f "$NAME" "$CAM" "$PEER" "$HUB" "$NAME-chrome" >/dev/null 2>&1 || true docker network rm "$NET" >/dev/null 2>&1 || true } trap cleanup EXIT INT TERM @@ -425,6 +429,25 @@ if [ -z "$SHOTS" ]; then close_dialog fi +# the debug page in a browser (#304): Chromium and its DevTools client in the emulator +# container's network, the page through adb forward there (no port on the host) +if [ -n "${PAGE_SHOTS:-}" ]; then + # a failed start is a failed check, not the end of the run (Qodo on #305) + if $ADB forward tcp:18085 tcp:8085 >/dev/null && + docker run -d --name "$NAME-chrome" --network "container:$NAME" --pull never \ + "${CHROME_IMAGE:-zenika/alpine-chrome:latest}" --headless --no-sandbox \ + --disable-gpu --hide-scrollbars --remote-debugging-address=127.0.0.1 \ + --remote-debugging-port=9222 about:blank >/dev/null && + timeout 120 docker run --rm --network "container:$NAME" --pull never -u "$UID_GID" \ + -v "$ROOT/tests:/t:ro" -v "$OUT:/out" "${NODE_IMAGE:-node:24-slim}" \ + node /t/page-fonts.mjs http://127.0.0.1:9222 http://127.0.0.1:18085/ \ + "x:$WEB_PASSWORD" /out > "$OUT/page-fonts.json" 2>&1; then + ok "the debug page: Brass Serif and Brass Mono loaded (tests/out/page-1280.png, page-400.png)" + else bad "the debug page: brass fonts not loaded or no browser (tests/out/page-fonts.json)"; fi + docker rm -f "$NAME-chrome" >/dev/null 2>&1 || true + $ADB forward --remove tcp:18085 >/dev/null 2>&1 || true +fi + # the tunnel restarts in the same process: Network → Save stops it and starts it again with the # saved values (a second run of the tunnel's native code in one process); the TUN comes back and the # camera's address answers again diff --git a/tests/page-fonts.mjs b/tests/page-fonts.mjs new file mode 100644 index 0000000..e227207 --- /dev/null +++ b/tests/page-fonts.mjs @@ -0,0 +1,77 @@ +// Copyright (c) OpenIPC https://openipc.org Prosperity Public License 3.0.0 +// +// page-fonts.mjs — the debug page in a headless Chromium (#304): which brass fonts +// document.fonts has loaded, and full-page screenshots 1280 and 400 px wide. +// Runs in node:24 (fetch and WebSocket built in) next to Chromium's DevTools port. +// +// Usage: node page-fonts.mjs +import fs from 'node:fs'; + +const [, , devtools, page, credentials, out] = process.argv; +const sleep = (ms) => new Promise((r) => setTimeout(r, ms)); +for (let i = 0; ; i++) { + try { await (await fetch(devtools + '/json/version')).json(); break; } catch (e) { + if (i > 50) throw new Error('no DevTools at ' + devtools); + await sleep(200); + } +} +const target = await (await fetch(devtools + '/json/new?about:blank', { method: 'PUT' })).json(); +const ws = new WebSocket(target.webSocketDebuggerUrl); +await new Promise((r, j) => { ws.onopen = r; ws.onerror = j; }); +let id = 0; +const pending = new Map(); +ws.onmessage = (e) => { + const m = JSON.parse(e.data); + if (m.id && pending.has(m.id)) { pending.get(m.id).resolve(m); pending.delete(m.id); } +}; +// a closed socket or a silent browser fails the commands waiting for it (Qodo on #305) +ws.onclose = () => { + for (const p of pending.values()) p.reject(new Error('DevTools closed')); + pending.clear(); +}; +const send = (method, params = {}) => new Promise((resolve, reject) => { + const i = ++id; + const timer = setTimeout(() => { + pending.delete(i); reject(new Error(method + ': no answer in 30 s')); + }, 30000); + pending.set(i, { + resolve: (m) => { clearTimeout(timer); resolve(m); }, + reject: (e) => { clearTimeout(timer); reject(e); }, + }); + ws.send(JSON.stringify({ id: i, method, params })); +}); +await send('Network.enable'); +await send('Network.setExtraHTTPHeaders', { + headers: { Authorization: 'Basic ' + Buffer.from(credentials).toString('base64') }, +}); +const result = {}; +for (const width of [1280, 400]) { + await send('Emulation.setDeviceMetricsOverride', + { width, height: 900, deviceScaleFactor: 1, mobile: width < 600 }); + await send('Page.navigate', { url: page }); + await sleep(5000); + const ev = await send('Runtime.evaluate', { + expression: 'document.fonts.ready.then(() => JSON.stringify([...document.fonts]' + + '.map((f) => [f.family.replace(/["\']/g, ""), f.weight, f.status])))', + awaitPromise: true, returnByValue: true, + }); + const faces = JSON.parse(ev.result.result.value); + const loaded = (family) => faces.some((f) => f[0] === family && f[2] === 'loaded'); + const h1 = await send('Runtime.evaluate', { + expression: 'getComputedStyle(document.querySelector("h1")).fontFamily + " | "' + + ' + getComputedStyle(document.querySelector(".board")).fontFamily', + returnByValue: true, + }); + result[width] = { faces, serif: loaded('Brass Serif'), mono: loaded('Brass Mono'), + computed: h1.result.result.value }; + const m = await send('Page.getLayoutMetrics'); + const size = m.result.cssContentSize; + const shot = await send('Page.captureScreenshot', { + format: 'png', captureBeyondViewport: true, + clip: { x: 0, y: 0, width, height: Math.ceil(size.height), scale: 1 }, + }); + fs.writeFileSync(`${out}/page-${width}.png`, Buffer.from(shot.result.data, 'base64')); +} +console.log(JSON.stringify(result)); +ws.close(); +process.exit(result[1280].serif && result[1280].mono && result[400].serif && result[400].mono ? 0 : 1);