Debloat any Android or Google TV over Wi-Fi and get an Apple TV-style home.
Python adbadblockandroid-tvandroid-tv-launcherapple-tvbloatware-removalclaude-codedebloatfire-tvgoogle-tvlauncherprivacysmart-tvsony-braviatclvibe-codingxiaomi
Launcher: race-weekend mode from an F1 calendar in a theme
Ritik Sahni8e1fd55a0c27
diff --git a/README.md b/README.mdindex d3ea4f6df..9aa4329f6 100644--- a/README.md+++ b/README.md@@ -261,6 +261,7 @@ tools/theme.sh themes/aurora # push a theme; --r| [`tools/disable.sh`](tools/disable.sh), [`restore.sh`](tools/restore.sh) | Apply or undo a debloat list, the undo from the state recorded before the change. || [`tools/recovery.py`](tools/recovery.py) | Writes the record `disable.sh` needs to undo itself, and prints the restore batch. || [`tools/theme.sh`](tools/theme.sh) | Push a folder from [`themes/`](themes/) to the launcher and restart Home. |+| [`tools/race_calendar.py`](tools/race_calendar.py) | Writes this season's F1 calendar into a theme for race-weekend mode, from the free Jolpica API. || [`launcher/build-and-install.sh`](launcher/build-and-install.sh) | Builds a shrunk release (about 390 KB), installs it, switches Home, and rolls back if Home does not land on it. |Debloat list paths passed to `disable.sh` and `restore.sh` are relative to the directory you rundiff --git a/launcher/app/src/main/java/com/gathin/tvhome/Config.java b/launcher/app/src/main/java/com/gathin/tvhome/Config.javaindex 96f18aae5..f5cd7354c 100644--- a/launcher/app/src/main/java/com/gathin/tvhome/Config.java+++ b/launcher/app/src/main/java/com/gathin/tvhome/Config.java@@ -90,6 +90,8 @@ final class Config {final boolean overlayApplied;/** Festive skin from a theme (festival, festival_until, greeting, accent_color); {@link Festival#NONE} if none. */final Festival festival;+ /** F1 weekends from a theme's race_calendar (see RaceWeekend); empty when the theme has none. */+ final List<RaceWeekend.Race> raceCalendar;private Config(List<String> dockApps, boolean fillDock, List<String> hiddenApps, String liveTvPackage,String liveTvAction, String sourcePanelService, String sourcePanelAction, String inputAction,@@ -98,7 +100,8 @@ final class Config {boolean showHomeSettingsShortcut, boolean showStats, boolean appLibrary, int backgroundColor, int skyIntensity,int[] settingsKeycodes, boolean settingsKeyPanel, boolean wallpaperEnabled, File wallpaper, List<File> wallpapers,int wallpaperRotationMinutes, int wallpaperDim, boolean overlayApplied,- Festival festival, int[] inputKeycodes, List<String> appKeys) {+ Festival festival, int[] inputKeycodes, List<String> appKeys,+ List<RaceWeekend.Race> raceCalendar) {this.inputKeycodes = inputKeycodes;this.appKeys = Collections.unmodifiableList(appKeys);this.dockApps = Collections.unmodifiableList(dockApps);@@ -135,6 +138,7 @@ final class Config {this.wallpaperDim = wallpaperDim;this.overlayApplied = overlayApplied;this.festival = festival;+ this.raceCalendar = Collections.unmodifiableList(raceCalendar);}/** The folder the theme tools push into; null when external storage is unavailable. */@@ -239,7 +243,37 @@ final class Config {shamsi, greetingName, moduleCards, reducedMotion, dockTitle, dockRow, reorderButton, vpn, homeSettings, showStats, library, background,Math.max(0, Math.min(100, skyIntensity)), settingsKeycodes, settingsKeyPanel, wallpaperEnabled, wallpaper,wallpapers, rotationMinutes, wallpaperDim, applied,- festival, inputKeycodes, appKeys);+ festival, inputKeycodes, appKeys, json == null ? Collections.emptyList() : raceCalendar(json));+ }++ /**+ * {@code "race_calendar": [{"round": 18, "name": "United States Grand Prix", "place": "Austin",+ * "sessions": [{"name": "FP1", "start": "2026-10-23T17:30:00Z"}, ...]}, ...]}. A race or session that does+ * not parse is left out on its own; the rest of the calendar still counts.+ */+ private static List<RaceWeekend.Race> raceCalendar(JSONObject json) {+ List<RaceWeekend.Race> races = new ArrayList<>();+ JSONArray list = json.optJSONArray("race_calendar");+ if (list == null) return races;+ for (int i = 0; i < list.length(); i++) {+ JSONObject r = list.optJSONObject(i);+ JSONArray sessions = r == null ? null : r.optJSONArray("sessions");+ if (sessions == null) continue;+ List<RaceWeekend.Session> parsed = new ArrayList<>();+ for (int j = 0; j < sessions.length(); j++) {+ JSONObject s = sessions.optJSONObject(j);+ if (s == null) continue;+ String name = s.optString("name", "").trim();+ try {+ if (!name.isEmpty()) parsed.add(new RaceWeekend.Session(name, java.time.Instant.parse(s.optString("start", ""))));+ } catch (java.time.format.DateTimeParseException ignored) {+ // a session without a readable start time cannot be counted down+ }+ }+ if (!parsed.isEmpty()) races.add(new RaceWeekend.Race(r.optInt("round", 0),+ r.optString("name", "Grand Prix").trim(), r.optString("place", "").trim(), parsed));+ }+ return races;}private static void syncThemeChoices(SharedPreferences choices, File dir, File config) {diff --git a/launcher/app/src/main/java/com/gathin/tvhome/MainActivity.java b/launcher/app/src/main/java/com/gathin/tvhome/MainActivity.javaindex 28a35f331..42efe050a 100644--- a/launcher/app/src/main/java/com/gathin/tvhome/MainActivity.java+++ b/launcher/app/src/main/java/com/gathin/tvhome/MainActivity.java@@ -113,6 +113,9 @@ public class MainActivity extends Activity implements AppAdapter.TileListener {private TextView btnWifi;private TextView shamsiDate;private TextView stats;+ private List<RaceWeekend.Race> raceCalendar;+ private View racePanel;+ private TextView raceKicker, raceHeadline, raceSessions;/** config.xml show_stats, overridable by a theme. Off: the line is gone and nothing is read. */private boolean showStats;private boolean shamsi;@@ -234,6 +237,7 @@ public class MainActivity extends Activity implements AppAdapter.TileListener {@Overridepublic void run() {updateGreeting();+ updateRace();updateWifiLabel();sky.update();wallpaperPlayer.update();@@ -282,6 +286,11 @@ public class MainActivity extends Activity implements AppAdapter.TileListener {btnWifi = findViewById(R.id.btnWifi);shamsiDate = findViewById(R.id.shamsiDate);stats = findViewById(R.id.stats);+ raceCalendar = cfg.raceCalendar;+ racePanel = findViewById(R.id.racePanel);+ raceKicker = findViewById(R.id.raceKicker);+ raceHeadline = findViewById(R.id.raceHeadline);+ raceSessions = findViewById(R.id.raceSessions);showStats = cfg.showStats;shamsi = cfg.shamsiDate;greetingName = cfg.greetingName;@@ -545,6 +554,7 @@ public class MainActivity extends Activity implements AppAdapter.TileListener {}rebuildOnResume = false;updateGreeting();+ updateRace();updateWifiLabel();updateInputsButton();if (showStats) startStats();@@ -1553,6 +1563,61 @@ public class MainActivity extends Activity implements AppAdapter.TileListener {if (shamsi) shamsiDate.setText(Shamsi.today());}+ // ---- race-weekend panel (a theme's race_calendar) -----------------------------------------------++ private static final int RACE_RED = 0xFFFF3B2F;++ /**+ * Shows or hides the race-weekend panel for this minute. Text only, set once a minute with the clock:+ * nothing animates, so the panel costs the GPU nothing between ticks.+ */+ private void updateRace() {+ if (raceCalendar.isEmpty()) return;+ RaceWeekend.State s = RaceWeekend.at(raceCalendar, java.time.Instant.now());+ if (s == null) {+ racePanel.setVisibility(View.GONE);+ return;+ }+ RaceWeekend.Race race = s.race;+ raceKicker.setText(race.place.isEmpty()+ ? getString(R.string.race_kicker_no_place, race.round, race.shortName())+ : getString(R.string.race_kicker, race.round, race.shortName(), race.place));++ if (s.live != null) {+ SpannableString live = new SpannableString("\u25CF " + getString(R.string.race_live, s.live.title()));+ live.setSpan(new android.text.style.ForegroundColorSpan(RACE_RED), 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);+ raceHeadline.setText(live);+ } else if (s.next != null) {+ String in = RaceWeekend.countdown(s.untilNext);+ raceHeadline.setText(s.next.isRace() ? getString(R.string.race_lights_out, in)+ : getString(R.string.race_next, s.next.title(), in));+ } else {+ raceHeadline.setText(R.string.race_finished);+ }++ // FP1 FRI 11:00 PM FP2 SAT 2:30 AM ...: done sessions fade, the live one is red, the next one bright.+ java.time.format.DateTimeFormatter when = java.time.format.DateTimeFormatter.ofPattern(+ android.text.format.DateFormat.is24HourFormat(this) ? "EEE HH:mm" : "EEE h:mm a", Locale.getDefault())+ .withZone(java.time.ZoneId.systemDefault());+ android.text.SpannableStringBuilder row = new android.text.SpannableStringBuilder();+ for (int i = 0; i < race.sessions.size(); i++) {+ RaceWeekend.Session session = race.sessions.get(i);+ if (i > 0) row.append(" ");+ int start = row.length();+ row.append(session.shortName()).append(" ").append(when.format(session.start).toUpperCase(Locale.getDefault()));+ int color;+ switch (s.statuses.get(i)) {+ case DONE: color = 0x47FFFFFF; break;+ case LIVE: color = RACE_RED; break;+ case NEXT: color = 0xFFFFFFFF; break;+ default: color = 0x99FFFFFF;+ }+ row.setSpan(new android.text.style.ForegroundColorSpan(color), start, row.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);+ }+ raceSessions.setText(row);+ racePanel.setVisibility(View.VISIBLE);+ }+/** Shows the Wi-Fi network name on the button when we can read it, otherwise the connection type. */private void updateWifiLabel() {String text = getString(R.string.wifi);diff --git a/launcher/app/src/main/java/com/gathin/tvhome/RaceWeekend.java b/launcher/app/src/main/java/com/gathin/tvhome/RaceWeekend.javanew file mode 100644index 000000000..f32a5c4d1--- /dev/null+++ b/launcher/app/src/main/java/com/gathin/tvhome/RaceWeekend.java@@ -0,0 +1,158 @@+package com.gathin.tvhome;++import java.time.Duration;+import java.time.Instant;+import java.util.ArrayList;+import java.util.Collections;+import java.util.List;+import java.util.Locale;++/**+ * Race-weekend mode. A theme's config.json can carry an F1 calendar ({@code race_calendar}, written by+ * tools/race_calendar.py); from shortly before a weekend's first session until the race is over, Home shows+ * a small panel with the next session and a countdown. Everything here is the clock against data the owner+ * pushed: no network, no Android types, so it is tested on the JVM.+ */+final class RaceWeekend {++ /** The panel shows from this long before a weekend's first session... */+ static final Duration LEAD = Duration.ofHours(12);+ /** ...until this long after the race starts: a race runs about two hours, then the result settles. */+ static final Duration TAIL = Duration.ofHours(4);++ enum Status { DONE, LIVE, NEXT, LATER }++ static final class Session {+ /** As written in the calendar: FP1, FP2, FP3, SPRINT QUALI, SPRINT, QUALIFYING or RACE. */+ final String name;+ final Instant start;++ Session(String name, Instant start) {+ this.name = name.trim().toUpperCase(Locale.ROOT);+ this.start = start;+ }++ boolean isRace() {+ return name.equals("RACE");+ }++ /** Roughly how long the session is live; only used to tell live from done. */+ Duration length() {+ if (isRace()) return Duration.ofHours(2);+ if (name.equals("SPRINT QUALI")) return Duration.ofMinutes(45);+ return Duration.ofHours(1);+ }++ /** The name in the countdown line: "Qualifying in 2h 14m". */+ String title() {+ switch (name) {+ case "FP1": return "Practice 1";+ case "FP2": return "Practice 2";+ case "FP3": return "Practice 3";+ case "SPRINT QUALI": return "Sprint qualifying";+ case "SPRINT": return "Sprint";+ case "QUALIFYING": return "Qualifying";+ case "RACE": return "Race";+ default: return name.charAt(0) + name.substring(1).toLowerCase(Locale.ROOT);+ }+ }++ /** The name in the session row, kept short so a whole weekend fits on one line. */+ String shortName() {+ switch (name) {+ case "SPRINT QUALI": return "SQ";+ case "QUALIFYING": return "QUALI";+ default: return name;+ }+ }+ }++ static final class Race {+ final int round;+ final String name;+ final String place;+ /** In start order; the last one is the race. */+ final List<Session> sessions;++ Race(int round, String name, String place, List<Session> sessions) {+ this.round = round;+ this.name = name;+ this.place = place;+ List<Session> sorted = new ArrayList<>(sessions);+ sorted.sort((a, b) -> a.start.compareTo(b.start));+ this.sessions = Collections.unmodifiableList(sorted);+ }++ /** "United States Grand Prix" becomes "United States GP", which fits the panel's top line. */+ String shortName() {+ return name.replace("Grand Prix", "GP").trim();+ }+ }++ /** What the panel shows at one moment of a race weekend. */+ static final class State {+ final Race race;+ /** One per session of {@link #race}, same order. */+ final List<Status> statuses;+ /** The session on track now, or null. */+ final Session live;+ /** The next session to start, or null once the race has started. */+ final Session next;+ /** Time until {@link #next} starts; null when there is no next session. */+ final Duration untilNext;++ State(Race race, List<Status> statuses, Session live, Session next, Duration untilNext) {+ this.race = race;+ this.statuses = Collections.unmodifiableList(statuses);+ this.live = live;+ this.next = next;+ this.untilNext = untilNext;+ }++ /** The race is over and the panel is only showing the weekend until {@link #TAIL} runs out. */+ boolean finished() {+ return live == null && next == null;+ }+ }++ private RaceWeekend() {+ }++ /** The weekend {@code now} falls in, or null when no race is near. */+ static State at(List<Race> calendar, Instant now) {+ for (Race race : calendar) {+ if (race.sessions.isEmpty()) continue;+ Instant opens = race.sessions.get(0).start.minus(LEAD);+ Instant closes = race.sessions.get(race.sessions.size() - 1).start.plus(TAIL);+ if (now.isBefore(opens) || !now.isBefore(closes)) continue;++ List<Status> statuses = new ArrayList<>();+ Session live = null, next = null;+ for (Session s : race.sessions) {+ if (now.isBefore(s.start)) {+ statuses.add(next == null ? Status.NEXT : Status.LATER);+ if (next == null) next = s;+ } else if (now.isBefore(s.start.plus(s.length()))) {+ statuses.add(Status.LIVE);+ live = s;+ } else {+ statuses.add(Status.DONE);+ }+ }+ return new State(race, statuses, live, next, next == null ? null : Duration.between(now, next.start));+ }+ return null;+ }++ /**+ * "42 min", "2h 14m", "1d 3h". Rounded up to the minute, so a session 20 seconds away still reads+ * "1 min" and the countdown never says 0 before the session is live.+ */+ static String countdown(Duration d) {+ long minutes = Math.max(1, (d.getSeconds() + 59) / 60);+ if (minutes < 60) return minutes + " min";+ long hours = minutes / 60;+ if (hours < 24) return hours + "h " + (minutes % 60) + "m";+ return (hours / 24) + "d " + (hours % 24) + "h";+ }+}diff --git a/launcher/app/src/main/res/drawable/race_bar.xml b/launcher/app/src/main/res/drawable/race_bar.xmlnew file mode 100644index 000000000..cd42c6bb9--- /dev/null+++ b/launcher/app/src/main/res/drawable/race_bar.xml@@ -0,0 +1,5 @@+<?xml version="1.0" encoding="utf-8"?>+<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">+ <solid android:color="#FFFF3B2F" />+ <corners android:radius="1.5dp" />+</shape>diff --git a/launcher/app/src/main/res/layout-iw/activity_main.xml b/launcher/app/src/main/res/layout-iw/activity_main.xmlindex 97ed870f3..e31d77342 100644--- a/launcher/app/src/main/res/layout-iw/activity_main.xml+++ b/launcher/app/src/main/res/layout-iw/activity_main.xml@@ -21,6 +21,68 @@android:layout_height="match_parent"android:alpha="0" />+ <!-- Race-weekend panel (a theme's race_calendar, see RaceWeekend), mirrored: under the clock on the right. -->+ <LinearLayout+ android:id="@+id/racePanel"+ android:layout_width="wrap_content"+ android:layout_height="wrap_content"+ android:layout_gravity="top|right"+ android:layout_marginEnd="60dp"+ android:layout_marginTop="158dp"+ android:gravity="right"+ android:orientation="vertical"+ android:focusable="false"+ android:importantForAccessibility="no"+ android:visibility="gone">++ <LinearLayout+ android:layout_width="wrap_content"+ android:layout_height="wrap_content"+ android:orientation="horizontal"+ android:gravity="center_vertical">++ <TextView+ android:id="@+id/raceKicker"+ android:layout_width="wrap_content"+ android:layout_height="wrap_content"+ android:singleLine="true"+ android:textColor="#B3FFFFFF"+ android:textSize="12sp"+ android:fontFamily="@font/outfit_medium"+ android:letterSpacing="0.22"+ android:textAllCaps="true" />++ <View+ android:layout_width="3dp"+ android:layout_height="13dp"+ android:layout_marginStart="10dp"+ android:background="@drawable/race_bar" />+ </LinearLayout>++ <TextView+ android:id="@+id/raceHeadline"+ android:layout_width="wrap_content"+ android:layout_height="wrap_content"+ android:layout_marginTop="8dp"+ android:singleLine="true"+ android:textColor="#FFFFFFFF"+ android:textSize="34sp"+ android:fontFamily="@font/outfit_light"+ android:letterSpacing="-0.01"+ android:includeFontPadding="false" />++ <TextView+ android:id="@+id/raceSessions"+ android:layout_width="wrap_content"+ android:layout_height="wrap_content"+ android:layout_marginTop="12dp"+ android:singleLine="true"+ android:textColor="#99FFFFFF"+ android:textSize="12sp"+ android:fontFamily="@font/outfit_medium"+ android:letterSpacing="0.12" />+ </LinearLayout>+<!-- Top shelf: the focused dock app's name, positioned above the dock in code. --><TextViewandroid:id="@+id/heroName"diff --git a/launcher/app/src/main/res/layout/activity_main.xml b/launcher/app/src/main/res/layout/activity_main.xmlindex 458c550dd..7edb2227d 100644--- a/launcher/app/src/main/res/layout/activity_main.xml+++ b/launcher/app/src/main/res/layout/activity_main.xml@@ -19,6 +19,70 @@android:layout_height="match_parent"android:alpha="0" />+ <!-- Race-weekend panel (a theme's race_calendar, see RaceWeekend): in the free space under the clock,+ shown only from shortly before a weekend's first session until the race is over. Updated once a+ minute with the clock, never animated. -->+ <LinearLayout+ android:id="@+id/racePanel"+ android:layout_width="wrap_content"+ android:layout_height="wrap_content"+ android:layout_gravity="top|left"+ android:layout_marginStart="60dp"+ android:layout_marginTop="158dp"+ android:orientation="vertical"+ android:focusable="false"+ android:importantForAccessibility="no"+ android:visibility="gone">++ <LinearLayout+ android:layout_width="wrap_content"+ android:layout_height="wrap_content"+ android:orientation="horizontal"+ android:gravity="center_vertical">++ <!-- A short kerb-red bar, the panel's one accent. -->+ <View+ android:layout_width="3dp"+ android:layout_height="13dp"+ android:layout_marginEnd="10dp"+ android:background="@drawable/race_bar" />++ <TextView+ android:id="@+id/raceKicker"+ android:layout_width="wrap_content"+ android:layout_height="wrap_content"+ android:singleLine="true"+ android:textColor="#B3FFFFFF"+ android:textSize="12sp"+ android:fontFamily="@font/outfit_medium"+ android:letterSpacing="0.22"+ android:textAllCaps="true" />+ </LinearLayout>++ <TextView+ android:id="@+id/raceHeadline"+ android:layout_width="wrap_content"+ android:layout_height="wrap_content"+ android:layout_marginTop="8dp"+ android:singleLine="true"+ android:textColor="#FFFFFFFF"+ android:textSize="34sp"+ android:fontFamily="@font/outfit_light"+ android:letterSpacing="-0.01"+ android:includeFontPadding="false" />++ <TextView+ android:id="@+id/raceSessions"+ android:layout_width="wrap_content"+ android:layout_height="wrap_content"+ android:layout_marginTop="12dp"+ android:singleLine="true"+ android:textColor="#99FFFFFF"+ android:textSize="12sp"+ android:fontFamily="@font/outfit_medium"+ android:letterSpacing="0.12" />+ </LinearLayout>+<!-- Top shelf: the focused dock app's name, positioned above the dock in code. --><TextViewandroid:id="@+id/heroName"diff --git a/launcher/app/src/main/res/values-iw/strings.xml b/launcher/app/src/main/res/values-iw/strings.xmlindex 82e6ddd43..f07d937b3 100644--- a/launcher/app/src/main/res/values-iw/strings.xml+++ b/launcher/app/src/main/res/values-iw/strings.xml@@ -88,4 +88,12 @@<item quantity="other">%1$d אפליקציות</item></plurals><string name="greeting_with_name">%1$s, %2$s</string>++ <!-- Race-weekend panel (RaceWeekend). -->+ <string name="race_kicker">סבב %1$d · %2$s · %3$s</string>+ <string name="race_kicker_no_place">סבב %1$d · %2$s</string>+ <string name="race_next">%1$s בעוד %2$s</string>+ <string name="race_lights_out">הזינוק בעוד %1$s</string>+ <string name="race_live">%1$s · בשידור חי</string>+ <string name="race_finished">הדגל המשובץ</string></resources>diff --git a/launcher/app/src/main/res/values/strings.xml b/launcher/app/src/main/res/values/strings.xmlindex 454dba403..b3f1069fb 100644--- a/launcher/app/src/main/res/values/strings.xml+++ b/launcher/app/src/main/res/values/strings.xml@@ -90,4 +90,12 @@</plurals><!-- The greeting, then greeting_name: "Good morning, Mr. Trịnh". --><string name="greeting_with_name">%1$s, %2$s</string>++ <!-- Race-weekend panel (RaceWeekend). Session names come from the calendar. -->+ <string name="race_kicker">Round %1$d · %2$s · %3$s</string>+ <string name="race_kicker_no_place">Round %1$d · %2$s</string>+ <string name="race_next">%1$s in %2$s</string>+ <string name="race_lights_out">Lights out in %1$s</string>+ <string name="race_live">%1$s · live</string>+ <string name="race_finished">Chequered flag</string></resources>diff --git a/launcher/app/src/test/java/com/gathin/tvhome/RaceWeekendTest.java b/launcher/app/src/test/java/com/gathin/tvhome/RaceWeekendTest.javanew file mode 100644index 000000000..6f17478ee--- /dev/null+++ b/launcher/app/src/test/java/com/gathin/tvhome/RaceWeekendTest.java@@ -0,0 +1,83 @@+package com.gathin.tvhome;++import static org.junit.Assert.assertEquals;+import static org.junit.Assert.assertNull;+import static org.junit.Assert.assertSame;+import static org.junit.Assert.assertTrue;++import java.time.Duration;+import java.time.Instant;+import java.util.Arrays;+import java.util.Collections;+import java.util.List;++import org.junit.Test;++public class RaceWeekendTest {++ // The 2026 United States GP, times as Jolpica gives them (UTC).+ private static final RaceWeekend.Race AUSTIN = new RaceWeekend.Race(18, "United States Grand Prix", "Austin",+ Arrays.asList(+ // Out of order on purpose: the calendar is sorted by start time.+ new RaceWeekend.Session("race", Instant.parse("2026-10-25T20:00:00Z")),+ new RaceWeekend.Session("FP1", Instant.parse("2026-10-23T17:30:00Z")),+ new RaceWeekend.Session("FP2", Instant.parse("2026-10-23T21:00:00Z")),+ new RaceWeekend.Session("FP3", Instant.parse("2026-10-24T17:30:00Z")),+ new RaceWeekend.Session("Qualifying", Instant.parse("2026-10-24T21:00:00Z"))));+ private static final List<RaceWeekend.Race> CALENDAR = Collections.singletonList(AUSTIN);++ @Test+ public void nothingBeforeTheWeekendOpens() {+ assertNull(RaceWeekend.at(CALENDAR, Instant.parse("2026-10-23T05:29:00Z")));+ }++ @Test+ public void opensTwelveHoursBeforeFirstPractice() {+ RaceWeekend.State s = RaceWeekend.at(CALENDAR, Instant.parse("2026-10-23T05:30:00Z"));+ assertSame(AUSTIN, s.race);+ assertEquals("FP1", s.next.name);+ assertEquals(Duration.ofHours(12), s.untilNext);+ assertEquals(RaceWeekend.Status.NEXT, s.statuses.get(0));+ assertEquals(RaceWeekend.Status.LATER, s.statuses.get(4));+ }++ @Test+ public void aSessionOnTrackIsLiveAndTheNextOneIsCountedDown() {+ RaceWeekend.State s = RaceWeekend.at(CALENDAR, Instant.parse("2026-10-24T21:30:00Z"));+ assertEquals("QUALIFYING", s.live.name);+ assertTrue(s.next.isRace());+ assertEquals(Arrays.asList(RaceWeekend.Status.DONE, RaceWeekend.Status.DONE, RaceWeekend.Status.DONE,+ RaceWeekend.Status.LIVE, RaceWeekend.Status.NEXT), s.statuses);+ }++ @Test+ public void theRaceIsLiveForTwoHoursThenFinished() {+ RaceWeekend.State live = RaceWeekend.at(CALENDAR, Instant.parse("2026-10-25T21:59:00Z"));+ assertTrue(live.live.isRace());+ assertNull(live.next);+ RaceWeekend.State done = RaceWeekend.at(CALENDAR, Instant.parse("2026-10-25T22:00:00Z"));+ assertTrue(done.finished());+ }++ @Test+ public void closesFourHoursAfterTheRaceStarts() {+ assertTrue(RaceWeekend.at(CALENDAR, Instant.parse("2026-10-25T23:59:00Z")).finished());+ assertNull(RaceWeekend.at(CALENDAR, Instant.parse("2026-10-26T00:00:00Z")));+ }++ @Test+ public void countdownRoundsUpAndChangesUnits() {+ assertEquals("1 min", RaceWeekend.countdown(Duration.ofSeconds(20)));+ assertEquals("42 min", RaceWeekend.countdown(Duration.ofMinutes(42)));+ assertEquals("2h 14m", RaceWeekend.countdown(Duration.ofMinutes(134)));+ assertEquals("1d 3h", RaceWeekend.countdown(Duration.ofHours(27).plusMinutes(10)));+ }++ @Test+ public void namesForThePanel() {+ assertEquals("United States GP", AUSTIN.shortName());+ assertEquals("QUALI", AUSTIN.sessions.get(3).shortName());+ assertEquals("Qualifying", AUSTIN.sessions.get(3).title());+ assertEquals("SQ", new RaceWeekend.Session("sprint quali", Instant.EPOCH).shortName());+ }+}diff --git a/themes/README.md b/themes/README.mdindex f81ca920c..a3fb75823 100644--- a/themes/README.md+++ b/themes/README.md@@ -60,6 +60,7 @@ is ignored, and a file that doesn't parse is ignored as a whole, so a theme can| `settings_key_panel` | bool | Those buttons open a small quick settings panel (TV settings, Display, Network, Apps, Launcher settings) instead of the TV's Settings || `input_key_keycodes` | list of keycodes | More remote buttons that open the input switcher, for `InputKeyService` (`KEYCODE_TV` and `KEYCODE_TV_INPUT` always do) || `app_keys` | list of strings | Remote buttons that open an app, as `"190:com.google.android.youtube.tv"` or `"KEYCODE_BUTTON_3:com.google.android.youtube.tv"`, for `InputKeyService` or `HomeKeyService` |+| `race_calendar` | list of races | F1 race-weekend mode: from 12 hours before a weekend's first session until 4 hours after the race starts, a panel under the clock shows the next session with a countdown (or the live one) and the weekend's session times in the TV's time zone. Write it with `tools/race_calendar.py <theme folder>`, which fetches the season from the free Jolpica API; the launcher itself never goes online |## Wallpapersdiff --git a/tools/race_calendar.py b/tools/race_calendar.pynew file mode 100644index 000000000..ca1fc0d68--- /dev/null+++ b/tools/race_calendar.py@@ -0,0 +1,87 @@+#!/usr/bin/env python3+"""Put this season's F1 calendar into a theme, for the launcher's race-weekend mode.++ race_calendar.py <theme folder> fetch the current season and write race_calendar into+ <theme folder>/config.json, keeping every other key+ race_calendar.py <theme folder> --season 2027++Then push the theme as usual: tools/theme.sh <theme folder>. The launcher never goes online; this script is+the only thing that does, once, on your computer. The data comes from Jolpica (https://jolpi.ca), the free+community successor to the Ergast API: no key, no account. Run it again when F1 moves a session or a new+season starts. Races that are already over are left out.+"""+import argparse+import datetime+import json+from pathlib import Path+import sys+import urllib.request++API = "https://api.jolpi.ca/ergast/f1/{season}.json?limit=100"+# Jolpica's session keys, in weekend order, and the names the launcher shows.+SESSIONS = (+ ("FirstPractice", "FP1"),+ ("SecondPractice", "FP2"),+ ("ThirdPractice", "FP3"),+ ("SprintQualifying", "SPRINT QUALI"),+ ("SprintShootout", "SPRINT QUALI"), # the 2023 name for the same session+ ("Sprint", "SPRINT"),+ ("Qualifying", "QUALIFYING"),+)+++def instant(block):+ """"2026-10-23" + "17:30:00Z" as one UTC timestamp; None when the time is not published yet."""+ if not block.get("date") or not block.get("time"):+ return None+ return f"{block['date']}T{block['time']}" if block["time"].endswith("Z") else f"{block['date']}T{block['time']}Z"+++def calendar(races, now):+ out = []+ for race in races:+ sessions = []+ for key, name in SESSIONS:+ if key in race and (start := instant(race[key])):+ sessions.append({"name": name, "start": start})+ start = instant(race)+ if not start:+ continue+ sessions.append({"name": "RACE", "start": start})+ # The launcher keeps a weekend on screen for four hours after the start; a day covers that.+ if datetime.datetime.fromisoformat(start.replace("Z", "+00:00")) < now - datetime.timedelta(days=1):+ continue+ out.append({+ "round": int(race["round"]),+ "name": race["raceName"],+ "place": race.get("Circuit", {}).get("Location", {}).get("locality", ""),+ "sessions": sessions,+ })+ return out+++def main():+ parser = argparse.ArgumentParser(description="Put this season's F1 calendar into a theme.")+ parser.add_argument("theme", help="theme folder with a config.json (created if missing)")+ parser.add_argument("--season", default="current", help="season year, default the current one")+ args = parser.parse_args()++ config = Path(args.theme) / "config.json"+ theme = json.loads(config.read_text(encoding="utf-8")) if config.is_file() else {}+ request = urllib.request.Request(API.format(season=args.season), headers={"User-Agent": "cleanyourtv"})+ with urllib.request.urlopen(request, timeout=30) as response:+ table = json.load(response)["MRData"]["RaceTable"]+ now = datetime.datetime.now(datetime.timezone.utc)+ races = calendar(table["Races"], now)+ if not races:+ sys.exit(f"no upcoming races in the {table['season']} calendar; try --season with next year")+ theme["race_calendar"] = races+ config.parent.mkdir(parents=True, exist_ok=True)+ config.write_text(json.dumps(theme, indent=2, ensure_ascii=False) + "\n", encoding="utf-8")+ first = races[0]+ print(f"{len(races)} races from the {table['season']} season -> {config}")+ print(f"next: round {first['round']} {first['name']}, race {first['sessions'][-1]['start']}")+++if __name__ == "__main__":+ main()