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:
@@ -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") }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user