Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ 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.27.0 — 2026-11-19

- After an update of the app (a new APK installed over it) the web page comes back by itself,
and nothing else: no camera is played, no camex tunnel, the app's screen stays shut (#288).
Android tells the updated app (`MY_PACKAGE_REPLACED`); a small foreground service with a
quiet notification ("Web page on port N") keeps the page until the app is opened. Only with
Settings → Allow remote access on, and not after a force stop (Android then tells the app
nothing until it is opened).
- `tests/e2e.sh` checks it: the same APK installed again, the page answers, no camera is read,
no tunnel, no screen.

## 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
Expand Down
4 changes: 2 additions & 2 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ android {
applicationId "com.openipc.decoder"
minSdk 21
targetSdk 36
versionCode 62
versionName "2.26.0"
versionCode 63
versionName "2.27.0"
// Keep only these locales of the libraries' resources, as in the other OpenIPC apps
resourceConfigurations += ['en', 'ru', 'zh-rCN']

Expand Down
18 changes: 17 additions & 1 deletion android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<!-- Android 10+ lets an app start an activity from a boot receiver only with this (#255) -->
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<!-- After an update the web page alone, kept by a foreground service (#288) -->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="28" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"
Expand Down Expand Up @@ -63,12 +66,25 @@
<data android:mimeType="text/plain" />
</intent-filter>
</activity>
<!-- Start on boot (#255); BOOT_COMPLETED is a protected broadcast: only the system sends it -->
<!-- Start on boot (#255); BOOT_COMPLETED is a protected broadcast: only the system sends it.
MY_PACKAGE_REPLACED (#288): sent to this app only, after it was updated -->
<receiver android:name="BootReceiver" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
</intent-filter>
</receiver>
<!-- The web page alone after an update, until the app is opened (#288) -->
<service
android:name="WebService"
android:exported="false"
android:foregroundServiceType="specialUse">
<property
android:name="android.app.PROPERTY_SPECIAL_USE_FGS_SUBTYPE"
android:value="The app's own read-only web page on the local network, kept after an update until the app is opened" />
</service>
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ static Map<String, Object> state(Context context) {

@Override
public void onReceive(Context context, Intent intent) {
// after an update: the web page alone, nothing that plays or draws traffic (#288)
if (Intent.ACTION_MY_PACKAGE_REPLACED.equals(intent.getAction())) {
WebService.startAfterUpdate(context);
return;
}
if (!Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) return;
if (!enabled(context)) return;
// A firmware autorun opened it already: another start would pause and resume it,
Expand Down
2 changes: 2 additions & 0 deletions android/app/src/main/java/com/openipc/decoder/Decoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -2722,6 +2722,8 @@ protected void onResume() {
sOpening = false;
sShown = true;
hideSystemBars();
// the page after an update had its own service: the app's screen keeps it now (#288)
WebService.stop(this);
startStreams();
// the page moved (a taken port, Settings): its address on screen follows (Qodo on #285)
NetworkPanel.onWebPort = this::updateDebugUrls;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ static void webPortSettled(int port) {
if (r != null && App.context != null && isOn(App.context)) r.run();
Runnable shown = onWebPort;
if (shown != null) shown.run();
WebService.refresh(); // after an update: its notification tells the real port
});
Context c = App.context;
if (c == null || port == announcedPort || !CamexTunnel.running() || !isOn(c)) return;
Expand Down
140 changes: 140 additions & 0 deletions android/app/src/main/java/com/openipc/decoder/WebService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
/*
* Copyright (c) OpenIPC https://openipc.org Prosperity Public License 3.0.0
*
* WebService.java — the web page alone after an app update, until the app is opened (#288)
*
*/

package com.openipc.decoder;

import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ServiceInfo;
import android.os.Build;
import android.os.IBinder;
import android.util.Log;

/**
* An update stops the app and nothing of it runs until someone opens it. The owner's rule
* (2026-11-19): after an update bring back by itself only what draws no traffic and starts no
* video — the web page ({@link DebugServer}); no cameras, no camex tunnel, no activity. A
* process with only a receiver is cached and may be frozen or killed, so this foreground
* service with a quiet notification keeps it. It ends when the app's screen opens
* ({@link #stop}) or when Allow remote access is off.
*/
public final class WebService extends Service {
private static final String TAG = "OpenIPCDecoder";
private static final String CHANNEL = "web";
/** Not the camex tunnel's (its library uses its own id). */
private static final int NOTIFICATION_ID = 0x5745;

/** After {@code MY_PACKAGE_REPLACED}: the page back, when it is allowed and the app is shut. */
static void startAfterUpdate(Context c) {
if (!WebPort.allowed(c)) {
Log.i(TAG, "Updated: remote access is off, nothing is started");
return;
}
if (Decoder.openOrOpening()) return;
Intent i = new Intent(c, WebService.class);
try {
// exempt from the background limits on foreground services: the update broadcast
if (Build.VERSION.SDK_INT >= 26) c.startForegroundService(i);
else c.startService(i);
Log.i(TAG, "Updated: the web page is back, nothing else (no video, no tunnel)");
} catch (RuntimeException e) {
Log.w(TAG, "Updated: the web page could not be started: " + e.getMessage());
}
}

/** The running service, to show the page's real port in its notification. */
private static volatile WebService running;

/**
* The page settled its port (taken: the next free one): the notification tells that one,
* not the one set (Qodo on #289). Main thread.
*/
static void refresh() {
WebService s = running;
if (s == null) return;
NotificationManager nm = (NotificationManager) s.getSystemService(NOTIFICATION_SERVICE);
try {
nm.notify(NOTIFICATION_ID, s.notification());
} catch (RuntimeException e) {
// no permission to post: the service runs on without it
}
}

@Override
public void onDestroy() {
running = null;
super.onDestroy();
}

/** The app's screen is open: its own process keeps the page from now on. */
static void stop(Context c) {
try {
c.stopService(new Intent(c, WebService.class));
} catch (RuntimeException e) {
// not running
}
}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Notification n = notification();
if (Build.VERSION.SDK_INT >= 34) {
startForeground(NOTIFICATION_ID, n, ServiceInfo.FOREGROUND_SERVICE_TYPE_SPECIAL_USE);
} else {
startForeground(NOTIFICATION_ID, n);
}
if (!WebPort.allowed(this)) {
stopSelf();
return START_NOT_STICKY;
}
running = this;
DebugServer.get(); // binds its port on a thread of its own; refresh() follows it
// killed by the system: not brought back (the next update or the app's start will)
return START_NOT_STICKY;
}

private String text() {
DebugServer d = DebugServer.get();
if (!d.settled()) return "Web page starting (updated; open to play)";
int p = d.port();
return p > 0 && "listening".equals(d.state())
? "Web page on port " + p + " (updated; open to play)"
: "Web page: " + d.state();
}

@Override
public IBinder onBind(Intent intent) {
return null;
}

@SuppressWarnings("deprecation") // Notification.Builder(Context) before Android 8
private Notification notification() {
Notification.Builder b;
if (Build.VERSION.SDK_INT >= 26) {
NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
nm.createNotificationChannel(new NotificationChannel(CHANNEL, "Web page",
NotificationManager.IMPORTANCE_LOW));
b = new Notification.Builder(this, CHANNEL);
} else {
b = new Notification.Builder(this);
}
Intent open = new Intent(this, Decoder.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
b.setContentIntent(PendingIntent.getActivity(this, 0, open,
(Build.VERSION.SDK_INT >= 23 ? PendingIntent.FLAG_IMMUTABLE : 0)
| PendingIntent.FLAG_UPDATE_CURRENT));
return b.setSmallIcon(R.drawable.ic_launcher_foreground)
.setContentTitle("Decoder")
.setContentText(text())
.setOngoing(true)
.build();
}
}
1 change: 1 addition & 0 deletions docs/debug.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ While the app runs it serves its debug information over HTTP on port **8085**, f
- 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 :<password>`). The rule and what is hidden: [security.md](security.md#debug-server).
- `GET` only (`405` otherwise), one request per connection, `Cache-Control: no-store`.
- Two worker threads at background priority, a short queue, a 20 s deadline per request: the server never gets in the way of decoding; a busy server drops the connection.
- After an update of the app (a new APK over it) the page comes back by itself, kept by a foreground service until the app is opened (its quiet notification, "Web page on port N", shows where the app may post notifications; the page runs either way); nothing else starts — no camera, no camex tunnel. Not with Allow remote access off, and not after a force stop (`am force-stop`, Settings → Apps → Force stop): Android sends a force-stopped app no broadcast until it is opened again.
- If the port is taken (another app on the device serves its page there), the server takes the next free one, up to nine ports on (8086 … 8094), and logs which one and why; `addresses` in `/stats.json`, the Network dialog and the debug text show the real port. With none of them free it retries every 10 s, and `server` in `/stats.json` says why. The camex tunnel is told the port the page really got, and restarts when it changes.
- On a phone that is only on a camera's or toy's Wi‑Fi, open the pages on the phone itself: `http://127.0.0.1:8085/`.

Expand Down
2 changes: 1 addition & 1 deletion docs/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ cd android

The native code is built for arm64-v8a and armeabi-v7a by default; `-PdecoderAbis` takes a list of `arm64-v8a`, `armeabi-v7a`, `x86_64`, `x86` (an empty or unknown one fails the build).

`tests/e2e.sh [API]` plays a camera through a camex server and the tunnel on an x86_64 emulator in Docker (API 21 and 34 are checked): 17 checks (18 with `TRANSPORT=TCP`, the tunnel over TCP), from no camera with Network off to the password of the debug page through the tunnel and a restart of the tunnel with Network → Save and the web page's port taken by another program (adbd's `adb reverse tcp:8085`): the page moves to 8086, through the tunnel too, and 8085 through the tunnel is refused. The links of the emulator, the hub and the Linux edge get a netem delay of `DELAY_MS` each way (default 30 ms, 60 ms between the box and the hub; `tc` comes from the `decoder-netem` image of `tests/netem`, built on the first run), so the video rate check catches a TCP tunnel that crawls, as camex 4.0.0 did (#281). Its output is in `tests/out/` (ignored by git).
`tests/e2e.sh [API]` plays a camera through a camex server and the tunnel on an x86_64 emulator in Docker (API 21 and 34 are checked): 19 checks (20 with `TRANSPORT=TCP`, the tunnel over TCP), from no camera with Network off to the password of the debug page through the tunnel and a restart of the tunnel with Network → Save and the web page's port taken by another program (adbd's `adb reverse tcp:8085`): the page moves to 8086, through the tunnel too, and 8085 through the tunnel is refused; and an update (the same APK installed again): the page answers by itself, no camera is read, no tunnel, no screen. The links of the emulator, the hub and the Linux edge get a netem delay of `DELAY_MS` each way (default 30 ms, 60 ms between the box and the hub; `tc` comes from the `decoder-netem` image of `tests/netem`, built on the first run), so the video rate check catches a TCP tunnel that crawls, as camex 4.0.0 did (#281). Its output is in `tests/out/` (ignored by git).

A release build needs a keystore at `android/key.jks` and `KEYSTORE_PASS`, `KEY_ALIAS`, `KEY_PASS` in the environment (`./gradlew assembleRelease`). Debug and release builds are signed with different keys: to switch, uninstall first, which removes the saved camera URLs.

Expand Down
28 changes: 28 additions & 0 deletions tests/e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,34 @@ if [ -z "$SHOTS" ]; then
$ADB reverse --remove tcp:8085 >/dev/null 2>&1 || true
fi

# an update (the same APK again): the web page comes back by itself, nothing else — no camera
# is read, no tunnel, the app's screen stays shut (#288)
# (over the running app, as an update comes: a force-stopped app is in the "stopped" state and
# Android delivers it no broadcast, MY_PACKAGE_REPLACED included)
if [ -z "$SHOTS" ]; then
$ADB logcat -c 2>/dev/null || true
before=$(readers) # before the update: a camera started by it is counted (Qodo on #289)
$ADB install -r /w/decoder.apk >/dev/null
$ADB forward tcp:18085 tcp:8085 >/dev/null
up=""
for _ in $(seq 1 30); do
c=$(docker exec "$NAME" curl -s -o /dev/null -m 3 -w '%{http_code}' -u "x:$WEB_PASSWORD" \
http://127.0.0.1:18085/stats.json || true)
if [ "$c" = 200 ]; then up=1; break; fi
sleep 2
done
$ADB logcat -d > "$OUT/logcat-update.txt" 2>&1 || true
if [ -n "$up" ] && grep -q 'Updated: the web page is back' "$OUT/logcat-update.txt"; then
ok "after an update the web page is back by itself"
else bad "no web page after an update (tests/out/logcat-update.txt)"; fi
sleep 5
if [ "$(readers)" -le "$before" ] && ! $ADB shell 'ip addr show tun0 2>/dev/null' | grep -q 'inet ' &&
! $ADB shell dumpsys activity activities | grep -q "Resumed.*$PKG"; then
ok "after an update: no camera read, no tunnel, no screen"
else bad "after an update something more than the page started"; fi
$ADB forward --remove tcp:18085 >/dev/null 2>&1 || true
fi

$ADB logcat -d -b crash > "$OUT/crash.log" 2>&1 || true
if grep -q "$PKG" "$OUT/crash.log"; then bad "crash in logcat (tests/out/crash.log)"; else ok "no crash"; fi

Expand Down
Loading