Updates shared between rooms (0.108.57)

From the roadmap (Paul, 6 November 2026): while Orbit is open it shares its version and its
installed copy on the home network (/room/version, /room/orbit.apk). As it opens, Orbit
looks for a newer one in another room and asks Install? or Not now. The download must be
this app, newer, and signed by the same keys; this room's schedules are copied aside first;
Android's own installer then asks to confirm. Nothing installs silently.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-11-06 13:48:46 +00:00
co-authored by Claude Opus 5.5
parent cb93da6644
commit d4cdd7221d
9 changed files with 298 additions and 8 deletions
@@ -0,0 +1,56 @@
package tv.orbit.classic
import android.content.pm.PackageInfo
import org.json.JSONObject
import org.junit.Assert.*
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TemporaryFolder
import java.net.InetAddress
/** Updates shared between rooms (Paul, 6 November 2026): only a newer Orbit, signed as this one is, and only when asked. */
class RoomUpdatesTest {
@get:Rule val folder = TemporaryFolder()
@Test fun onlyANewerVersionIsOfferedAndNotNowSticks() {
val answer = JSONObject().put("code", 220).put("name", "0.108.60-x")
assertEquals(220L, offerFrom("Living Room", "192.168.0.252", answer, 216, emptySet())!!.code)
assertNull(offerFrom("Living Room", "192.168.0.252", answer, 220, emptySet())) // the same version
assertNull(offerFrom("Living Room", "192.168.0.252", answer, 230, emptySet())) // older than this one
assertNull(offerFrom("Living Room", "192.168.0.252", answer, 216, setOf(220L))) // turned down this time
assertEquals("0.108.60", shortVersion("0.108.60-x"))
}
@Suppress("DEPRECATION")
private fun info(name: String, code: Int) = PackageInfo().apply { packageName = name; versionCode = code }
@Test fun theDownloadMustBeNewerOrbitSignedTheSameWay() {
val installed = info("tv.orbit.classic", 216)
fun signers(same: Boolean): (PackageInfo) -> Set<String> = { p -> if (p === installed || same) setOf("abc") else setOf("xyz") }
assertNull(acceptableUpdate(info("tv.orbit.classic", 217), installed, signers(true)))
assertNotNull(acceptableUpdate(info("tv.orbit.classic", 217), installed, signers(false))) // another key: refused
assertNotNull(acceptableUpdate(info("tv.orbit.classic", 216), installed, signers(true))) // not newer
assertNotNull(acceptableUpdate(info("com.example.other", 300), installed, signers(true))) // another app
assertNotNull(acceptableUpdate(null, installed, signers(true)))
}
@Test fun theOtherRoomServesItsVersionAndCopyOnlyWhileShared() {
PhoneLink.initForTest(object : PhoneStore {
override fun all() = emptyMap<String, String>(); override fun get(id: String): String? = null
override fun put(id: String, value: String) {}; override fun remove(id: String) {} })
PhoneLink.bindTo = InetAddress.getLoopbackAddress(); PhoneLink.port = 18_099; PhoneLink.allowed = { it.isLoopbackAddress }
val apk = folder.newFile("orbit.apk").apply { writeBytes(ByteArray(300_000) { (it % 251).toByte() }) }
fun get(path: String): Pair<Int, ByteArray> {
val c = java.net.URL("http://127.0.0.1:18099$path").openConnection() as java.net.HttpURLConnection
val s = c.responseCode; return s to ((if (s < 400) c.inputStream else c.errorStream)?.use { it.readBytes() } ?: ByteArray(0))
}
try {
PhoneLink.shared = SharedBuild(220, "0.108.60-x", apk); PhoneLink.listening = true
val (status, body) = get("/room/version")
assertEquals(200, status); assertEquals(220L, JSONObject(String(body)).getLong("code"))
assertArrayEquals(apk.readBytes(), get("/room/orbit.apk").second)
PhoneLink.shared = null
assertEquals(404, get("/room/version").first); assertEquals(404, get("/room/orbit.apk").first)
} finally { PhoneLink.listening = false; PhoneLink.stop(); PhoneLink.allowed = EmbyServer::isHomeAddress; PhoneLink.bindTo = null; PhoneLink.port = PhoneLink.PORT }
}
}