0.126.0 (versionCode 323): no server built into the app
pauljd/davidson-ci: Davidson CI / quality (push) Failing after 3m12s
release-gate / verify (push) Successful in 8m58s
pauljd/davidson-ci: Davidson CI / ai-review (push) Failing after 2m41s

The address field starts empty on a new box, and its first server becomes
its original. A box from before reads its original server once from its own
saved sign-in and notes it beside its data; nothing else is moved or changed.
Paul's own decisions by item are kept to his server by a SHA-256 of its
address. The release gate refuses an APK that contains a server address.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-10 01:11:08 +00:00
co-authored by Claude Opus 5.5
parent 3bb5142817
commit 9f815a2bb7
16 changed files with 158 additions and 50 deletions
@@ -99,7 +99,7 @@ internal data class ChannelProgramming(val number: Int, val name: String, val se
/** Marathon (Create your own): this many episodes of a show back to back before the next takes over; 0 for none. */
val marathon: Int = 0) {
/** The items taken off this channel on the server signed in to: [withdrawnOnOriginal] there, none anywhere else. */
val withdrawn: Set<String> get() = if (Workspaces.originalOpen) withdrawnOnOriginal else emptySet()
val withdrawn: Set<String> get() = if (Workspaces.paulsServerOpen) withdrawnOnOriginal else emptySet()
/** A show's weight here, by its tier (a show the brief doesn't name counts as supporting), scaled by [catalogueScaleHours]. */
fun weightOf(show: PoolSeries): Double {
val tier = tierWeights?.get(seriesKey(show.title)) ?: TIER_SUPPORTING
@@ -15,9 +15,8 @@ import java.net.URI
* and every connection checks again that the name still leads to a private address. Never a public one.
*/
internal object EmbyServer {
/** Paul's server: what a box signed in before addresses could be typed was always using. */
const val DEFAULT = "https://bk2.appboxmanager.xyz"
@Volatile var origin: String = DEFAULT
/** The server in use: empty until one is signed in to. No server is built in (launch blocker, 10 November 2026). */
@Volatile var origin: String = ""
val host: String get() = URI(origin).host
val port: Int get() = URI(origin).port
@@ -27,7 +27,7 @@ internal class PremiereCall(val itemId: String, val title: String, val premiere:
val decidedOn: LocalDate = LocalDate.of(2026, 11, 5))
/** Paul's calls, by item on the original server: on any other server there are none, and its own Chair decides afresh. */
internal val PremiereCalls: List<PremiereCall> get() = if (Workspaces.originalOpen) PaulsPremiereCalls else emptyList()
internal val PremiereCalls: List<PremiereCall> get() = if (Workspaces.paulsServerOpen) PaulsPremiereCalls else emptyList()
private val PaulsPremiereCalls = listOf(
PremiereCall("7789551", "Avatar: Fire and Ash", true, 303, true, "approved by Paul on 5 November 2026: Premiere debut, then Orbit Sci-Fi"),
@@ -74,6 +74,13 @@ internal class RememberedConnectionStore(path: File, private val alias: String,
runCatching { android.util.Log.i("OrbitStartup", "saved sign-in keyMs=$keyMs openMs=$openMs decodeMs=${System.currentTimeMillis() - started - keyMs - openMs}") }
}
}
/** The server a saved sign-in belongs to, whichever it is, or null if there's none or it can't be read. Reads only. */
@Synchronized fun savedOrigin(): String? = runCatching {
if (!file.baseFile.exists() && !File(file.baseFile.path + ".bak").exists()) return null
file.openRead().use { input ->
RememberedStateCodec.decode(ConnectionCipher.open(key(false), input.readBytesLimited(RememberedStateCodec.MAX_BYTES + 29))).origin
}
}.getOrNull()
/** Opens the saved sign-in in the background as Orbit starts, so it's ready by the time the screen asks for it. */
fun warm() { Thread({ runCatching { load() } }, "orbit-warm-signin").apply { isDaemon = true }.start() }
@Synchronized fun save(state: RememberedState, ticket: Long): Boolean {
@@ -17,10 +17,14 @@ import java.security.MessageDigest
* The data a box already has belongs to the original server (the only one Orbit could use before an address could be typed
* in), and it stays exactly where it always was: nothing is moved, copied or rewritten, so an older Orbit still finds all of
* it. Any other server's data lives under servers/<key>, where an older Orbit never looks.
*
* No server is built in (launch blocker, 10 November 2026): the original server is the one named in a small note,
* original-server, beside its data. A box from before the note learns it once from its own saved sign-in; a new box's first
* server signed in to becomes its original. Until then nothing is open and the sign-in's address field is empty.
*/
internal class ServerWorkspace(val origin: String, val root: File, val artworkDir: File, val keyAlias: String) {
/** The server this box used before addresses could be typed in: its data is the box's existing data, where it was. */
val original get() = origin == EmbyServer.DEFAULT
internal class ServerWorkspace(val origin: String, val root: File, val artworkDir: File, val keyAlias: String,
/** The box's first server, whose data sits at the top of no_backup where it always was (see [Workspaces.originalOrigin]). */
val original: Boolean) {
val connectionFile get() = File(root, "orbit-connection.v1")
val catalogueFile get() = File(root, "catalogue.db")
val scheduleDir get() = File(root, "schedule")
@@ -38,30 +42,65 @@ internal object Workspaces {
private const val ORIGINAL_ALIAS = "orbit-connection-key-v1"
private const val ACTIVE_FILE = "active-server"
private const val ORIGIN_FILE = "server"
private const val ORIGINAL_FILE = "original-server"
/**
* Paul's own server, as a SHA-256 of its address, so the address itself isn't in the app: his decisions by item apply
* there and nowhere else, and a box from before the note whose sign-in can't be read gives its data to that server only.
*/
private const val PAULS_SERVER_SHA256 = "8a2a645acebc3401b07585a214d4b7dd0f24e254b8377e4b59128931c2376e80"
internal var isPaulsServer: (String) -> Boolean = { origin ->
MessageDigest.getInstance("SHA-256").digest(origin.toByteArray(Charsets.UTF_8)).joinToString("") { "%02x".format(it) } == PAULS_SERVER_SHA256
}
var current by mutableStateOf<ServerWorkspace?>(null)
private set
/** Whether the original server is the one open (or none is yet, as in tests): Paul's own decisions by item apply only there. */
val originalOpen: Boolean get() = current?.original ?: true
/** Whether Paul's server is the one open (or none is yet, as in tests): his own decisions by item apply only there. */
val paulsServerOpen: Boolean get() = current?.origin?.let { isPaulsServer(it) } ?: true
/** A short, stable folder name for [origin]. */
fun keyOf(origin: String): String = MessageDigest.getInstance("SHA-256").digest(origin.toByteArray(Charsets.UTF_8))
.take(8).joinToString("") { "%02x".format(it) }
private fun readOrigin(file: File): String? = runCatching { file.takeIf { it.isFile && it.length() <= 300 }?.readText()?.trim() }.getOrNull()
?.takeIf { EmbyServer.normalise(it) == it }
/** The box's original server, from its note; null on a new box, or a box from before the note until it learns it. */
fun originalOrigin(noBackup: File): String? = readOrigin(File(noBackup, ORIGINAL_FILE))
private fun rootLayout(noBackup: File, cacheDir: File, origin: String) = ServerWorkspace(origin, noBackup, File(cacheDir, "artwork"), ORIGINAL_ALIAS, original = true)
/**
* Whether [origin] would be the original server: the one in the note, or, with no note yet, the first server on a box with
* no data of its own, or Paul's server on a box from before the note (the only server an older Orbit could use).
*/
private fun isOriginal(noBackup: File, cacheDir: File, origin: String): Boolean = originalOrigin(noBackup)?.let { it == origin }
?: (!hasData(rootLayout(noBackup, cacheDir, origin)) || isPaulsServer(origin))
/** Where [origin]'s data lives under [noBackup] and [cacheDir]. Nothing is created here. */
fun layout(noBackup: File, cacheDir: File, origin: String): ServerWorkspace =
if (origin == EmbyServer.DEFAULT) ServerWorkspace(origin, noBackup, File(cacheDir, "artwork"), ORIGINAL_ALIAS)
else keyOf(origin).let { key -> ServerWorkspace(origin, File(noBackup, "servers/$key"), File(cacheDir, "artwork-$key"), "$ORIGINAL_ALIAS-$key") }
if (isOriginal(noBackup, cacheDir, origin)) rootLayout(noBackup, cacheDir, origin)
else keyOf(origin).let { key -> ServerWorkspace(origin, File(noBackup, "servers/$key"), File(cacheDir, "artwork-$key"), "$ORIGINAL_ALIAS-$key", original = false) }
/** The server whose workspace was open last: the original server until another has been signed in to. */
fun activeOrigin(noBackup: File): String {
val saved = runCatching { File(noBackup, ACTIVE_FILE).takeIf { it.isFile && it.length() <= 300 }?.readText()?.trim() }.getOrNull() ?: return EmbyServer.DEFAULT
return saved.takeIf { EmbyServer.normalise(it) == it } ?: EmbyServer.DEFAULT
/**
* The server whose workspace was open last, or the original server, or null when there's none yet. A box from before the
* note has its original server's address only in its saved sign-in: [savedOrigin] reads it from there.
*/
fun activeOrigin(noBackup: File, savedOrigin: () -> String? = { null }): String? =
readOrigin(File(noBackup, ACTIVE_FILE)) ?: originalOrigin(noBackup)
?: if (File(noBackup, "orbit-connection.v1").exists()) savedOrigin()?.takeIf { EmbyServer.normalise(it) == it } else null
/** The open workspace, opening the last one used if none is yet; with no server yet, the box's own empty place for one. */
@Synchronized fun current(context: Context): ServerWorkspace {
current?.let { return it }
val app = context.applicationContext
val origin = activeOrigin(app.noBackupFilesDir) {
// Once, on a box from before the note: the address its own sign-in was saved with.
RememberedConnectionStore(File(app.noBackupFilesDir, "orbit-connection.v1"), ORIGINAL_ALIAS, "").savedOrigin()
}
if (origin != null) return open(app, origin)
return rootLayout(app.noBackupFilesDir, app.cacheDir, "").also { it.appContext = app; current = it }
}
/** The open workspace, opening the last one used if none is yet. */
@Synchronized fun current(context: Context): ServerWorkspace = current ?: open(context, activeOrigin(context.noBackupFilesDir))
@Synchronized fun open(context: Context, origin: String): ServerWorkspace {
val app = context.applicationContext
return openIn(app.noBackupFilesDir, app.cacheDir, origin) { it.appContext = app }
@@ -76,7 +115,8 @@ internal object Workspaces {
require(EmbyServer.normalise(origin) == origin)
if (current?.origin == origin) return current!!
val next = layout(noBackup, cacheDir, origin).also(prepare)
if (!next.original) {
if (next.original) { if (originalOrigin(noBackup) == null) replace(File(noBackup, ORIGINAL_FILE), origin) }
else {
val note = File(next.root, ORIGIN_FILE)
if (note.exists()) check(note.readText().trim() == origin) { "A server folder belongs to another address." }
else { next.root.mkdirs(); replace(note, origin) }
@@ -93,7 +133,8 @@ internal object Workspaces {
}
/** For tests: no workspace open. */
@Synchronized internal fun reset() { current?.close(); current = null; EmbyServer.origin = EmbyServer.DEFAULT }
@Synchronized internal fun reset() { current?.close(); current = null; EmbyServer.origin = ""; isPaulsServer = defaultPaulsCheck }
private val defaultPaulsCheck = isPaulsServer
/** A small file written whole or not at all. */
private fun replace(target: File, text: String) {
@@ -108,9 +149,10 @@ internal object Workspaces {
/** Every server with data on this box, the original first if it has any. Read only. */
fun known(noBackup: File, cacheDir: File): List<String> {
val original = originalOrigin(noBackup)
val others = File(noBackup, "servers").listFiles().orEmpty().mapNotNull { dir -> File(dir, ORIGIN_FILE).takeIf { it.isFile }?.readText()?.trim() }
.filter { EmbyServer.normalise(it) == it && it != EmbyServer.DEFAULT }.sorted()
return (listOf(EmbyServer.DEFAULT) + others).filter { hasData(layout(noBackup, cacheDir, it)) }
.filter { EmbyServer.normalise(it) == it && it != original }.sorted()
return (listOfNotNull(original) + others).filter { hasData(layout(noBackup, cacheDir, it)) }
}
fun known(context: Context) = known(context.noBackupFilesDir, context.cacheDir)