diff --git a/android/app/build.gradle.kts b/android/app/build.gradle.kts index daf8dfe0..4c615781 100644 --- a/android/app/build.gradle.kts +++ b/android/app/build.gradle.kts @@ -9,8 +9,8 @@ android { applicationId = "tv.orbit.classic" minSdk = 26 targetSdk = 36 - versionCode = 262 - versionName = "0.108.102-rooms-sync" + versionCode = 263 + versionName = "0.108.103-sync-not-self" } buildFeatures { compose = true } // The finished build for the TVs (Paul, 6 November 2026: the test build stuttered on the box). Not debuggable, so diff --git a/android/app/src/main/java/tv/orbit/classic/EmbyClient.kt b/android/app/src/main/java/tv/orbit/classic/EmbyClient.kt index d38cd2d4..993747d2 100644 --- a/android/app/src/main/java/tv/orbit/classic/EmbyClient.kt +++ b/android/app/src/main/java/tv/orbit/classic/EmbyClient.kt @@ -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 = when (kind) { - ServerKind.Emby -> mapOf("X-Emby-Authorization" to "Emby Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.108.102\"") + + ServerKind.Emby -> mapOf("X-Emby-Authorization" to "Emby Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.108.103\"") + (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.102\"" + + ServerKind.Jellyfin -> mapOf("Authorization" to "MediaBrowser Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.108.103\"" + (token?.let { ", Token=\"$it\"" } ?: "")) } /** One picture from the provider, or nothing. Same fixed origin and no redirects, and failures are never shown or logged. */ diff --git a/android/app/src/main/java/tv/orbit/classic/RoomSync.kt b/android/app/src/main/java/tv/orbit/classic/RoomSync.kt index 2b5d9a67..0df9e791 100644 --- a/android/app/src/main/java/tv/orbit/classic/RoomSync.kt +++ b/android/app/src/main/java/tv/orbit/classic/RoomSync.kt @@ -108,6 +108,7 @@ internal object RoomSync { fun answer(context: Context, scheduleDir: File, body: String, from: String?, nowMs: Long = System.currentTimeMillis()): Pair { val req = runCatching { JSONObject(body) }.getOrNull() ?: return 400 to JSONObject() val link = RoomLinks.of(req.optString("link"))?.takeIf { it.on } ?: return 404 to JSONObject() + if (from != null && from in ownAddresses()) return 409 to JSONObject() val o = open(link, req.optString("sealed"), nowMs) ?: return 403 to JSONObject() merge(context, scheduleDir, o, nowMs) val reply = state(context, scheduleDir, o.optLong("since"), nowMs) @@ -116,10 +117,16 @@ internal object RoomSync { return 200 to JSONObject().put("sealed", RoomCrypto.seal(link.key, reply.toString().toByteArray())) } - /** One round from this TV: each paired room it can reach, at its last address or as found on the Wi-Fi. */ + /** This TV's own addresses: it finds itself on the Wi-Fi too, and must never sync with itself (seen 7 November 2026). */ + fun ownAddresses(): Set = runCatching { + java.net.NetworkInterface.getNetworkInterfaces().toList().flatMap { it.inetAddresses.toList() }.mapNotNull { it.hostAddress?.substringBefore('%') }.toSet() + }.getOrDefault(emptySet()) + + /** One round from this TV: each paired room it can reach, at its last address or as found on the Wi-Fi, never itself. */ fun round(context: Context, scheduleDir: File, found: List, nowMs: Long = System.currentTimeMillis()) { + val mine = ownAddresses() for (link in RoomLinks.links.filter { it.on }) { - for (address in (listOfNotNull(link.address) + found).distinct()) { + for (address in (listOfNotNull(link.address) + found).distinct().filter { it !in mine }) { val call = roomTransport(address) ?: continue val sent = state(context, scheduleDir, link.lastSyncMs, nowMs) val (status, text) = runCatching { call("POST", "/room/sync", JSONObject().put("link", link.id).put("sealed", RoomCrypto.seal(link.key, sent.toString().toByteArray())).toString()) } diff --git a/android/app/src/main/java/tv/orbit/classic/SecureMediaDataSource.kt b/android/app/src/main/java/tv/orbit/classic/SecureMediaDataSource.kt index ffd912be..4a5e7007 100644 --- a/android/app/src/main/java/tv/orbit/classic/SecureMediaDataSource.kt +++ b/android/app/src/main/java/tv/orbit/classic/SecureMediaDataSource.kt @@ -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.102") + next.setRequestProperty("User-Agent", "OrbitTV/0.108.103") 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()) {