diff --git a/android/app/build.gradle.kts b/android/app/build.gradle.kts index 85d393ed..a4046df3 100644 --- a/android/app/build.gradle.kts +++ b/android/app/build.gradle.kts @@ -3,7 +3,7 @@ plugins { id("org.jetbrains.kotlin.plugin.compose") } /** The release's build number: versionCode is this x 10 plus the edition's channel. */ -val ORBIT_BUILD = 44 +val ORBIT_BUILD = 45 android { namespace = "tv.orbit.classic" compileSdk = 36 @@ -11,7 +11,7 @@ android { applicationId = "tv.orbit.classic" minSdk = 26 targetSdk = 36 - versionName = "1.0.0-rc2" + versionName = "1.0.0-rc3" } // Two editions of the same app (Paul, 10 November 2026): the household build, which updates itself between rooms, and the // Play build, which only Google Play updates. Both are tv.orbit.classic, so a TV can move between them keeping its data. diff --git a/android/app/src/main/java/tv/orbit/classic/ChannelTuningBackdrop.kt b/android/app/src/main/java/tv/orbit/classic/ChannelTuningBackdrop.kt index 67985b43..86528e84 100644 --- a/android/app/src/main/java/tv/orbit/classic/ChannelTuningBackdrop.kt +++ b/android/app/src/main/java/tv/orbit/classic/ChannelTuningBackdrop.kt @@ -12,7 +12,7 @@ import androidx.tv.material3.Text /** Presentation only: no timers, media requests or schedule changes. */ @Composable -internal fun ChannelTuningBackdrop(number: Int, modifier: Modifier = Modifier, artwork: @Composable () -> Unit = {}) { +internal fun ChannelTuningBackdrop(number: Int, modifier: Modifier = Modifier, waiting: Boolean = false, artwork: @Composable () -> Unit = {}) { val branding = ChannelBrands.forNumber(number) Box(modifier.fillMaxSize().background(Navy)) { artwork() @@ -25,6 +25,7 @@ internal fun ChannelTuningBackdrop(number: Int, modifier: Modifier = Modifier, a ClassicTuningNumber(number, Modifier.align(Alignment.TopEnd).padding(top = 32.dp, end = 44.dp)) Column(Modifier.align(Alignment.BottomStart).padding(start = 40.dp, bottom = 36.dp).background(Navy.copy(alpha = .78f)).padding(horizontal = 12.dp, vertical = 6.dp), verticalArrangement = Arrangement.spacedBy(6.dp)) { Text("Tuning…", color = Muted, fontSize = 17.sp) + if (waiting) Text("Waiting for your server to answer…", color = Muted, fontSize = 14.sp) Text("Back for TV guide", color = Muted, fontSize = 13.sp) } } 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 ed5f7587..c3801caa 100644 --- a/android/app/src/main/java/tv/orbit/classic/EmbyClient.kt +++ b/android/app/src/main/java/tv/orbit/classic/EmbyClient.kt @@ -8,6 +8,8 @@ import java.util.UUID import java.net.HttpURLConnection internal open class EmbyCheckException(message: String, val httpStatus: Int? = null, val retryable: Boolean = false) : Exception(message) +/** The server took too long or couldn't be reached at all, as opposed to answering with a problem (1.0 RC3). */ +internal class ServerNotAnswering(message: String) : EmbyCheckException(message, retryable = true) internal data class SampleItem(val title: String, val type: String, val minutes: Long?, val format: String, val id: String = "", val durationMs: Long? = minutes?.takeIf { it in 1..(Long.MAX_VALUE / 60_000) }?.times(60_000)) internal data class EmbySample(val items: List, val total: Long?) internal class EmbyRequest(val method: String, val path: String, val body: String? = null, val token: String? = null, val readTimeoutMs: Int? = null) @@ -134,8 +136,8 @@ internal class HttpsEmbyTransport(internal val deviceId: String = UUID.randomUUI return EmbyReply(status, body) } catch (e: EmbyCheckException) { throw e } catch (_: javax.net.ssl.SSLException) { throw EmbyCheckException("The secure connection could not be verified. No insecure fallback was used.") } - catch (_: java.net.SocketTimeoutException) { throw EmbyCheckException("The provider took too long to answer.", retryable = true) } - catch (_: java.io.IOException) { throw EmbyCheckException("The provider could not be reached. Check your connection and try again.", retryable = true) } + catch (_: java.net.SocketTimeoutException) { throw ServerNotAnswering("The provider took too long to answer.") } + catch (_: java.io.IOException) { throw ServerNotAnswering("The provider could not be reached. Check your connection and try again.") } finally { connection.disconnect() } } } diff --git a/android/app/src/main/java/tv/orbit/classic/EmbyConnectionScreen.kt b/android/app/src/main/java/tv/orbit/classic/EmbyConnectionScreen.kt index 64707f8f..b991cd19 100644 --- a/android/app/src/main/java/tv/orbit/classic/EmbyConnectionScreen.kt +++ b/android/app/src/main/java/tv/orbit/classic/EmbyConnectionScreen.kt @@ -435,7 +435,9 @@ internal fun EmbyConnectionScreen(modifier: Modifier = Modifier, visible: Boolea // Refreshed each round, so it's there once the catalogue finishes its first full read (0.129 audit). withContext(Dispatchers.IO) { active.libraryTitles = runCatching { catalogue.libraryTitles(active.accountId) }.getOrNull() } val quiet = withContext(Dispatchers.IO) { workspace.quietStart() } - BackgroundPacing.budget = if (quiet) QUIET_START_BUDGET else BackgroundPacing.HOURLY_BUDGET + // Shared by every TV in the house on this server (1.0 RC3): the rooms this TV is linked to or set up. + BackgroundPacing.tvs = 1 + (RoomLinks.links.map { it.room } + Rooms.joined.map { it.first }).distinct().size + BackgroundPacing.budget = BackgroundPacing.share(if (quiet) QUIET_START_BUDGET else BackgroundPacing.HOURLY_BUDGET) for (programming in SmartChannels) { val loop = smartLoop(programming) ?: run { // A channel of your own that is switched on but whose first plan never finished (an update arrived mid-read, diff --git a/android/app/src/main/java/tv/orbit/classic/SampleChannelScreens.kt b/android/app/src/main/java/tv/orbit/classic/SampleChannelScreens.kt index 6522cb13..b480124a 100644 --- a/android/app/src/main/java/tv/orbit/classic/SampleChannelScreens.kt +++ b/android/app/src/main/java/tv/orbit/classic/SampleChannelScreens.kt @@ -124,6 +124,12 @@ internal fun ScheduledChannelPlayer(session: EmbySampleSession, channel: SampleC var preparedSlot by remember(channel) { mutableStateOf(handedNow?.startMs) } var problem by remember(channel) { mutableStateOf(null) } var retryAttempt by remember(channel) { mutableIntStateOf(0) } + // Waiting on a slow server (1.0 RC3): after a few seconds the tuning screen says so; when it doesn't answer at all, Orbit + // tries again every 30 seconds by itself. + var serverRetry by remember(channel) { mutableIntStateOf(0) } + LaunchedEffect(serverRetry) { if (serverRetry > 0) { delay(30_000); if (problem == SERVER_NOT_ANSWERING) { problem = null; retryAttempt++ } } } + var waitingOnServer by remember(channel, current.startMs) { mutableStateOf(false) } + LaunchedEffect(channel, current.startMs, retryAttempt) { waitingOnServer = false; delay(8_000); waitingOnServer = true } // Kids on a channel during a grown-up takeover: it's asleep, and nothing of it is opened. // A channel of your own outside its hours is off air, and nothing of it is opened either. val offAir = offAirUntil(channel.number, current.startMs) @@ -155,6 +161,9 @@ internal fun ScheduledChannelPlayer(session: EmbySampleSession, channel: SampleC } preparedSlot = current.startMs; prepared = plan } catch (cancelled: CancellationException) { throw cancelled } + // The server not answering at all (13 November 2026: Emby froze for six minutes during its scan) isn't this programme's + // fault: say so plainly, and try again by itself every 30 seconds rather than give the slot up. + catch (failure: ServerNotAnswering) { problem = SERVER_NOT_ANSWERING; serverRetry++ } catch (failure: EmbyCheckException) { problem = if (channel is ScheduledChannel) "This programme isn't available right now. Orbit moves on at ${clock(current.endMs)}." else failure.message } catch (_: Exception) { problem = if (channel is ScheduledChannel) "This programme isn't available right now. Orbit moves on at ${clock(current.endMs)}." else "This scheduled programme could not be opened. Return to the guide and try again." } } @@ -219,7 +228,7 @@ internal fun ScheduledChannelPlayer(session: EmbySampleSession, channel: SampleC }) } else { SideEffect { window.onBack = { if (introPlayback?.showing == true) introPlayback.skip() else onClose() } } - if (problem == null) ChannelTuningBackdrop(channel.number) { ProgrammeArtwork(session, channel, current) } + if (problem == null) ChannelTuningBackdrop(channel.number, waiting = waitingOnServer) { ProgrammeArtwork(session, channel, current) } else Box(Modifier.fillMaxSize().background(Navy)) { Column(Modifier.align(Alignment.Center).widthIn(max = 620.dp).padding(32.dp), verticalArrangement = Arrangement.spacedBy(12.dp)) { Text(problem.orEmpty(), color = Color.White, fontSize = 20.sp) @@ -271,6 +280,8 @@ internal fun ScheduledChannelPlayer(session: EmbySampleSession, channel: SampleC } } } +internal const val SERVER_NOT_ANSWERING = "Your server isn't answering right now. Orbit tries again every 30 seconds; nothing is wrong with this TV." + @Composable internal fun ClassicTuningNumber(number: Int, modifier: Modifier = Modifier) { Text(number.toString(), modifier = modifier, color = Color(0xFF47FF52), fontSize = 46.sp, diff --git a/android/app/src/main/java/tv/orbit/classic/ServerRequests.kt b/android/app/src/main/java/tv/orbit/classic/ServerRequests.kt index 5d5117b6..123e6447 100644 --- a/android/app/src/main/java/tv/orbit/classic/ServerRequests.kt +++ b/android/app/src/main/java/tv/orbit/classic/ServerRequests.kt @@ -133,7 +133,17 @@ internal object BackgroundPacing { * once the TV reaches this, background work stops until the hour has room again, and Settings says so. */ const val TOTAL_CEILING = 400 - /** When background work last stopped at [TOTAL_CEILING], for Settings; null if it hasn't since Orbit opened. */ + /** + * TVs in this household using the server (1.0 RC3, Paul: size the limits for the whole house, not one TV): this one plus + * the other rooms it knows. The background budget is shared between them, and each TV's ceiling comes down too, though + * never below [MIN_CEILING], so watching and a little background always fit. + */ + @Volatile var tvs = 1 + const val MIN_CEILING = 250 + val ceiling get() = maxOf(TOTAL_CEILING / tvs.coerceAtLeast(1), MIN_CEILING) + /** A household's share of a per-TV [base] budget for one TV. */ + fun share(base: Int, tvs: Int = this.tvs) = (base / tvs.coerceAtLeast(1)).coerceAtLeast(25) + /** When background work last stopped at the ceiling, for Settings; null if it hasn't since Orbit opened. */ @Volatile var ceilingHitMs: Long? = null /** * First-run and switch-on channel setup (0.129 audit): not on the hourly budget, since someone is waiting for it, but @@ -186,11 +196,11 @@ internal object BackgroundPacing { if (wait > 0) { sleep(wait); now = clock() } while (sent.isNotEmpty() && sent.first() <= now - 60 * 60_000L) sent.removeFirst() if (sent.size >= budget) throw PacedOut() - if (ServerRequests.inLastHour() >= TOTAL_CEILING) { ceilingHitMs = now; throw PacedOut() } + if (ServerRequests.inLastHour() >= ceiling) { ceilingHitMs = now; throw PacedOut() } lastMs = now; sent.addLast(now) } } - internal fun resetForTest() { lastMs = 0; lastSetupMs = 0; sent.clear(); ceilingHitMs = null; budget = HOURLY_BUDGET; gapMs = GAP_MS; clock = System::currentTimeMillis; sleep = { Thread.sleep(it) } } + internal fun resetForTest() { lastMs = 0; lastSetupMs = 0; sent.clear(); ceilingHitMs = null; budget = HOURLY_BUDGET; tvs = 1; gapMs = GAP_MS; clock = System::currentTimeMillis; sleep = { Thread.sleep(it) } } @Synchronized internal fun usedThisHour(): Int { val now = clock(); return sent.count { it > now - 60 * 60_000L } } } diff --git a/android/app/src/main/java/tv/orbit/classic/Settings.kt b/android/app/src/main/java/tv/orbit/classic/Settings.kt index 9195a338..6fda0266 100644 --- a/android/app/src/main/java/tv/orbit/classic/Settings.kt +++ b/android/app/src/main/java/tv/orbit/classic/Settings.kt @@ -457,6 +457,13 @@ private fun AccountDetail(server: String, titles: Long?, onSignOut: () -> Unit, Column(modifier.footScroll(), verticalArrangement = Arrangement.spacedBy(8.dp)) { Heading("Your server") SettingLine("Connected", server + (titles?.let { ", $it titles available" }.orEmpty()) + ". Your password is never saved: this box only keeps a sign-in token, in encrypted storage.") {} + // The owner's permission (1.0 RC3, Paul: permission always wins over capacity). Off for any server Orbit doesn't know. + val workspace = remember { Workspaces.current(context) } + var own by remember { mutableStateOf(runCatching { workspace.ownServer }.getOrDefault(false)) } + SettingLine("This is my server", if (own) "You run this server, so Orbit skips the quiet first week here and reads its collections. Takes effect within the hour." + else "Switch on only for a server you own or run. On a shared server, leave it off: Orbit keeps its use of it light.") { + OnOff(own, Modifier, onClick = { own = !own; runCatching { workspace.ownServer = own } }) + } Heading("Help") SettingLine("Show me around", "The welcome tour again, from Ollie's welcome to You're on air. Nothing is changed by it.") { OrbitButton("Start", Modifier.focusRequester(firstSwitch), onClick = { Onboarding.start(tour = true) }) @@ -488,7 +495,7 @@ private fun AccountDetail(server: String, titles: Long?, onSignOut: () -> Unit, val requestsHour = remember { ServerRequests.lastHourTotal() }; val requestsDay = remember { ServerRequests.lastDayTotal() } val ceilingHit = remember { BackgroundPacing.ceilingHitMs?.let { java.text.SimpleDateFormat("HH:mm", java.util.Locale.UK).format(java.util.Date(it)) } } SettingLine("Requests to your server", "This hour: $requestsHour. Last 24 hours: $requestsDay. Counted on this TV only; nothing is sent anywhere. Background reading keeps to $BACKGROUND_BUDGET_LINE, " + - "and stops whenever this TV has made ${BackgroundPacing.TOTAL_CEILING} requests in an hour." + (ceilingHit?.let { " It last stopped at $it; watching carried on." } ?: "")) {} + "and stops whenever this TV has made ${BackgroundPacing.ceiling} requests in an hour" + (if (BackgroundPacing.tvs > 1) " (shared with ${BackgroundPacing.tvs - 1} other TV${if (BackgroundPacing.tvs > 2) "s" else ""} in the house)." else ".") + (ceilingHit?.let { " It last stopped at $it; watching carried on." } ?: "")) {} // Credits for the sounds Paul chose (8 November 2026): royalty-free effects, named with thanks (design/channels/sound/samples). Text("Sound credits: VHS, Horror, After Dark, Vortex, Heroes, Riot, Paradox and Ring X use royalty-free effects from Pixabay by " + "freesound_community, jusatti890, tomas_herudek, audiopapkin, vishiv and other Pixabay creators, mastered for Orbit. Thank you.", diff --git a/android/app/src/test/java/tv/orbit/classic/HouseholdBudgetTest.kt b/android/app/src/test/java/tv/orbit/classic/HouseholdBudgetTest.kt new file mode 100644 index 00000000..1875cc65 --- /dev/null +++ b/android/app/src/test/java/tv/orbit/classic/HouseholdBudgetTest.kt @@ -0,0 +1,22 @@ +package tv.orbit.classic + +import org.junit.Assert.* +import org.junit.Test + +/** 1.0 RC3 (Paul): limits sized for the whole house, so a second TV doesn't double what the server gets. */ +class HouseholdBudgetTest { + @org.junit.After fun reset() = BackgroundPacing.resetForTest() + @Test fun twoTvsShareTheBackgroundBudgetAndTheCeilingComesDown() { + BackgroundPacing.tvs = 1 + assertEquals(200, BackgroundPacing.share(BackgroundPacing.HOURLY_BUDGET)) + assertEquals(400, BackgroundPacing.ceiling) + BackgroundPacing.tvs = 2 + assertEquals(100, BackgroundPacing.share(BackgroundPacing.HOURLY_BUDGET)) + assertEquals(50, BackgroundPacing.share(QUIET_START_BUDGET)) + // Never so low that watching plus a little background can't fit. + assertEquals(BackgroundPacing.MIN_CEILING, BackgroundPacing.ceiling) + BackgroundPacing.tvs = 10 + assertEquals(25, BackgroundPacing.share(BackgroundPacing.HOURLY_BUDGET)) + assertEquals(BackgroundPacing.MIN_CEILING, BackgroundPacing.ceiling) + } +}