What's on for Orbit Central: a read-only schedule provider, its look, and orbit_channel
- content://tv.orbit.classic.schedule/summary: one row of version-1 JSON (look, onNow with next, tonight's films and events, tonight's Drive-In), from saved plans only, never the server; only channels that are on and that the viewer may see (Kids, After Dark's PIN); empty when there's nothing. - Guarded by tv.orbit.classic.permission.READ_SCHEDULE, signature|knownSigner, trusting only Orbit Central's release certificate. - An int extra orbit_channel on Orbit's launch tunes that channel once it's on and allowed, as the phone remote's Watch does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<!-- What's on, for Orbit Central only (13 November 2026): granted to apps signed with Orbit Central's key and to Orbit itself. -->
|
||||
<permission android:name="tv.orbit.classic.permission.READ_SCHEDULE" android:protectionLevel="signature|knownSigner"
|
||||
android:knownCerts="@array/orbit_central_certs" android:label="Read what's on in Orbit" />
|
||||
<uses-feature android:name="android.software.leanback" android:required="true" />
|
||||
<uses-feature android:name="android.hardware.touchscreen" android:required="false" />
|
||||
<application android:label="Orbit TV" android:theme="@style/OrbitTheme" android:icon="@drawable/orbit_app_icon" android:banner="@drawable/orbit_banner" android:allowBackup="false" android:networkSecurityConfig="@xml/network_security_config" android:supportsRtl="true">
|
||||
@@ -8,5 +11,7 @@
|
||||
<activity android:name=".MainActivity" android:exported="true" android:screenOrientation="landscape" android:launchMode="singleTask">
|
||||
<intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.LEANBACK_LAUNCHER" /></intent-filter>
|
||||
</activity>
|
||||
<provider android:name=".ScheduleSummaryProvider" android:authorities="tv.orbit.classic.schedule" android:exported="true"
|
||||
android:readPermission="tv.orbit.classic.permission.READ_SCHEDULE" android:writePermission="tv.orbit.classic.permission.READ_SCHEDULE" />
|
||||
</application>
|
||||
</manifest>
|
||||
|
||||
@@ -733,6 +733,17 @@ internal fun EmbyConnectionScreen(modifier: Modifier = Modifier, visible: Boolea
|
||||
SmartChannels.firstOrNull { it.number == number }?.takeIf { scheduledChannels.containsKey(number) }?.let { setSmartSchedule(it, true) }
|
||||
"${fresh.size} added to ${ch.name}. They join as it plans ahead; nothing already booked changes."
|
||||
}) } }
|
||||
// A channel asked for from outside (Orbit Central's cards, ExternalTune): tuned once it's on and allowed, as Watch from a phone.
|
||||
LaunchedEffect(ExternalTune.pending, scheduledChannels.keys) {
|
||||
val n = ExternalTune.pending ?: return@LaunchedEffect
|
||||
if (!scheduledChannels.containsKey(n)) return@LaunchedEffect
|
||||
ExternalTune.pending = null
|
||||
if (!lockedOut(n) && !profileHides(n)) {
|
||||
if (selectedNumber != n) { lastNumber = selectedNumber; selectedNumber = n }
|
||||
channelClockOffset = 0; watchingChannel = true
|
||||
if (!mainGuide && !mainHome && !mainWhatsOn && !mainCatchUp) onGuide()
|
||||
}
|
||||
}
|
||||
// The phone page (Create your own from a phone) asks the same of this screen as Settings does, and can tune the TV.
|
||||
DisposableEffect(channelMaker) {
|
||||
PhoneLink.handler = channelMaker?.let { m -> PhoneHandler(m, isOn = { n -> scheduledChannels.containsKey(n) }, watch = { n ->
|
||||
|
||||
@@ -69,7 +69,7 @@ class MainActivity : ComponentActivity() {
|
||||
* opens as one copy (singleTask, 8 November 2026), also when adb sends them to an Orbit already open.
|
||||
*/
|
||||
private fun readAdbRequests(intent: android.content.Intent?) = Edition.readAdbRequests(this, intent)
|
||||
override fun onNewIntent(intent: android.content.Intent) { super.onNewIntent(intent); setIntent(intent); readAdbRequests(intent) }
|
||||
override fun onNewIntent(intent: android.content.Intent) { super.onNewIntent(intent); setIntent(intent); readAdbRequests(intent); ExternalTune.read(intent) }
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
// A restore confirmed on the phone's backup is put in place first, before anything here reads the data.
|
||||
PhoneBackups.finishAtStart(this)
|
||||
@@ -90,6 +90,7 @@ class MainActivity : ComponentActivity() {
|
||||
ProviderSwitches.load(this)
|
||||
PlayerSwitches.load(this)
|
||||
readAdbRequests(intent)
|
||||
ExternalTune.read(intent)
|
||||
Edition.openPlaybackTest(this, intent)
|
||||
// Before anything is drawn, so a locked After Dark never shows for a moment.
|
||||
AfterDarkLock.load(this)
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
package tv.orbit.classic
|
||||
|
||||
import android.content.ContentProvider
|
||||
import android.content.ContentValues
|
||||
import android.database.Cursor
|
||||
import android.database.MatrixCursor
|
||||
import android.net.Uri
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.setValue
|
||||
import org.json.JSONArray
|
||||
import org.json.JSONObject
|
||||
import java.io.File
|
||||
|
||||
/**
|
||||
* What's on, for Orbit Central (Paul's home screen, 13 November 2026): content://tv.orbit.classic.schedule/summary returns one
|
||||
* row, one column "json", in the format agreed with it (version 1). Read only, and only from the plans already saved on this
|
||||
* box: it never asks the server anything. Guarded by READ_SCHEDULE, which only an app signed with Orbit Central's key holds.
|
||||
* It lists only what the person last watching may see: Kids sees its own channels, and After Dark is left out while its PIN
|
||||
* is set and locked. With nothing to say (signed out, no channels) it answers with an empty cursor.
|
||||
*/
|
||||
class ScheduleSummaryProvider : ContentProvider() {
|
||||
override fun onCreate() = true
|
||||
|
||||
override fun query(uri: Uri, projection: Array<out String>?, selection: String?, selectionArgs: Array<out String>?, sortOrder: String?): Cursor {
|
||||
val cursor = MatrixCursor(arrayOf("json"))
|
||||
if (uri.lastPathSegment != "summary") return cursor
|
||||
val context = context ?: return cursor
|
||||
runCatching {
|
||||
AfterDarkLock.load(context); Profiles.load(context)
|
||||
val dir = Workspaces.current(context).scheduleDir
|
||||
scheduleSummary(dir, System.currentTimeMillis(), OrbitSettings(context).look.name)?.let { cursor.addRow(arrayOf(it.toString())) }
|
||||
}
|
||||
return cursor
|
||||
}
|
||||
|
||||
override fun getType(uri: Uri) = "vnd.android.cursor.item/vnd.tv.orbit.summary"
|
||||
override fun insert(uri: Uri, values: ContentValues?): Uri? = null
|
||||
override fun delete(uri: Uri, selection: String?, selectionArgs: Array<out String>?) = 0
|
||||
override fun update(uri: Uri, values: ContentValues?, selection: String?, selectionArgs: Array<out String>?) = 0
|
||||
}
|
||||
|
||||
/** Tonight's highlights start from this hour, local time. */
|
||||
internal const val SUMMARY_TONIGHT_FROM_HOUR = 18
|
||||
internal const val SUMMARY_TONIGHT_MAX = 8
|
||||
|
||||
/**
|
||||
* The summary from the saved plans in [dir] (null when there are none): each channel on now and next, tonight's films and
|
||||
* events, and the Drive-In's show tonight. [allowed] says which channels the viewer may see; [look] is Orbit's look by name.
|
||||
*/
|
||||
internal fun scheduleSummary(dir: File, nowMs: Long, look: String, allowed: (Int) -> Boolean = { !lockedOut(it) && !profileHides(it) },
|
||||
zone: java.time.ZoneId = java.time.ZoneId.systemDefault()): JSONObject? {
|
||||
val plans = (dir.listFiles { f -> Regex("schedule-\\d+\\.json").matches(f.name) } ?: return null).mapNotNull { f ->
|
||||
val number = f.name.removePrefix("schedule-").removeSuffix(".json").toIntOrNull() ?: return@mapNotNull null
|
||||
val user = runCatching { JSONObject(f.readText()).optString("user") }.getOrNull()?.takeIf { it.isNotBlank() } ?: return@mapNotNull null
|
||||
val store = ScheduleStore(dir)
|
||||
if (number != DRIVE_IN_NUMBER && store.loadProgress(user, number)?.enabled != true) return@mapNotNull null
|
||||
store.loadPlan(user, number)?.let { number to it }
|
||||
}.filter { (n, _) -> allowed(n) }.toMap()
|
||||
if (plans.isEmpty()) return null
|
||||
fun name(n: Int) = ChannelBrands.forNumber(n)?.displayName ?: SmartChannels.firstOrNull { it.number == n }?.name ?: n.toString()
|
||||
fun title(e: ScheduleEntry) = e.media.item.title.substringBefore(" / ")
|
||||
val onNow = JSONArray()
|
||||
plans.filterKeys { it != DRIVE_IN_NUMBER }.toSortedMap().forEach { (n, plan) ->
|
||||
val at = plan.entries.indexOfFirst { nowMs >= it.startMs && nowMs < it.endMs }.takeIf { it >= 0 } ?: return@forEach
|
||||
val now = plan.entries[at]; val next = plan.entries.getOrNull(at + 1)
|
||||
onNow.put(JSONObject().put("channel", name(n)).put("number", n).put("channelId", n.toString()).put("title", title(now))
|
||||
.put("start", now.startMs).put("end", now.endMs).also { o -> next?.let { o.put("next", JSONObject().put("title", title(it)).put("start", it.startMs)) } })
|
||||
}
|
||||
val today = java.time.Instant.ofEpochMilli(nowMs).atZone(zone).toLocalDate()
|
||||
val eveningFrom = today.atTime(SUMMARY_TONIGHT_FROM_HOUR, 0).atZone(zone).toInstant().toEpochMilli()
|
||||
val eveningTo = today.plusDays(1).atTime(2, 0).atZone(zone).toInstant().toEpochMilli()
|
||||
val tonight = plans.filterKeys { it != DRIVE_IN_NUMBER }.flatMap { (n, plan) ->
|
||||
plan.entries.filter { it.startMs in maxOf(eveningFrom, nowMs)..eveningTo && (it.media.item.type == "Movie" || it.presentation.isNotEmpty()) }.map { n to it }
|
||||
}.sortedBy { it.second.startMs }.distinctBy { title(it.second) }.take(SUMMARY_TONIGHT_MAX)
|
||||
val out = JSONObject().put("version", 1).put("look", look).put("onNow", onNow)
|
||||
.put("tonight", JSONArray(tonight.map { (n, e) -> JSONObject().put("channel", name(n)).put("number", n).put("title", title(e)).put("start", e.startMs).put("end", e.endMs) }))
|
||||
plans[DRIVE_IN_NUMBER]?.entries?.firstOrNull { it.endMs > nowMs && it.startMs <= eveningTo && it.startMs >= today.atStartOfDay(zone).toInstant().toEpochMilli() }?.let { e ->
|
||||
out.put("driveIn", JSONObject().put("channel", "Drive-In").put("number", DRIVE_IN_NUMBER).put("title", title(e)).put("start", e.startMs).put("end", e.endMs))
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
/**
|
||||
* A channel to open from outside Orbit (Orbit Central's cards): the int extra "orbit_channel" on Orbit's launch. It's only a
|
||||
* request: Orbit tunes it once the channel is on and the viewer may see it, exactly as the phone remote's Watch does.
|
||||
*/
|
||||
internal object ExternalTune {
|
||||
var pending by androidx.compose.runtime.mutableStateOf<Int?>(null)
|
||||
fun read(intent: android.content.Intent?) {
|
||||
val n = intent?.getIntExtra("orbit_channel", -1) ?: -1
|
||||
if (n in 1..9999) { pending = n; intent?.removeExtra("orbit_channel") }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<!-- Orbit Central's release signing certificate (SHA-256), the only app given READ_SCHEDULE (see ScheduleSummaryProvider). -->
|
||||
<string-array name="orbit_central_certs" translatable="false">
|
||||
<item>ad0a167450cbc7a2d4913049e7a8b4f5cf802bb93f25d72658b3d2483a55cfe4</item>
|
||||
</string-array>
|
||||
</resources>
|
||||
@@ -0,0 +1,50 @@
|
||||
package tv.orbit.classic
|
||||
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Test
|
||||
import java.time.ZoneId
|
||||
|
||||
/** Orbit Central's what's on (13 November 2026): built from saved plans only, and only what the viewer may see. */
|
||||
class ScheduleSummaryTest {
|
||||
private val min = 60_000L
|
||||
private val zone = ZoneId.of("Europe/London")
|
||||
private val sixPm = java.time.LocalDate.of(2026, 11, 16).atTime(18, 0).atZone(zone).toInstant().toEpochMilli()
|
||||
private fun entry(id: String, title: String, type: String, start: Long, length: Long, presentation: String = "") =
|
||||
ScheduleEntry(id, EpisodeMark(1, 1), ScheduledMedia(SampleItem(title, type, length / min, "", id, length), "s$id", length), start, presentation = presentation)
|
||||
|
||||
private fun store(dir: java.io.File) = ScheduleStore(dir).also { s ->
|
||||
fun save(n: Int, vararg e: ScheduleEntry, on: Boolean = true) {
|
||||
s.savePlan("u1", n, ChannelPlan(e.toList(), ScheduleCursor()))
|
||||
s.saveProgress("u1", n, ScheduleStore.SavedProgress(on, ScheduleCursor()))
|
||||
}
|
||||
save(101, entry("a1", "Coastal Kitchens / S1 E2 / Crab", "Episode", sixPm - 10 * min, 30 * min), entry("a2", "The Quiz Hour / S2 E1 / One", "Episode", sixPm + 20 * min, 60 * min))
|
||||
save(305, entry("f1", "The Thing", "Movie", sixPm - 30 * min, 109 * min), entry("f2", "Alien", "Movie", sixPm + 79 * min, 117 * min))
|
||||
save(103, entry("x1", "Panel Show", "Episode", sixPm, 30 * min), on = false)
|
||||
save(DRIVE_IN_NUMBER, entry("d1", "Jaws", "Movie", sixPm + 2 * 60 * min, 124 * min))
|
||||
}
|
||||
|
||||
@Test fun nowNextTonightAndTheDriveInFromSavedPlans() {
|
||||
val dir = kotlin.io.path.createTempDirectory("summary").toFile()
|
||||
try {
|
||||
store(dir)
|
||||
val s = scheduleSummary(dir, sixPm, "RetroTube", allowed = { true }, zone = zone)!!
|
||||
assertEquals(1, s.getInt("version")); assertEquals("RetroTube", s.getString("look"))
|
||||
val now = s.getJSONArray("onNow")
|
||||
assertEquals(listOf(101, 305), (0 until now.length()).map { now.getJSONObject(it).getInt("number") }) // 103 is switched off
|
||||
assertEquals("Coastal Kitchens", now.getJSONObject(0).getString("title"))
|
||||
assertEquals("The Quiz Hour", now.getJSONObject(0).getJSONObject("next").getString("title"))
|
||||
assertEquals(listOf("Alien"), s.getJSONArray("tonight").let { a -> (0 until a.length()).map { a.getJSONObject(it).getString("title") } })
|
||||
assertEquals("Jaws", s.getJSONObject("driveIn").getString("title"))
|
||||
} finally { dir.deleteRecursively() }
|
||||
}
|
||||
|
||||
@Test fun lockedAndHiddenChannelsAreLeftOutAndNothingMeansNoRow() {
|
||||
val dir = kotlin.io.path.createTempDirectory("summary").toFile()
|
||||
try {
|
||||
store(dir)
|
||||
val s = scheduleSummary(dir, sixPm, "Night", allowed = { it != 305 }, zone = zone)!!
|
||||
assertTrue(s.toString().indexOf("Alien") < 0 && s.toString().indexOf("The Thing") < 0)
|
||||
assertNull(scheduleSummary(kotlin.io.path.createTempDirectory("empty").toFile(), sixPm, "Night", allowed = { true }, zone = zone))
|
||||
} finally { dir.deleteRecursively() }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user