From 5c8a33ffb1a43312207d112ac40226c8a58e03bc Mon Sep 17 00:00:00 2001 From: Pauljd Date: Mon, 9 Nov 2026 14:31:50 +0000 Subject: [PATCH] Playtest build: a separate app with an adb-only file player for AVI and frame-rate tests tv.orbit.classic.playtest has its own data and Orbit's own screens switched off, so it can't reach the household's schedules, Taste or Continue watching. It plays only the ten approved clips (checked by SHA-256) through Orbit's own player set-up, container rule and frame-rate matcher, with each switch set per run. Each run covers seeking, reopening (recovery), one retry on error, and the no-decoder case. verify.sh now fails if the hook ever reaches the release APK. Co-Authored-By: Claude Opus 5.5 --- android/app/build.gradle.kts | 9 ++ android/app/src/playtest/AndroidManifest.xml | 8 ++ .../src/playtest/assets/playtest-approved.txt | 10 ++ .../tv/orbit/classic/PlaytestFileActivity.kt | 126 ++++++++++++++++++ tools/playtest-run.sh | 24 ++++ tools/verify.sh | 3 + 6 files changed, 180 insertions(+) create mode 100644 android/app/src/playtest/AndroidManifest.xml create mode 100644 android/app/src/playtest/assets/playtest-approved.txt create mode 100644 android/app/src/playtest/java/tv/orbit/classic/PlaytestFileActivity.kt create mode 100755 tools/playtest-run.sh diff --git a/android/app/build.gradle.kts b/android/app/build.gradle.kts index 285fc279..a7bc7edb 100644 --- a/android/app/build.gradle.kts +++ b/android/app/build.gradle.kts @@ -20,6 +20,15 @@ android { isMinifyEnabled = false signingConfig = signingConfigs.getByName("debug") } + // The playback test build (Paul, 9 November 2026): a separate app, tv.orbit.classic.playtest, with its own data, so it + // can never touch the household's schedules, Taste or Continue watching. Its adb-only test player lives in + // src/playtest and is in no other build; Orbit's own screens are switched off in it. Never shipped. + create("playtest") { + initWith(getByName("release")) + applicationIdSuffix = ".playtest" + versionNameSuffix = "-playtest" + matchingFallbacks += "release" + } } // Android logging and the like do nothing in unit tests, so whole flows (a channel read from a fake server) can run. testOptions { unitTests.isReturnDefaultValues = true } diff --git a/android/app/src/playtest/AndroidManifest.xml b/android/app/src/playtest/AndroidManifest.xml new file mode 100644 index 00000000..0a4e0ff1 --- /dev/null +++ b/android/app/src/playtest/AndroidManifest.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/android/app/src/playtest/assets/playtest-approved.txt b/android/app/src/playtest/assets/playtest-approved.txt new file mode 100644 index 00000000..52aef6e0 --- /dev/null +++ b/android/app/src/playtest/assets/playtest-approved.txt @@ -0,0 +1,10 @@ +fps-23.976.mkv 6f400250fe694ea945becc0e8d261e92b546ea2b5108274e60e90e91618e54c6 +fps-24.mkv fe72138c24891306f9c2e36c8e3120c28898d712b66291df67907244f8250ee0 +fps-25.mkv 3c71aea66ae1973e41ebcb28da576b0721ae39d2fb1006073d4acdcb75530743 +fps-29.97.mkv 1399228d4936a0903b01c6aef3d07b492e1e4d9609a237c1236e081b5c224c08 +fps-50.mkv 01f7ddbef89fe9c3c7e80f03b1519b328515f35daa64fc4040c6710e2c66c040 +fps-59.94.mkv 0b4f4096878dfe54469dd6e62cf9728ec841730dc763bd3f6d10facdc73e9231 +avi-divx3-mp3.avi 70f740f9d1838a019869196caf364589a7ba5471cf47747c0b27bfa9d9778c28 +avi-divx5-ac3.avi a77b8b1d40521c749570d0d4cf5d7cdcf0211fbd14cd70865bf1a1679fed6ec9 +avi-h264-mp3.avi 3f65252975befa6abf7a5cbf141b1b28da94f13f9f9b020ab551c61cd91e3e0a +avi-xvid-mp3.avi 061a638181659908c4fcdc8599dfe2184abd8533b0ca32637dca68656e544e0f diff --git a/android/app/src/playtest/java/tv/orbit/classic/PlaytestFileActivity.kt b/android/app/src/playtest/java/tv/orbit/classic/PlaytestFileActivity.kt new file mode 100644 index 00000000..6ecc79cd --- /dev/null +++ b/android/app/src/playtest/java/tv/orbit/classic/PlaytestFileActivity.kt @@ -0,0 +1,126 @@ +package tv.orbit.classic + +import android.app.Activity +import android.net.Uri +import android.os.Bundle +import android.os.Handler +import android.os.Looper +import android.os.SystemClock +import android.view.WindowManager +import androidx.media3.common.C +import androidx.media3.common.MediaItem +import androidx.media3.common.PlaybackException +import androidx.media3.common.Player +import androidx.media3.common.Tracks +import androidx.media3.datasource.DefaultDataSource +import androidx.media3.exoplayer.ExoPlayer +import androidx.media3.exoplayer.source.DefaultMediaSourceFactory +import androidx.media3.ui.PlayerView +import org.json.JSONObject +import java.io.File +import java.security.MessageDigest + +/** + * The playback test for AVI and frame-rate matching (Paul, 9 November 2026). It's in the playtest build only (a separate app + * with its own data), opened from adb only, and plays only the approved test clips (assets/playtest-approved.txt, checked by + * SHA-256) from its own folder, through Orbit's own player set-up, container rule and frame-rate matcher: + * adb push fps-25.mkv /sdcard/Android/data/tv.orbit.classic.playtest/files/playtest/ + * adb shell am start -W -n tv.orbit.classic.playtest/tv.orbit.classic.PlaytestFileActivity --es file fps-25.mkv --es frame_rate on --es avi off + * The switches apply to this one test run only, in memory. Each run follows the same script: + * - play from the start; + * - at 8 s, seek to 40 s (as tuning in mid-programme does); + * - at 16 s, stop and reopen at the same point (recovery); + * - at 26 s, end and put the display mode back. + * If a playback error happens, it's retried once. Results go to files/playtest/results/.json and to logcat (tag + * OrbitPlaytest): the container decision, formats, decoder support, frame rate, display mode before and after, first-frame + * time, stalls, errors and recovery. + */ +@androidx.annotation.OptIn(androidx.media3.common.util.UnstableApi::class) +class PlaytestFileActivity : Activity() { + private val main = Handler(Looper.getMainLooper()) + private val result = JSONObject() + private var player: ExoPlayer? = null + private var startedAt = 0L + private var ready = false + private var stalls = 0 + private var retried = false + private var reopenedAt = 0L + private var finished = false + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) + val name = intent.getStringExtra("file").orEmpty() + PlayerSwitches.avi = intent.getStringExtra("avi") == "on" + PlayerSwitches.frameRate = intent.getStringExtra("frame_rate") == "on" + result.put("file", name).put("avi", PlayerSwitches.avi).put("frameRate", PlayerSwitches.frameRate) + val approved = assets.open("playtest-approved.txt").bufferedReader().readLines().mapNotNull { l -> l.split(' ').takeIf { it.size == 2 }?.let { it[0] to it[1] } }.toMap() + val file = File(getExternalFilesDir("playtest"), name) + val refusal = when { + name !in approved -> "not an approved test file" + !file.isFile -> "not found in the playtest folder" + sha256(file) != approved[name] -> "checksum doesn't match the approved file" + supportedDirectContainer(name.substringAfterLast('.')) == null -> "container not played directly (as Orbit: unplayable, left out of plans)" + else -> null + } + if (refusal != null) { result.put("outcome", "refused").put("reason", refusal); end(); return } + val view = PlayerView(this).apply { useController = false } + setContentView(view) + result.put("modeBefore", modeNow()) + val p = ExoPlayer.Builder(this, programmeRenderers(this)).setLoadControl(programmeLoadControl()) + .setMediaSourceFactory(DefaultMediaSourceFactory(DefaultDataSource.Factory(this), OrbitExtractorsFactory())).build() + player = p; view.player = p + p.addListener(object : Player.Listener { + override fun onTracksChanged(tracks: Tracks) { + val video = tracks.groups.firstOrNull { it.type == C.TRACK_TYPE_VIDEO } + val audio = tracks.groups.firstOrNull { it.type == C.TRACK_TYPE_AUDIO } + video?.getTrackFormat(0)?.let { f -> result.put("video", JSONObject().put("mime", f.sampleMimeType).put("codecs", f.codecs).put("width", f.width) + .put("height", f.height).put("fps", f.frameRate.toDouble()).put("decoder", video.isSupported)) } + audio?.getTrackFormat(0)?.let { f -> result.put("audio", JSONObject().put("mime", f.sampleMimeType).put("decoder", audio.isSupported)) } + if (video != null && !video.isSupported) { result.put("outcome", "no video decoder (as Orbit: unplayable, moves on)"); end(); return } + if (PlayerSwitches.frameRate) video?.getTrackFormat(0)?.frameRate?.let { FrameRateMatch.apply(window, it) } + main.postDelayed({ result.put("modeDuring", modeNow()) }, 4_000) + } + override fun onRenderedFirstFrame() { + if (!result.has("firstFrameMs")) result.put("firstFrameMs", SystemClock.elapsedRealtime() - startedAt) + if (reopenedAt > 0 && !result.has("recoveredMs")) result.put("recoveredMs", SystemClock.elapsedRealtime() - reopenedAt) + } + override fun onPlaybackStateChanged(state: Int) { + if (state == Player.STATE_BUFFERING && ready) stalls++ + if (state == Player.STATE_READY) ready = true + } + override fun onPlayerError(error: PlaybackException) { + result.accumulate("errors", error.errorCodeName) + if (!retried) { retried = true; ready = false; p.prepare(); p.play() } + else { result.put("outcome", "failed after one retry"); end() } + } + }) + startedAt = SystemClock.elapsedRealtime() + p.setMediaItem(MediaItem.fromUri(Uri.fromFile(file))); p.prepare(); p.play() + main.postDelayed({ p.seekTo(40_000) }, 8_000) + main.postDelayed({ val at = p.currentPosition; ready = false; p.stop(); reopenedAt = SystemClock.elapsedRealtime(); p.seekTo(at); p.prepare(); p.play() }, 16_000) + main.postDelayed({ if (!result.has("outcome")) result.put("outcome", if (result.has("recoveredMs")) "played" else "played, but didn't recover after reopening"); end() }, 26_000) + } + + private fun modeNow(): String = window.decorView.display?.mode?.let { "${it.physicalWidth}x${it.physicalHeight}@${"%.3f".format(it.refreshRate)}" } ?: "unknown" + + private fun end() { + if (finished) return + finished = true + main.removeCallbacksAndMessages(null) + result.put("stalls", stalls).put("retried", retried) + player?.let { result.put("positionMs", it.currentPosition); it.release() } + FrameRateMatch.reset(window) + main.postDelayed({ + result.put("modeAfter", modeNow()) + val out = File(getExternalFilesDir("playtest"), "results").apply { mkdirs() } + File(out, "${result.optString("file").ifBlank { "unnamed" }.replace('/', '_')}.json").writeText(result.toString(2)) + android.util.Log.i("OrbitPlaytest", result.toString()) + finish() + }, 3_000) + } + + override fun onStop() { super.onStop(); if (!finished) { result.put("outcome", "left early"); end() } } + + private fun sha256(f: File) = MessageDigest.getInstance("SHA-256").digest(f.readBytes()).joinToString("") { "%02x".format(it) } +} diff --git a/tools/playtest-run.sh b/tools/playtest-run.sh new file mode 100755 index 00000000..9a8a560a --- /dev/null +++ b/tools/playtest-run.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash +# The AVI and frame-rate test matrix (9 November 2026), on one TV, with the separate playtest app (tv.orbit.classic.playtest). +# Orbit itself is never opened, changed or stopped; its schedules, Taste and Continue watching live in another app. +# tools/playtest-run.sh (needs the playtest app installed: apks/orbit-playtest-0.123.0.apk) +# Each of the 10 approved clips runs with its switch off and then on (20 runs, about 35 s each). Results are pulled to +# audits/playtest-/ with one summary line per run. +set -uo pipefail +A=${ADB:-/opt/android-sdk/platform-tools/adb}; D=$1; MEDIA=${PLAYTEST_MEDIA:-/home/pauljd/Documents/OrbitTV/player-test-media} +OUT=/home/pauljd/Documents/OrbitTV/audits/playtest-$(date +%Y%m%d-%H%M); mkdir -p "$OUT" +DIR=/sdcard/Android/data/tv.orbit.classic.playtest/files/playtest +$A -s $D shell pm path tv.orbit.classic.playtest >/dev/null || { echo "The playtest app isn't installed on $D."; exit 1; } +$A -s $D shell am start -W -n tv.orbit.classic.playtest/tv.orbit.classic.PlaytestFileActivity --es file none >/dev/null; sleep 5 # makes its folder +for f in "$MEDIA"/fps-*.mkv "$MEDIA"/avi-*.avi; do $A -s $D push "$f" "$DIR/" >/dev/null; done +for f in "$MEDIA"/fps-*.mkv "$MEDIA"/avi-*.avi; do + n=$(basename "$f"); sw=$([[ $n == avi-* ]] && echo avi || echo frame_rate) + for state in off on; do + $A -s $D shell am start -W -n tv.orbit.classic.playtest/tv.orbit.classic.PlaytestFileActivity --es file "$n" --es $sw $state >/dev/null + sleep 33 + $A -s $D pull "$DIR/results/$n.json" "$OUT/${n%.*}-$sw-$state.json" >/dev/null 2>&1 + python3 -c "import json,sys; r=json.load(open(sys.argv[1])); v=r.get('video',{}); print(f\"{sys.argv[2]:<28} {r.get('outcome')}; fps {v.get('fps')}; decoder {v.get('decoder')}; mode {r.get('modeBefore')} > {r.get('modeDuring')} > {r.get('modeAfter')}; first frame {r.get('firstFrameMs')} ms; recovered {r.get('recoveredMs')} ms; stalls {r.get('stalls')}; errors {r.get('errors')}\")" "$OUT/${n%.*}-$sw-$state.json" "$n $sw=$state" 2>/dev/null | tee -a "$OUT/summary.txt" || echo "$n $sw=$state: no result" | tee -a "$OUT/summary.txt" + done +done +$A -s $D shell rm -r "$DIR" >/dev/null +echo "Results: $OUT" diff --git a/tools/verify.sh b/tools/verify.sh index 23b74a4e..fb9a2443 100755 --- a/tools/verify.sh +++ b/tools/verify.sh @@ -23,5 +23,8 @@ lint = len(re.findall(r'severity="(Error|Fatal)"', open('app/build/reports/lint- print(f"tests {tests}, failures {fails}, lint errors {lint}, contract suite {'present' if contract else 'MISSING'}") sys.exit(0 if fails == 0 and lint == 0 and contract and tests > 0 else 1) PY +# The playback test hook is only ever in the playtest build (Paul, 9 November 2026): never in the release APK. +if unzip -l app/build/outputs/apk/release/app-release.apk | grep -q playtest-approved || \ + unzip -p app/build/outputs/apk/release/app-release.apk 'classes*.dex' | grep -aq PlaytestFileActivity; then echo "Release APK contains the playback test hook."; exit 1; fi sha256sum app/build/outputs/apk/release/app-release.apk | cut -c1-64 echo "Release gate passed."