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 <noreply@anthropic.com>
This commit is contained in:
2026-11-09 14:31:50 +00:00
co-authored by Claude Opus 5.5
parent 9bcbe768d6
commit 5c8a33ffb1
6 changed files with 180 additions and 0 deletions
+9
View File
@@ -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 }
@@ -0,0 +1,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools">
<application android:label="Orbit playtest" tools:replace="android:label">
<!-- Orbit's own screens are off in the playtest build: it has no channels, no Companion and no Rooms, only the file test. -->
<activity android:name=".MainActivity" android:enabled="false" tools:replace="android:enabled" />
<!-- adb only, no launcher entry. How to run it: see PlaytestFileActivity.kt. -->
<activity android:name=".PlaytestFileActivity" android:exported="true" android:screenOrientation="landscape" />
</application>
</manifest>
@@ -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
@@ -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/<file>.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) }
}