Restore sends one zip, after a rehearsal on the TV found adb can't make folders there (0.108.109)

Rehearsal downstairs (8 November 2026): Android 14 lets adb put files only in a folder Orbit made, so 'prepare-restore'
makes install-restore/ and the PC sends restore.zip; the receiver unpacks only restore.txt and snapshot names (zip-slip
refused) and removes the pushed copy afterwards. The script restarts Orbit even if a step fails. Rehearsed end to end:
snapshot, restore of all 278 files, snapshot again: identical (the sign-in file is re-saved on every launch anyway).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-08 11:41:32 +00:00
co-authored by Claude Opus 5.5
parent 1b77e18adf
commit 6dec924a83
6 changed files with 58 additions and 16 deletions
@@ -62,9 +62,9 @@ internal class HttpsEmbyTransport(internal val deviceId: String = UUID.randomUUI
}
/** The sign-in headers for this kind of server. */
internal fun authHeaders(token: String?): Map<String, String> = when (kind) {
ServerKind.Emby -> mapOf("X-Emby-Authorization" to "Emby Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.108.108\"") +
ServerKind.Emby -> mapOf("X-Emby-Authorization" to "Emby Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.108.109\"") +
(token?.let { mapOf("X-Emby-Token" to it) } ?: emptyMap())
ServerKind.Jellyfin -> mapOf("Authorization" to "MediaBrowser Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.108.108\"" +
ServerKind.Jellyfin -> mapOf("Authorization" to "MediaBrowser Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.108.109\"" +
(token?.let { ", Token=\"$it\"" } ?: ""))
}
/** One picture from the provider, or nothing. Same fixed origin and no redirects, and failures are never shown or logged. */
@@ -24,10 +24,16 @@ import java.security.MessageDigest
class InstallSnapshotReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
val result = runCatching {
if (intent.getStringExtra("do") == "restore") {
if (intent.getStringExtra("do") == "prepare-restore") {
// adb can't make folders in Orbit's shared folder on Android 14, only put files in one Orbit made.
File(context.getExternalFilesDir(null), "install-restore").run { deleteRecursively(); mkdirs(); "ready" }
} else if (intent.getStringExtra("do") == "restore") {
if (InstallSnapshot.screenOpen) "refused: Orbit is open; force-stop it first"
else InstallRestore.apply(context.filesDir.parentFile!!, File(context.getExternalFilesDir(null), "install-restore"),
intent.getStringExtra("confirm"), System.currentTimeMillis())
else File(context.getExternalFilesDir(null), "install-restore").let { folder ->
// The pushed copy goes once it's been used, restored or refused.
try { InstallRestore.apply(context.filesDir.parentFile!!, folder, intent.getStringExtra("confirm"), System.currentTimeMillis()) }
finally { if (intent.getStringExtra("confirm") == "RESTORE") folder.deleteRecursively() }
}
} else InstallSnapshot.handle(context, intent.getStringExtra("do").orEmpty(), intent.getStringExtra("version"))
}
resultData = result.fold({ it }, { "failed" })
@@ -95,8 +101,24 @@ internal object InstallSnapshot {
internal object InstallRestore {
private val allowed = Regex("""no_backup/schedule/[A-Za-z0-9._-]+(/[A-Za-z0-9._-]+)?|shared_prefs/orbit_(settings|profiles)\.xml""")
fun apply(data: File, source: File, confirm: String?, nowMs: Long): String {
fun apply(data: File, folder: File, confirm: String?, nowMs: Long): String {
if (confirm != "RESTORE") return "refused: needs confirm RESTORE"
// The snapshot comes as one restore.zip (adb can only put files in a folder Orbit made): unpacked beside it, taking
// only restore.txt and the names a snapshot can hold, so nothing can be written anywhere else.
val zip = File(folder, "restore.zip")
val source = if (!zip.isFile) folder else File(folder, "unpacked").also { out ->
out.deleteRecursively(); out.mkdirs()
java.util.zip.ZipInputStream(zip.inputStream().buffered()).use { z ->
while (true) {
val e = z.nextEntry ?: break
if (e.isDirectory) continue
val name = e.name
if (name != "restore.txt" && (!allowed.matches(name) || name.split('/').any { it == ".." || it == "." || it.isEmpty() }))
return "refused: not allowed in zip: ${name.take(80)}"
File(out, name).apply { parentFile?.mkdirs() }.outputStream().use { z.copyTo(it) }
}
}
}
val manifest = File(source, "restore.txt").takeIf { it.isFile } ?: return "refused: no restore.txt"
val listed = manifest.readLines().filter { it.isNotBlank() }.map { line ->
val hash = line.substringBefore(' '); val path = line.substringAfter(' ').trimStart(' ', '*')
@@ -39,7 +39,7 @@ internal class SecureMediaDataSource(private val session: EmbySampleSession) : B
next.instanceFollowRedirects = false
next.connectTimeout = 10_000
next.readTimeout = 20_000
next.setRequestProperty("User-Agent", "OrbitTV/0.108.108")
next.setRequestProperty("User-Agent", "OrbitTV/0.108.109")
next.setRequestProperty("Accept-Encoding", "identity")
session.mediaHeaders(address).forEach { (key, value) -> next.setRequestProperty(key, value) }
if (dataSpec.position != 0L || dataSpec.length != C.LENGTH_UNSET.toLong()) {