Skip to content

Debloat any Android or Google TV over Wi-Fi and get an Apple TV-style home.

docs: where the sky's sunrise and sunset come from

xbsheng21bf632a073b
diff --git a/docs/sky.md b/docs/sky.md
index 7183eaad7..73210ef6a 100644
--- a/docs/sky.md
+++ b/docs/sky.md
@@ -1,7 +1,7 @@
# Sky
An optional backdrop that follows the clock: night blues until dawn, a soft blue day, then a warm
-horizon that peaks just before eight in the evening. It is off in the built-in configuration, so a
+horizon that peaks at seven in the evening. It is off in the built-in configuration, so a
launcher built from this repository behaves exactly like before until a theme turns it on.
```json
@@ -27,6 +27,34 @@ It sits behind everything, over the wallpaper when there is one, and the palette
purpose: the white clock, the greeting, the hero name and the dock band all keep their contrast at
the default 60.
+## Where the sun is
+
+With nothing set, the day the sky is drawn on is a fixed temperate one: sunrise 07:30, sunset 19:00,
+counted on the TV's own clock. The warm glow therefore peaks at seven in the evening wherever the TV
+is, and its position travels left to right through that day — which for most of Europe lands a couple of
+hours before the real sunset in summer, and after it in winter.
+
+To pin the sky to the real sun, set `latitude` and `longitude` in decimal degrees (south and west
+negative) in `launcher/app/src/main/res/values/config.xml`, before building the launcher:
+
+```xml
+<string name="latitude" translatable="false">54.69</string>
+<string name="longitude" translatable="false">25.28</string>
+```
+
+The sky then stretches the same anchors onto that place's real sunrise and sunset: NOAA's solar
+position equations in `Sun.java`, run on the TV from today's date and the system time zone. No
+network, no location permission, nothing to query, and a tenth of a degree only moves sunset by
+about half a minute, so a city's coordinates are plenty.
+
+Two days keep that fixed day instead: one with no sunrise or sunset at all (polar night, or the
+midnight sun), and one whose sunset the arithmetic puts past midnight, as in Reykjavik in June.
+Nothing is guessed from the time zone: it only decides which clock the minutes are counted on.
+
+**A theme cannot set this.** `sky_intensity` comes from a theme's `config.json`, but the place is a
+launcher build setting — `SkyView` reads those two string resources and `Config` never looks for them
+in a theme. A theme that wants the right sun says so in its own README, with the two lines above.
+
## Cost
`Sky` is pure maths — no Android types, no clock of its own; the caller passes the minutes since
diff --git a/tests/test_sky_place_note.py b/tests/test_sky_place_note.py
new file mode 100644
index 000000000..87e51011a
--- /dev/null
+++ b/tests/test_sky_place_note.py
@@ -0,0 +1,185 @@
+"""docs/sky.md has to say where the sky's sunrise and sunset come from.
+
+The page described the glow as following the sun, and named only `sky_intensity`, which a theme can set.
+The place the sun is computed for lives in two string resources in `config.xml` instead, and nothing in
+the repo mentioned them outside that file's own comment, so a theme author reading the page had no way to
+know the glow peaks at a fixed 19:00 rather than at their own sunset. These tests pin the section that
+says so to the code and the resource it describes: the two times against `Sky.java`'s reference constants,
+the two resources against `config.xml`, and "a theme cannot set this" against `Config.java` never reading
+the key and the Keys table never listing it. The page is reachable now too: `themes/README.md`'s backdrop
+section, where `sky_intensity` is explained, links it.
+"""
+import re
+import unittest
+from pathlib import Path
+
+ROOT = Path(__file__).resolve().parents[1]
+SKY_DOC = ROOT / "docs" / "sky.md"
+THEMES_DOC = ROOT / "themes" / "README.md"
+CONFIG_XML = ROOT / "launcher" / "app" / "src" / "main" / "res" / "values" / "config.xml"
+SKY_JAVA = ROOT / "launcher" / "app" / "src" / "main" / "java" / "com" / "gathin" / "tvhome" / "Sky.java"
+SKY_VIEW_JAVA = SKY_JAVA.with_name("SkyView.java")
+CONFIG_JAVA = SKY_JAVA.with_name("Config.java")
+
+HEADING = "## Where the sun is"
+
+
+def section(text, heading):
+ """The lines under `heading`, up to the next heading of the same level, or None."""
+ lines = text.splitlines()
+ try:
+ start = next(i for i, l in enumerate(lines) if l.strip() == heading)
+ except StopIteration:
+ return None
+ level = len(heading) - len(heading.lstrip("#"))
+ body = []
+ for line in lines[start + 1:]:
+ stripped = line.strip()
+ if stripped.startswith("#") and len(stripped) - len(stripped.lstrip("#")) <= level:
+ break
+ body.append(line)
+ return "\n".join(body)
+
+
+def markdown_destinations(text, base):
+ """Every relative destination a reader can click in `text`, resolved against `base`."""
+ out = []
+ for pattern in (r"\[[^\]]*\]\(([^)\s]+)\)", r'(?:href|src)="([^"]+)"'):
+ for target in re.findall(pattern, text):
+ if target.startswith(("http://", "https://", "mailto:", "#", "data:")):
+ continue
+ target = target.split("#")[0]
+ if target:
+ out.append((base / target).resolve())
+ return out
+
+
+def reference_times(java):
+ """The reference day as HH:MM, read from the two constants the page quotes."""
+ out = {}
+ for name in ("REF_SUNRISE", "REF_SUNSET"):
+ m = re.search(name + r"\s*=\s*(\d+)", java)
+ if not m:
+ raise AssertionError(f"Sky.java no longer defines {name}; the page's two times are unbacked")
+ minutes = int(m.group(1))
+ out[name] = f"{minutes // 60:02d}:{minutes % 60:02d}"
+ return out
+
+
+def keys_table(text):
+ """The first cell of every body row of the ## Keys table: the keys a theme can set."""
+ table = section(text, "## Keys")
+ if table is None:
+ raise AssertionError("themes/README.md has no ## Keys table")
+ out = []
+ for line in table.splitlines():
+ stripped = line.strip()
+ if not stripped.startswith("|") or re.match(r"^\|\s*-", stripped):
+ continue
+ first = stripped.strip("|").split("|")[0].strip().strip("`")
+ if first and first != "Key":
+ out.append(first)
+ return out
+
+
+class SkyPlaceSection(unittest.TestCase):
+ def setUp(self):
+ self.doc = SKY_DOC.read_text(encoding="utf-8")
+ self.section = section(self.doc, HEADING)
+ if self.section is None:
+ self.fail(f"docs/sky.md has no {HEADING!r} section")
+ self.java = SKY_JAVA.read_text(encoding="utf-8")
+ self.config_xml = CONFIG_XML.read_text(encoding="utf-8")
+
+ def test_names_both_coordinates_and_the_file_they_live_in(self):
+ for needle in ("latitude", "longitude"):
+ self.assertIn(needle, self.section)
+ self.assertIn("launcher/app/src/main/res/values/config.xml", self.section,
+ "the page has to name the file a reader edits, not only its file name")
+
+ def test_the_two_resources_exist_and_are_empty_by_default(self):
+ for name in ("latitude", "longitude"):
+ m = re.search(r'<string name="%s"([^>]*)>([^<]*)</string>' % name, self.config_xml)
+ if m is None:
+ self.fail(f"config.xml has no {name} string resource")
+ self.assertIn('translatable="false"', m.group(1), f"{name} is a number, not a translation")
+ self.assertEqual(m.group(2), "",
+ f"{name} is no longer empty by default; the page's fallback may be stale")
+
+ def test_the_fixed_day_it_quotes_is_the_one_sky_java_draws(self):
+ times = reference_times(self.java)
+ self.assertIn(times["REF_SUNRISE"], self.section,
+ f"the page should give the reference sunrise, {times['REF_SUNRISE']}")
+ self.assertIn(times["REF_SUNSET"], self.section,
+ f"the page should give the reference sunset, {times['REF_SUNSET']}")
+
+ def test_skyview_is_what_reads_them(self):
+ view = SKY_VIEW_JAVA.read_text(encoding="utf-8")
+ for name in ("latitude", "longitude"):
+ self.assertIn(f"R.string.{name}", view,
+ f"SkyView no longer reads R.string.{name}: the page points at the wrong knob")
+
+ def test_it_says_a_theme_cannot_set_the_place(self):
+ self.assertIn("theme", self.section.lower())
+ table = keys_table(THEMES_DOC.read_text(encoding="utf-8"))
+ self.assertNotIn("latitude", table, "latitude is a theme key now: the page has to say so")
+ self.assertNotIn("longitude", table, "longitude is a theme key now: the page has to say so")
+ config_java = CONFIG_JAVA.read_text(encoding="utf-8")
+ for name in ("latitude", "longitude"):
+ self.assertNotIn(f'"{name}"', config_java,
+ f"Config.java reads a {name} key now: a theme can set the place after all")
+
+ def test_it_names_the_days_that_fall_back(self):
+ for needle in ("polar night", "midnight sun"):
+ self.assertIn(needle, self.section,
+ f"the fixed day also covers the {needle}, and the page should say so")
+
+ def test_the_section_links_nothing_dead(self):
+ for target in markdown_destinations(self.section, SKY_DOC.parent):
+ self.assertTrue(target.exists(), f"{target} does not exist")
+
+
+class ThePageIsReachable(unittest.TestCase):
+ def test_the_backdrop_section_of_themes_readme_links_it(self):
+ text = THEMES_DOC.read_text(encoding="utf-8")
+ backdrop = section(text, "## Time-of-day backdrop")
+ if backdrop is None:
+ self.fail("themes/README.md has no backdrop section")
+ self.assertIn(SKY_DOC.resolve(), markdown_destinations(backdrop, THEMES_DOC.parent),
+ "the page a theme author needs is not linked from the key it explains")
+
+
+class TheCheckersThemselves(unittest.TestCase):
+ """Every check above has to fail on the text it is there to catch."""
+
+ def test_section_stops_at_the_next_heading_of_its_level(self):
+ text = "## Where the sun is\nA\n### Deeper\nB\n## Cost\nC\n"
+ self.assertEqual(section(text, "## Where the sun is"), "A\n### Deeper\nB")
+
+ def test_section_is_none_when_the_heading_is_gone(self):
+ self.assertIsNone(section("## Cost\nonly this\n", HEADING))
+
+ def test_the_wrong_times_are_reported(self):
+ times = reference_times(SKY_JAVA.read_text(encoding="utf-8"))
+ old = "sunrise 06:00, sunset 20:00"
+ self.assertNotIn(times["REF_SUNRISE"], old)
+ self.assertNotIn(times["REF_SUNSET"], old)
+
+ def test_keys_table_reads_the_first_cell_only(self):
+ table = ("## Keys\n\n| Key | Type | Meaning |\n|---|---|---|\n"
+ "| `sky_intensity` | 0 to 100 | see `latitude` in config.xml |\n\n## Next\n")
+ self.assertEqual(keys_table(table), ["sky_intensity"])
+
+ def test_a_destination_that_does_not_exist_is_caught(self):
+ doc = "see [the note](../docs/missing-page.md) and [tailscale](https://tailscale.com)"
+ targets = markdown_destinations(doc, ROOT / "themes")
+ self.assertEqual(len(targets), 1, "only the relative link is a destination to check")
+ self.assertFalse(targets[0].exists())
+
+ def test_the_reference_constants_are_required(self):
+ with self.assertRaises(AssertionError):
+ reference_times("final class Sky { }")
+
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/themes/README.md b/themes/README.md
index 29701c8a0..58269da5a 100644
--- a/themes/README.md
+++ b/themes/README.md
@@ -156,7 +156,7 @@ Android 10 is the known case. The default, `false`, keeps the normal motion.
## Time-of-day backdrop
`"sky_intensity": 60` draws a dark gradient over the wallpaper and behind everything else, that follows the
-clock: night blues, a soft blue day, then a warm horizon that peaks just before eight in the evening.
+clock: night blues, a soft blue day, then a warm horizon that peaks at seven in the evening.
The glow near the bottom edge travels from left to right with the sun. The colours stay dark so the
white clock, the hero name and the dock band keep their contrast. It is drawn as one 480×270 bitmap
and redrawn once a minute, never animated, so even a 1 GB TV has nothing to keep up with. `0` keeps
@@ -166,6 +166,11 @@ the plain background; the default is off (the reference launcher looks exactly a
{ "sky_intensity": 60 }
```
+That evening peak is a fixed reference day, sunrise 07:30 and sunset 19:00 on the TV's clock. The
+launcher follows the real sun only when `latitude` and `longitude` are set in
+`launcher/app/src/main/res/values/config.xml`, which is a build setting a theme cannot carry: see
+[docs/sky.md](../docs/sky.md) for the two lines and what still falls back.
+
## Adding a theme
Open a PR with a new folder here containing: