diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d7c1e50..26138898 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,31 @@ 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.26.0 — 2026-11-18 + +- Decoder takes the "brass" look of our apps (#286, brass 1.3.0 of the brand project); the app + icon and the TV banner stay blue and white: + - the menu over the video is a brass panel of brass keys with serif labels; an item that is + on is pressed brass with an amber glow (was an orange fill), the remote's focus an amber + frame (was light blue), a slot without a camera has dim text; the version stays on Exit; + - the status line over the video is amber monospace capitals on a dark plate; + - the dialogs (camera, Start on boot, Reset) are brass panels with a serif title, dark text + fields, amber radio buttons and check boxes with the amber focus ring, brass buttons; + - **Network** opens one **Settings** dialog: a **Decoder** section with **Allow remote + access** (new; off, the debug page is closed and the app opens no port), the page's port + and password, and a **Camex** section with **Join a camex server** (was "On: connect now + and at every start"), the tunnel's state and the library's fields; + - the camex fields come from the camex 4.2.0 library (was 4.1.2): its labels (**Proto** + for the transport), the hints of empty fields, the key hidden with **Show the key** under + it, the client name `decoder-` by default; + - the web page: the title **Decoder** with the version, "Elegant video player", a panel with + rivets and the plate **Video wall**, a board of rows with lamps (Decoder, Cameras, Screen, + Camex), brass JSON, Log, Report and switches, the wall in a frame, the camera on screen in + amber; the tab's title and icon show the worst lamp. `/stats.json` has `camex`. +- The web page's port (Qodo on #285): a Save while the socket was opening is no longer lost; a + new port is tried at once after all ports failed; the address on screen follows a move; a + tunnel start waits for the new port after a Save; Network saved off cancels a waiting start. + ## 2.25.0 — 2026-11-18 - The web (debug) page's port is set in **Network** → **Web page port** (default 8085, as diff --git a/README.md b/README.md index 741ac642..3b00cfef 100644 --- a/README.md +++ b/README.md @@ -89,7 +89,7 @@ Every item, the remote, sharing a URL from another app and **Reset**: [Usage](do ## Network (a tunnel to the cameras) -Decoder has a tunnel built in, [OpenIPC camex](https://github.com/OpenIPC/camex) 4.1.2: cameras that are clients of the same camex server are watched from anywhere, without a separate VPN app. **Network** in the menu (a row under the grid) holds the server (`host:port`), the client name (the box's ID on the server), UDP or TCP, the server's public key, the pre-shared key, the server timeout, the port and the password of the debug page and **On**: connect now and at every start. Off by default. The server gives the address, MTU and routes; only the tunnel network and the server's routes (none wider than a /8) go through it, the local network is reached as before. The state is shown in the dialog (Connecting, Connected with the address, VPN consent needed, Failed) and in a notification. A camera reached through the tunnel plays over TCP with Auto. The debug page is on port 8085 unless Network sets another; when that port is taken (another app on the device serves its page there), Decoder takes the next free one (8086, 8087, …) and shows the real address. Decoder tells the server the port its page really is on (for nginx there; a camex server 3.19.0 or later), and the tunnel lets in only that port of Decoder's own page: another app's page is not reached through it. The password, when set, guards that page from the local network and through the tunnel alike; empty (the default), the page is open. +Decoder has a tunnel built in, [OpenIPC camex](https://github.com/OpenIPC/camex) 4.2.0: cameras that are clients of the same camex server are watched from anywhere, without a separate VPN app. **Network** in the menu (a row under the grid) opens the **Settings** dialog. Its **Decoder** section holds **Allow remote access** (the debug page; off, the app opens no port at all), the page's port and its password. Its **Camex** section holds **Join a camex server** (connect now and at every start; off by default) and the tunnel's state, then the server (`host:port`), the client name (the box's ID on the server; by default `decoder-` and the last four characters of the device's Android ID), **Proto** (UDP or TCP), the server's public key, the pre-shared key (hidden, with **Show the key** under it), MTU, keepalive and the server timeout, as the camex library lists them. The server gives the address, MTU and routes; only the tunnel network and the server's routes (none wider than a /8) go through it, the local network is reached as before. The state is shown in the dialog (Connecting, Connected with the address, VPN consent needed, Failed) and in a notification. A camera reached through the tunnel plays over TCP with Auto. The debug page is on port 8085 unless Network sets another; when that port is taken (another app on the device serves its page there), Decoder takes the next free one (8086, 8087, …) and shows the real address. Decoder tells the server the port its page really is on (for nginx there; a camex server 3.19.0 or later), and the tunnel lets in only that port of Decoder's own page: another app's page is not reached through it. The password, when set, guards that page from the local network and through the tunnel alike; empty (the default), the page is open.

The Network dialog on a TV box: connected, the server and the client name diff --git a/README.ru.md b/README.ru.md index d3e2df5a..ebd95290 100644 --- a/README.ru.md +++ b/README.ru.md @@ -89,7 +89,7 @@ ## Network (туннель к камерам) -В Decoder встроен туннель [OpenIPC camex](https://github.com/OpenIPC/camex) 4.1.2: камеры, подключённые клиентами к тому же серверу camex, видны откуда угодно, без отдельного VPN-приложения. Пункт **Network** в меню (ряд под сеткой): сервер (`host:port`), имя клиента (идентификатор приставки на сервере), UDP или TCP, открытый ключ сервера, общий ключ (psk), таймаут сервера, порт и пароль отладочной страницы и **On** — подключиться сейчас и при каждом запуске. По умолчанию выключено. Адрес, MTU и маршруты выдаёт сервер; через туннель идут только его сеть и маршруты сервера (не шире /8), локальная сеть доступна как прежде. Состояние видно в окне (Connecting, Connected с адресом, VPN consent needed, Failed) и в уведомлении. Камера за туннелем в режиме Auto идёт по TCP. Отладочная страница — на порту 8085, если в Network не задан другой; если порт занят (на устройстве его держит страница другого приложения), Decoder берёт следующий свободный (8086, 8087, …) и показывает настоящий адрес. Серверу Decoder сообщает порт, на котором страница на самом деле (для nginx на сервере; нужен сервер camex 3.19.0 или новее), а туннель пропускает только этот порт собственной страницы Decoder: страница другого приложения через него недоступна. Пароль, если задан, закрывает эту страницу одинаково из локальной сети и через туннель; пустой (по умолчанию) — страница открыта. +В Decoder встроен туннель [OpenIPC camex](https://github.com/OpenIPC/camex) 4.2.0: камеры, подключённые клиентами к тому же серверу camex, видны откуда угодно, без отдельного VPN-приложения. Пункт **Network** в меню (ряд под сеткой) открывает окно **Settings**. Раздел **Decoder**: **Allow remote access** (отладочная страница; выключено — у приложения нет ни одного сетевого порта), порт и пароль страницы. Раздел **Camex**: **Join a camex server** (подключиться сейчас и при каждом запуске; по умолчанию выключено) и состояние туннеля, затем сервер (`host:port`), имя клиента (идентификатор приставки на сервере; по умолчанию `decoder-` и четыре последних знака Android ID устройства), **Proto** (UDP или TCP), открытый ключ сервера, общий ключ (psk; скрыт, под ним **Show the key**), MTU, keepalive и таймаут сервера — как их перечисляет библиотека camex. Адрес, MTU и маршруты выдаёт сервер; через туннель идут только его сеть и маршруты сервера (не шире /8), локальная сеть доступна как прежде. Состояние видно в окне (Connecting, Connected с адресом, VPN consent needed, Failed) и в уведомлении. Камера за туннелем в режиме Auto идёт по TCP. Отладочная страница — на порту 8085, если в Network не задан другой; если порт занят (на устройстве его держит страница другого приложения), Decoder берёт следующий свободный (8086, 8087, …) и показывает настоящий адрес. Серверу Decoder сообщает порт, на котором страница на самом деле (для nginx на сервере; нужен сервер camex 3.19.0 или новее), а туннель пропускает только этот порт собственной страницы Decoder: страница другого приложения через него недоступна. Пароль, если задан, закрывает эту страницу одинаково из локальной сети и через туннель; пустой (по умолчанию) — страница открыта.

Окно Network на ТВ-приставке: подключено, сервер и имя клиента diff --git a/README.zh-CN.md b/README.zh-CN.md index f5b00147..5ee4f5be 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -89,7 +89,7 @@ ## Network(通往摄像头的隧道) -Decoder 内置 [OpenIPC camex](https://github.com/OpenIPC/camex) 4.1.2 隧道:作为客户端接入同一台 camex 服务器的摄像头,可以在任何地方观看,无需另装 VPN 应用。菜单中的 **Network**(网格下方一行)包含:服务器(`host:port`)、客户端名称(设备在服务器上的 ID)、UDP 或 TCP、服务器公钥、预共享密钥、服务器超时、调试页面端口和密码,以及 **On**:立即连接并在每次启动时连接。默认关闭。地址、MTU 和路由由服务器下发;只有隧道网络和服务器的路由(不宽于 /8)经过隧道,本地网络照常访问。状态显示在对话框(Connecting、Connected 及地址、VPN consent needed、Failed)和通知中。经隧道访问的摄像头在 Auto 模式下走 TCP。调试页面默认位于 8085 端口,可在 Network 中更改;若该端口被占用(设备上另一个应用的页面在用),Decoder 会使用下一个空闲端口(8086、8087……)并显示实际地址。Decoder 告知服务器页面实际所在的端口(供服务器上的 nginx 使用;需 camex 服务器 3.19.0 或更新版本),隧道只放行 Decoder 自身页面的这个端口:无法经隧道访问其他应用的页面。设置密码后,无论从本地网络还是经隧道访问,该页面都需要密码;为空(默认)时页面开放。 +Decoder 内置 [OpenIPC camex](https://github.com/OpenIPC/camex) 4.2.0 隧道:作为客户端接入同一台 camex 服务器的摄像头,可以在任何地方观看,无需另装 VPN 应用。菜单中的 **Network**(网格下方一行)打开 **Settings** 对话框。**Decoder** 部分包含 **Allow remote access**(调试页面;关闭时应用不打开任何端口)、页面端口和密码。**Camex** 部分包含 **Join a camex server**(立即连接并在每次启动时连接;默认关闭)和隧道状态,然后是服务器(`host:port`)、客户端名称(设备在服务器上的 ID;默认为 `decoder-` 加设备 Android ID 的后四位)、**Proto**(UDP 或 TCP)、服务器公钥、预共享密钥(隐藏,下方有 **Show the key**)、MTU、keepalive 和服务器超时,均按 camex 库列出。地址、MTU 和路由由服务器下发;只有隧道网络和服务器的路由(不宽于 /8)经过隧道,本地网络照常访问。状态显示在对话框(Connecting、Connected 及地址、VPN consent needed、Failed)和通知中。经隧道访问的摄像头在 Auto 模式下走 TCP。调试页面默认位于 8085 端口,可在 Network 中更改;若该端口被占用(设备上另一个应用的页面在用),Decoder 会使用下一个空闲端口(8086、8087……)并显示实际地址。Decoder 告知服务器页面实际所在的端口(供服务器上的 nginx 使用;需 camex 服务器 3.19.0 或更新版本),隧道只放行 Decoder 自身页面的这个端口:无法经隧道访问其他应用的页面。设置密码后,无论从本地网络还是经隧道访问,该页面都需要密码;为空(默认)时页面开放。

电视盒子上的 Network 对话框:已连接、服务器和客户端名称 diff --git a/android/app/build.gradle b/android/app/build.gradle index d9c1e301..965545a3 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 61 - versionName "2.25.0" + versionCode 62 + versionName "2.26.0" // 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/java/com/openipc/decoder/Brass.java b/android/app/src/main/java/com/openipc/decoder/Brass.java new file mode 100644 index 00000000..0b3297aa --- /dev/null +++ b/android/app/src/main/java/com/openipc/decoder/Brass.java @@ -0,0 +1,234 @@ +/* + * Copyright (c) OpenIPC https://openipc.org Prosperity Public License 3.0.0 + * + * Brass.java — the "brass" look of the menu and the dialogs (#286, brand brass 1.3.0) + * + */ + +package com.openipc.decoder; + +import android.app.AlertDialog; +import android.content.Context; +import android.content.res.ColorStateList; +import android.graphics.Typeface; +import android.graphics.drawable.Drawable; +import android.graphics.drawable.GradientDrawable; +import android.graphics.drawable.StateListDrawable; +import android.util.TypedValue; +import android.view.Gravity; +import android.view.View; +import android.view.ViewGroup; +import android.view.Window; +import android.widget.Button; +import android.widget.CompoundButton; +import android.widget.EditText; +import android.widget.LinearLayout; +import android.widget.TextView; + +/** + * The palette is res/values/colors.xml (the brand's master copy); the shapes follow brass.css: + * a panel of {@code panel2} → {@code panel} with a {@code brass2} frame, brass keys (an engaged + * one "pressed" with an amber glow, the remote's focus an amber frame), dark displays for text + * fields, section bands of a brass plate. The video window keeps its own black theme: only the + * menu over it, the status line and the dialogs are brass. + */ +final class Brass { + /** Dark ink on brass (keys, plates): {@code ink_dark}. */ + static final int INK_DARK = 0xFF2A1C10; + /** A key that leads nowhere (an unconfigured camera, a word that does not apply now). */ + static final int INK_OFF = 0xFF6E5A3C; + /** The latency of the active camera on a brass key: dark tones of green, amber and red. */ + static final int INK_OK = 0xFF1E6B3A; + static final int INK_WARN = 0xFF8A4B00; + static final int INK_BAD = 0xFF9A2A14; + /** The display behind text fields and the status line, as {@code .state} of brass.css. */ + static final int DISPLAY = 0xFF120D0A; + private static final int DISPLAY_EDGE = 0xFF574123; + private static final int KEY_EDGE = 0xFF4A3510; + private static final int PLATE_EDGE = 0xFF5B4416; + + private Brass() { + } + + /** A colour of colors.xml (Context.getColor is API 23; the app starts at 21). */ + @SuppressWarnings("deprecation") + static int color(Context c, int id) { + return c.getResources().getColor(id); + } + + private static float dp(Context c) { + return c.getResources().getDisplayMetrics().density; + } + + /** The panel: {@code panel2} → {@code panel}, a 3dp {@code brass2} frame, radius 16dp. */ + static GradientDrawable panel(Context c) { + float d = dp(c); + GradientDrawable g = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, + new int[]{color(c, R.color.panel2), color(c, R.color.panel)}); + g.setCornerRadius(16 * d); + g.setStroke(Math.round(3 * d), color(c, R.color.brass2)); + return g; + } + + /** A brass key: plain or engaged ("pressed", an amber glow), with the amber focus frame. */ + static GradientDrawable key(Context c, boolean engaged, boolean focused) { + float d = dp(c); + GradientDrawable g = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, engaged + ? new int[]{0xFFF6DC95, 0xFFC99D45, 0xFF8A6621} + : new int[]{0xFFE9CD84, 0xFFB08B3C, 0xFF7C5C1F}); + g.setCornerRadius(10 * d); + if (focused) g.setStroke(Math.round(3 * d), color(c, R.color.amber)); + else if (engaged) g.setStroke(Math.round(2 * d), 0xFFFFC266); // the glow's rim + else g.setStroke(Math.max(1, Math.round(d)), KEY_EDGE); + return g; + } + + /** A dialog button: a brass key that shows the remote's focus by itself. */ + private static Drawable keyStates(Context c) { + StateListDrawable s = new StateListDrawable(); + s.addState(new int[]{android.R.attr.state_focused}, key(c, false, true)); + s.addState(new int[]{android.R.attr.state_pressed}, key(c, true, false)); + s.addState(new int[]{}, key(c, false, false)); + return s; + } + + /** The dark display of a text field: the focused one with an amber frame. */ + private static Drawable displayStates(Context c) { + StateListDrawable s = new StateListDrawable(); + s.addState(new int[]{android.R.attr.state_focused}, display(c, color(c, R.color.amber))); + s.addState(new int[]{}, display(c, DISPLAY_EDGE)); + return s; + } + + private static GradientDrawable display(Context c, int edge) { + float d = dp(c); + GradientDrawable g = new GradientDrawable(); + g.setColor(DISPLAY); + g.setCornerRadius(6 * d); + g.setStroke(Math.round(2 * d), edge); + return g; + } + + /** The plate of a section band: a brass gradient, dark serif capitals. */ + static TextView band(Context c, String text, boolean gapAbove) { + float d = dp(c); + TextView t = new TextView(c); + t.setText(text); + t.setAllCaps(true); + t.setTypeface(Typeface.SERIF, Typeface.BOLD); + t.setLetterSpacing(0.25f); + t.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15); + t.setTextColor(INK_DARK); + GradientDrawable g = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, + new int[]{0xFFE2C377, 0xFFA88237}); + g.setCornerRadius(4 * d); + g.setStroke(Math.max(1, Math.round(d)), PLATE_EDGE); + t.setBackground(g); + t.setGravity(Gravity.CENTER); + int p = Math.round(8 * d); + t.setPadding(p, p, p, p); + LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams( + ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); + lp.setMargins(0, Math.round((gapAbove ? 22 : 6) * d), 0, Math.round(8 * d)); + t.setLayoutParams(lp); + t.setTag(BAND); + return t; + } + + private static final String BAND = "brass-band"; + + /** A builder whose dialog has the brass theme (amber accents, the focus ring). */ + static AlertDialog.Builder dialog(Context c) { + return new AlertDialog.Builder(c, R.style.BrassDialog); + } + + /** + * The brass panel of a dialog, before {@code show()}: a window changed once it shows loses + * the keyboard it opened with (a phone editing the camera's URL at once). + */ + static void frame(AlertDialog dialog) { + Window w = dialog.getWindow(); + if (w != null) w.setBackgroundDrawable(panel(dialog.getContext())); + } + + /** + * The brass look of a dialog that is showing (its panel set by {@link #frame} before): the + * serif title in brass, brass keys for its buttons, dark displays for its fields. Call right + * after {@code show()}; it changes the views only, not the window. + */ + static void style(AlertDialog dialog) { + Window w = dialog.getWindow(); + if (w == null) return; + Context c = dialog.getContext(); + styleTree(c, w.getDecorView()); + for (int which : new int[]{AlertDialog.BUTTON_POSITIVE, AlertDialog.BUTTON_NEGATIVE, + AlertDialog.BUTTON_NEUTRAL}) { + Button b = dialog.getButton(which); + if (b != null) key(c, b); + } + } + + /** A dialog button as a brass key: serif capitals in dark ink, a little apart. */ + private static void key(Context c, Button b) { + b.setBackground(keyStates(c)); + b.setTextColor(INK_DARK); + b.setTypeface(Typeface.SERIF); + b.setLetterSpacing(0.15f); + b.setAllCaps(true); + ViewGroup.LayoutParams lp = b.getLayoutParams(); + if (lp instanceof ViewGroup.MarginLayoutParams) { + int m = Math.round(4 * dp(c)); + ((ViewGroup.MarginLayoutParams) lp).setMargins(m, m, m, m); + b.setLayoutParams(lp); + } + } + + private static void styleTree(Context c, View v) { + if (v instanceof EditText) { + EditText e = (EditText) v; + e.setTextColor(color(c, R.color.ink)); + e.setHintTextColor(0x99B09873); + e.setTypeface(Typeface.MONOSPACE); + int l = e.getPaddingLeft(), t = e.getPaddingTop(); + e.setBackground(displayStates(c)); + int p = Math.round(10 * dp(c)); + e.setPadding(Math.max(l, p), Math.max(t, p), p, p); + } else if (v instanceof CompoundButton) { + CompoundButton b = (CompoundButton) v; + b.setTextColor(color(c, R.color.ink)); + b.setButtonTintList(ColorStateList.valueOf(color(c, R.color.amber))); + // the remote's focus (focus_ring.xml): views made with the activity's context miss + // the dialog theme's checkboxStyle + b.setBackgroundResource(R.drawable.focus_ring); + } else if (v instanceof Button) { + // the dialog's own buttons: style(AlertDialog) + } else if (v instanceof TextView && BAND.equals(v.getTag())) { + // a section band keeps its plate + } else if (v instanceof TextView) { + TextView t = (TextView) v; + if (t.getId() == android.R.id.title || isAlertTitle(t)) { + t.setTextColor(color(c, R.color.brass)); + t.setTypeface(Typeface.SERIF); + t.setAllCaps(true); + t.setLetterSpacing(0.2f); + } else if (t.getId() == android.R.id.message) { + t.setTextColor(color(c, R.color.ink)); + } else if (!Boolean.TRUE.equals(t.getTag(R.id.brass_keep))) { + t.setTextColor(color(c, R.color.dim)); + } + } + if (v instanceof ViewGroup) { + ViewGroup g = (ViewGroup) v; + for (int i = 0; i < g.getChildCount(); i++) styleTree(c, g.getChildAt(i)); + } + } + + private static boolean isAlertTitle(View v) { + if (v.getId() == View.NO_ID) return false; + try { + return "alertTitle".equals(v.getResources().getResourceEntryName(v.getId())); + } catch (RuntimeException e) { + return false; + } + } +} 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 5cf2bc3b..9b3ffc40 100644 --- a/android/app/src/main/java/com/openipc/decoder/DebugServer.java +++ b/android/app/src/main/java/com/openipc/decoder/DebugServer.java @@ -33,7 +33,7 @@ * Serves what the decoder knows about itself on the port of {@link WebPort} (8085 unless Network * sets another; the next free one when it is taken, #284), for a browser or curl: * {@code /} a page refreshing itself, {@code /stats.json} the same as JSON, {@code /log} the - * app's recent log, {@code /report.txt} both in one file to download (#207). Always on; a client outside the local network gets 403. With a password set in + * app's recent log, {@code /report.txt} both in one file to download (#207). On unless Settings → Allow remote access is off (#286); a client outside the local network gets 403. With a password set in * Network, every request needs it (HTTP Basic, any user name), from the local network and the * tunnel alike; without one the pages are open, as before. GET only, one * request per connection, short timeouts and a few workers: it must never get in the way of @@ -79,6 +79,7 @@ interface Source { private volatile String state = "starting"; /** The port the server listens on, 0 while it has none. */ private volatile int port; + private static final String OFF = "off (Allow remote access)"; /** True once the first port was tried: the tunnel waits for it, so it starts with that port. */ private volatile boolean settled; /** The open socket, closed by {@link #rebind()} to take the port set in Network now. */ @@ -139,22 +140,54 @@ void clearSource(Source s) { String state() { return state; } - /** The port the page is on: the one listened on, else the one asked for. */ + /** The port the page is on: the one listened on, else the one asked for; 0 when off. */ int port() { + if (!WebPort.allowed(App.context)) return 0; int p = port; return p != 0 ? p : WebPort.get(App.context); } + /** Woken by {@link #rebind()}: a change in Settings is taken at once, not after a delay. */ + private final Object wake = new Object(); + private boolean woken; + + private boolean sleep(long ms) { + synchronized (wake) { + if (!woken) { + try { + wake.wait(ms); + } catch (InterruptedException e) { + return false; + } + } + woken = false; + } + return true; + } + /** Whether the server has tried its port since the start (it listens, or none was free). */ boolean settled() { return settled; } - /** Takes the port now set in Network: the open socket is closed and the next one opened. */ + /** Bumped by {@link #rebind()}: a socket opened for an older setting is closed again. */ + private volatile int generation; + + /** + * Takes the port now set in Network (or Allow remote access): the open socket is closed and + * the next one opened; a wait between tries ends at once. Until the server has tried the new + * port it is not {@link #settled()}, so a tunnel start waits for the real port (Qodo on #285). + */ void rebind() { + settled = false; + port = 0; // until the new one is open, port() is the one now set + synchronized (wake) { + generation++; + woken = true; + wake.notifyAll(); + } ServerSocket s = server; if (s == null) return; - port = 0; // until the new one is open, port() is the one now set try { s.close(); } catch (IOException ignored) { @@ -190,6 +223,19 @@ private static ServerSocket open(int wanted, String[] why) { private void acceptLoop() { while (true) { + final int gen = generation; + if (!WebPort.allowed(App.context)) { + // Settings → Allow remote access off: no port at all, until it is on again; each + // wake (a Save) settles again, so a tunnel start waiting for it goes on (Qodo on + // #287) + port = 0; + if (!OFF.equals(state)) Log.i(TAG, "Debug HTTP server: off, remote access is not allowed"); + state = OFF; + settled = true; + NetworkPanel.webPortSettled(0); + if (!sleep(REBIND_DELAY_MS)) return; + continue; + } int wanted = WebPort.get(App.context); String[] why = new String[1]; ServerSocket opened = open(wanted, why); @@ -203,6 +249,11 @@ private void acceptLoop() { } else { try (ServerSocket s = opened) { server = s; + // a Save while the socket was opening: its close went nowhere, take it now + if (generation != gen) { + server = null; + continue; + } port = s.getLocalPort(); state = "listening"; if (port == wanted) { @@ -223,18 +274,14 @@ private void acceptLoop() { } } catch (IOException e) { server = null; - // closed by rebind(): the port set in Network now, at once - if (WebPort.get(App.context) != wanted) continue; + // closed by rebind(): the port set in Network now, or off, at once + if (generation != gen) continue; port = 0; state = "port closed: " + e.getMessage(); Log.w(TAG, "Debug HTTP server: " + state + ", retrying"); } } - try { - Thread.sleep(REBIND_DELAY_MS); - } catch (InterruptedException e) { - return; - } + if (!sleep(REBIND_DELAY_MS)) return; } } @@ -243,6 +290,8 @@ private void handle(Socket s) { ScheduledFuture deadline = deadlines.schedule(() -> closeQuietly(s), REQUEST_DEADLINE_MS, TimeUnit.MILLISECONDS); try (Socket socket = s) { + // accepted just before Allow remote access went off: not served (Qodo on #287) + if (!WebPort.allowed(App.context)) return; socket.setSoTimeout(SOCKET_TIMEOUT_MS); OutputStream out = socket.getOutputStream(); if (!NetInfo.isLocalClient(socket.getInetAddress())) { @@ -680,7 +729,8 @@ private static void closeQuietly(Socket s) { */ private static final String PAGE = "" + "OpenIPC Decoder" + + " content=\"width=device-width, initial-scale=1\">Decoder" + + "" + "" - + "

" - + "
OpenIPC Decoder" - + "
" - + "
" - + "" - + "
" + // brass 1.3.0 of the brand project (#286): the shared look of our apps' pages + + ":root{--panel:#2c2119;--panel2:#3d2d22;--brass:#c9a24d;--brass2:#8c6a2a;--amber:#ffb347;" + + "--ink:#e8d9b8;--dim:#b09873;--red:#c8452c;--green:#5ad38f;--foot:#a08a69}*{box-sizing:bo" + + "rder-box}body.brass{display:block;height:auto;min-height:100%;background:radial-gradient" + + "(ellipse at 50% 0,#3b2c22 0,#1a1512 55%,#0f0b09 100%);color:var(--ink);font-family:Georg" + + "ia,'Times New Roman',serif;padding:28px 12px;text-align:center}.brass h1{font-size:clamp" + + "(22px,4.5vw,40px);letter-spacing:.2em;text-transform:uppercase;margin:0 0 6px;color:var(" + + "--brass);text-shadow:0 1px 0 #f3d78a,0 -1px 0 #3d2a0c,0 0 22px rgba(201,162,77,.35);font" + + "-weight:400}.ttl{position:relative;display:inline-block}.ttl .ver{position:absolute;left" + + ":100%;bottom:.24em;margin-left:.6em;font:12px/1 'Courier New',monospace;letter-spacing:." + + "12em;color:var(--dim);text-shadow:none;white-space:nowrap}.brass .sub{font-family:'Couri" + + "er New',monospace;font-size:12px;color:var(--dim);letter-spacing:.3em;text-transform:upp" + + "ercase;margin-bottom:24px}.brass .panel{position:relative;width:min(1200px,100%);margin:" + + "0 auto;text-align:left;background:linear-gradient(180deg,var(--panel2),var(--panel));bor" + + "der:3px solid var(--brass2);border-radius:16px;box-shadow:inset 0 0 0 2px #1a1210,inset " + + "0 0 50px rgba(0,0,0,.6),0 24px 48px rgba(0,0,0,.65);padding:30px 24px 24px}.rivet{positi" + + "on:absolute;width:14px;height:14px;border-radius:50%;background:radial-gradient(circle a" + + "t 35% 35%,#f1d38b,#8c6a2a 60%,#3a2a10)}.rivet.tl{top:8px;left:8px}.rivet.tr{top:8px;righ" + + "t:8px}.rivet.bl{bottom:8px;left:8px}.rivet.br{bottom:8px;right:8px}.plate{font-family:'C" + + "ourier New',monospace;font-size:12px;letter-spacing:.2em;text-transform:uppercase;color:" + + "#2a1c10;background:linear-gradient(180deg,#e2c377,#a88237);border:1px solid #5b4416;bord" + + "er-radius:4px;padding:4px 10px;display:inline-block}.brass .top{position:static;display:" + + "flex;flex-wrap:wrap;gap:10px;align-items:center;justify-content:space-between;background" + + ":none;padding:0;font-size:inherit;text-shadow:none;color:inherit}.brass nav{display:flex" + + ";flex-wrap:wrap;align-items:center;gap:8px;margin:0;font-family:'Courier New',monospace;" + + "font-size:12px;color:var(--dim);letter-spacing:.12em;text-transform:uppercase}.bb,.brass" + + " .seg button{font:12px Georgia,serif;letter-spacing:.15em;text-transform:uppercase;color" + + ":#2a1c10;background:linear-gradient(180deg,#e9cd84,#b08b3c 55%,#7c5c1f);border:0;border-" + + "radius:8px;padding:6px 12px;box-shadow:0 3px 0 #4a3510;text-decoration:none;cursor:point" + + "er}.brass .seg{display:inline-flex;gap:4px;margin:0}.brass .seg button{border-radius:8px" + + ";margin:0}.brass .seg button.on{background:linear-gradient(180deg,#f6dc95,#c99d45 55%,#8" + + "a6621);box-shadow:0 1px 0 #4a3510,inset 0 0 10px rgba(255,180,60,.55);color:#2a1c10}.lab" + + "{margin-left:6px}.board{margin-top:18px;padding:10px 16px;border:2px solid #574123;borde" + + "r-radius:8px;background:#120d0a;box-shadow:inset 0 0 20px rgba(0,0,0,.8);font-family:'Co" + + "urier New',monospace;font-size:14px}.board .r{display:grid;grid-template-columns:22px 12" + + "0px minmax(0,1fr);align-items:center;padding:5px 0;gap:0 6px}.board .bulb{width:14px;hei" + + "ght:14px;border-radius:50%;border:1px solid #6e5320;background:#2a2118}.board .bulb.ok{b" + + "ackground:radial-gradient(circle at 40% 35%,#d8ffe8,var(--green) 45%,#155b34);box-shadow" + + ":0 0 10px var(--green)}.board .bulb.warn{background:radial-gradient(circle at 40% 35%,#f" + + "ff3c4,var(--amber) 45%,#a24d0a);box-shadow:0 0 10px var(--amber)}.board .bulb.bad{backgr" + + "ound:radial-gradient(circle at 40% 35%,#ffd0c4,var(--red) 45%,#5a1a0e)}.board .bulb.none" + + "{visibility:hidden}.board .k{color:var(--dim);letter-spacing:.15em;text-transform:upperc" + + "ase;font-size:12px}.board .v{color:var(--ink);letter-spacing:.06em;text-transform:upperc" + + "ase}.brass main{display:flex;flex-direction:column;align-items:center;padding:0;margin-t" + + "op:18px;overflow:visible}.brass #wall{border:2px solid #574123;border-radius:8px;overflo" + + "w:hidden;box-shadow:inset 0 0 20px rgba(0,0,0,.8)}.brass .cell{border-color:#574123}.bra" + + "ss .cell.on{border:2px solid var(--amber)}.brass .top.ct,.brass .cell .top{position:abso" + + "lute;display:block;font-family:'Courier New',monospace}.brass .cell .slot{color:var(--am" + + "ber)}.brass .ok{color:var(--green)}.brass .bad{color:var(--red)}.brass .warn{color:var(-" + + "-amber)}.brass .off b{color:#6e5a3c}.brass #list td{border-top-color:#574123;color:var(-" + + "-dim);font-family:'Courier New',monospace}.foot{margin-top:18px;font-family:'Courier New" + + "',monospace;font-size:11px;color:var(--foot);letter-spacing:.2em;text-transform:uppercas" + + "e;text-align:center}@media (max-width:620px){.ttl .ver{bottom:.1em}.sub .br{display:bloc" + + "k}.board{padding:8px 12px;font-size:12px}.board .r{grid-template-columns:20px 74px minma" + + "x(0,1fr)}.board .k{font-size:11px;letter-spacing:.1em}.brass .panel{padding:26px 14px 18" + + "px}}" + + ".board .bulb.dim{background:#2a2118}.brass nav .g{display:inline-flex;align-items:center;gap:6px}" + + "" + + "

Decoder

" + + "
Elegant video player
" + + "
" + + "" + + "
Video wall" + + "
" + // the board (#286): a row with a lamp for the app, the cameras, the screen, camex + + "
" + + "" + "
\"\"
" - + "
" + + "
" + + "
Decoder \u00b7 OpenIPC \u00b7 Prosperity Public License 3.0.0
" + "