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
tools: a theme the scripts cannot read sends nothing, so it answers 2
xbshengf5e763ccd87c
diff --git a/tests/test_theme_config_root.py b/tests/test_theme_config_root.pyindex 80eed0b75..6636edc1d 100644--- a/tests/test_theme_config_root.py+++ b/tests/test_theme_config_root.py@@ -70,7 +70,8 @@ class ThemeConfigRootTest(unittest.TestCase):def assert_refused_as_not_an_object(self, text):self.theme_with(text)result = self.run_theme()- self.assertEqual(1, result.returncode, result.stdout + result.stderr)+ # 2: the run stops before anything is sent, the status theme.sh's header gives that shape.+ self.assertEqual(2, result.returncode, result.stdout + result.stderr)self.assertIn("is not a JSON object", result.stderr, result.stderr)self.assertIn(str(self.theme / "config.json"), result.stderr, "the message has to name the file")self.assertIn("themes/README.md", result.stderr, "and the page that says what a theme holds")@@ -90,7 +91,7 @@ class ThemeConfigRootTest(unittest.TestCase):with self.subTest(config=text.strip()):self.theme_with(text)result = self.run_theme()- self.assertEqual(1, result.returncode, result.stdout + result.stderr)+ self.assertEqual(2, result.returncode, result.stdout + result.stderr)self.assertIn("is not valid JSON", result.stderr, result.stderr)self.assertNotIn("is not a JSON object", result.stderr)self.assertEqual([], self.tv_calls())diff --git a/tests/test_theme_drive_letter_path.py b/tests/test_theme_drive_letter_path.pyindex 799dc6250..7e59eaa90 100644--- a/tests/test_theme_drive_letter_path.py+++ b/tests/test_theme_drive_letter_path.py@@ -48,8 +48,10 @@ class ThemeDriveLetterPathTest(unittest.TestCase):base = Path(tmp)tools = self.prepare(base / "repo")result, capture = self.run_theme(tools, missing, cwd=base)- self.assertEqual(result.returncode, 1, result.stderr)- self.assertEqual(result.stderr, f"no config.json in {missing}\n")+ # 2 and the sentence every refusal that sends nothing ends with: a folder that is not a theme+ # is a command line this script cannot use, not a push the TV refused.+ self.assertEqual(2, result.returncode, result.stderr)+ self.assertEqual(result.stderr, f"no config.json in {missing}. Nothing was sent to the TV.\n")self.assertFalse(capture.exists(), "a missing theme must not reach the TV transport")diff --git a/tests/test_theme_exit_status.py b/tests/test_theme_exit_status.pyindex a0a4e3ed9..069acdb8e 100644--- a/tests/test_theme_exit_status.py+++ b/tests/test_theme_exit_status.py@@ -17,6 +17,11 @@ reader (and an assistant following PROMPT.md) reads as "the theme was tried andAll three are judged before anything is asked of the TV now, in this script's own words, on exit 2. The usageline in the header is unchanged: a theme folder or --reset, one argument.+The rest of the same family answers 2 as well: a folder with no config.json, a config.json that does not+parse, and one the launcher would drop (an array, a number, a string) each stop before the first byte is+sent, and each answered 1 - the status of a push that ran and failed - while its own last sentence said+"Nothing was sent to the TV.". The header's 2 now names them.+These tests run the real tools/theme.sh against a stub tools/tv.py that appends every call to a log and exits 0,so "nothing was sent" means the log is missing and "the theme is still pushed" means the log holds theconfig.json push. A theme folder with a config.json is written in the test.@@ -129,6 +134,28 @@ class ThemeExitStatusTest(unittest.TestCase):result = self.run_theme(str(self.theme))self.assert_stopped(result, "python3 -m venv tools/venv")+ def test_a_folder_that_is_not_a_theme_stops_with_2(self):+ # `theme.sh themes`, or a list folder: no config.json to push, and nothing reached the TV - the defect+ # answered 1, which reads as "the theme was tried and the TV refused it".+ shutil.rmtree(self.theme)+ self.theme.mkdir()+ result = self.run_theme(str(self.theme))+ self.assert_stopped(result, "no config.json in")++ def test_a_config_json_that_does_not_parse_stops_with_2(self):+ (self.theme / "config.json").write_text('{"columns": 6,\n', encoding="utf-8")+ result = self.run_theme(str(self.theme))+ self.assert_stopped(result, "is not valid JSON")++ def test_a_config_json_the_launcher_would_drop_stops_with_2(self):+ # Config.read() answers "no overlay" for anything that is not a JSON object, so this theme would replace+ # the one on the TV with a file the launcher ignores: nothing may be sent, and 2 says so.+ for text in ('[{"columns": 6}]\n', "6\n", '"a theme"\n'):+ with self.subTest(config=text.strip()):+ (self.theme / "config.json").write_text(text, encoding="utf-8")+ result = self.run_theme(str(self.theme))+ self.assert_stopped(result, "is not a JSON object")+def test_a_theme_folder_still_pushes_with_a_host(self):# The other direction: the refusal above must not catch a folder, and the harness has to reach the TV.result = self.run_theme(str(self.theme))diff --git a/tests/test_theme_names_first.py b/tests/test_theme_names_first.pyindex 848a5c1e4..70ac11885 100644--- a/tests/test_theme_names_first.py+++ b/tests/test_theme_names_first.py@@ -46,7 +46,8 @@ class ThemeNamesFirstTest(unittest.TestCase):(self.device / "wallpapers" / "old.jpg").write_bytes(b"old collection")def assertTvUnchanged(self, result, name):- self.assertEqual(result.returncode, 1, result.stdout + result.stderr)+ # 2, not 1: a refused name sends nothing, and the header keeps 1 for a push that ran and failed.+ self.assertEqual(result.returncode, 2, result.stdout + result.stderr)self.assertIn(f"unsupported wallpaper filename: {name}", result.stderr)self.assertEqual((self.device / "config.json").read_bytes(), b'{"background": "#000000"}',"the refused theme's config.json must not replace the one on the TV")diff --git a/tools/theme.ps1 b/tools/theme.ps1index 7379a5878..47c16341b 100644--- a/tools/theme.ps1+++ b/tools/theme.ps1@@ -6,8 +6,11 @@## One argument, and -Reset takes none: both together are refused rather than one of them dropped (below).# Exit status: 0 the theme is on the TV, or the reset ran; 1 the theme could not be pushed, or Home did not-# restart after it (a failure of the shared helper stops this script with that status); 2 the command line is-# not one theme folder or -Reset, no TV host was given, or tools\venv is missing, so nothing was sent.+# restart after it (a failure of the shared helper stops this script with that status); 2 the run stopped+# before the theme was up and nothing was sent - the command line is not one theme folder or -Reset, the+# folder has no config.json or one the launcher would drop, a wallpaper name b64push.py refuses, no TV host+# was given, or tools\venv is missing. 1 is a run that reached the push, so a theme this script cannot read+# answers 2, as theme.sh does, instead of stopping with a PowerShell error record.param([Parameter(Position = 0)][string]$Theme,[switch]$Reset,@@ -31,7 +34,10 @@ if (-not $TvHost) {}$env:TV_HOST = $TvHost# Resolve the theme folder against the caller's directory before moving into tools\.-if ($Theme) { $Theme = (Resolve-Path $Theme).Path }+# A folder that is not there keeps the path as typed: Resolve-Path answers a missing path with its own error+# record and a script line number, where theme.sh stops at "no config.json in <typed path>" - a message about+# the folder the reader named, not about the cmdlet.+if ($Theme -and (Test-Path -LiteralPath $Theme)) { $Theme = (Resolve-Path -LiteralPath $Theme).Path }Set-Location $PSScriptRoot$py = 'venv\Scripts\python.exe'if (-not (Test-Path $py)) {@@ -87,13 +93,23 @@ if ($Reset) {}if (-not $Theme) { [Console]::Error.WriteLine('usage: theme.ps1 <theme folder> | -Reset'); exit 2 }$config = Join-Path $Theme 'config.json'-if (-not (Test-Path $config)) { throw "no config.json in $Theme" }-try { $themeJson = Get-Content $config -Raw | ConvertFrom-Json } catch { throw "$config is not valid JSON" }+# The three refusals below send nothing, so they answer 2 like theme.sh's - not 1, the status of a push that+# ran and failed - and in this script's own words instead of a PowerShell error record with a script line.+if (-not (Test-Path -LiteralPath $config)) {+ [Console]::Error.WriteLine("no config.json in $Theme. Nothing was sent to the TV.")+ exit 2+}+try { $themeJson = Get-Content $config -Raw | ConvertFrom-Json }+catch {+ [Console]::Error.WriteLine("$config is not valid JSON, so there is no theme to push (themes/README.md says what the file holds). Nothing was sent to the TV.")+ exit 2+}# Config.read() answers "no overlay" for anything that is not a JSON object, so an array, a number or a# string is a theme the launcher drops - and it replaces the theme the set had with the built-in config.# Judged here, before anything is pushed, so "is on the TV" cannot mean the opposite.if ($themeJson -isnot [System.Management.Automation.PSCustomObject]) {- throw "$config is not a JSON object of theme keys, so the launcher would ignore it and the TV would go back to its built-in config (themes/README.md). Nothing was sent to the TV."+ [Console]::Error.WriteLine("$config is not a JSON object of theme keys, so the launcher would ignore it and the TV would go back to its built-in config (themes/README.md). Nothing was sent to the TV.")+ exit 2}# Every collection name is checked before anything changes on the TV, as in theme.sh: a name refused halfway# through the push left the new config.json and part of the collection behind. b64push.py refuses '..' in a path.@@ -102,7 +118,10 @@ $images = @()if (Test-Path $wallpapers -PathType Container) {$images = @(Get-ChildItem $wallpapers -File | Where-Object { $_.Extension -match '^\.(jpg|jpeg|png|webp)$' })foreach ($image in $images) {- if ($image.Name -notmatch '^[A-Za-z0-9_.-]+$' -or $image.Name.Contains('..')) { throw "unsupported wallpaper filename: $($image.Name)" }+ if ($image.Name -notmatch '^[A-Za-z0-9_.-]+$' -or $image.Name.Contains('..')) {+ [Console]::Error.WriteLine("unsupported wallpaper filename: $($image.Name) (b64push.py takes letters, digits, '.', '_' and '-', with no '..' in the name). Nothing was sent to the TV.")+ exit 2+ }}}diff --git a/tools/theme.sh b/tools/theme.shindex c90cfbd8f..545494727 100755--- a/tools/theme.sh+++ b/tools/theme.sh@@ -8,9 +8,12 @@## One argument, and --reset takes none: a second word is refused rather than dropped (see below). Exit status:# 0 the theme is on the TV, or the reset ran; 1 the theme could not be pushed, or Home did not restart after-# it; 2 the run stopped before the theme was up - the command line is not one theme folder or --reset (a word-# that starts with a dash is not a folder name, -h and --help included), TV_HOST is unset or empty, the checkout-# has no tools/venv, or the TV was not reached (tv.py's and theme_restart.py's own message says which).+# it; 2 the run stopped before the theme was up and nothing was sent - the command line is not one theme folder+# or --reset (a word that starts with a dash is not a folder name, -h and --help included), the folder has no+# config.json or one the launcher would drop, a wallpaper name b64push.py refuses, TV_HOST is unset or empty,+# the checkout has no tools/venv, or the TV was not reached (tv.py's and theme_restart.py's own message says+# which). 1 is a run that reached the push, so a theme this script cannot read before it sends anything is not+# one: it answers 2 with the sentence every one of those refusals ends with.set -euo pipefailTHEME_ARG="${1:-}"# A theme folder or --reset, and nothing else. The first word alone decided everything the script did, so@@ -116,7 +119,11 @@ if [ "${1:-}" = --reset ]; thenexit 0fiTHEME="${THEME_ARG:?usage: theme.sh <theme folder> | --reset}"-[ -f "$THEME/config.json" ] || { echo "no config.json in $THEME" >&2; exit 1; }+# A folder that is not a theme, a file the launcher would drop, a wallpaper name the push refuses: each is a+# run that stops before anything is sent, which the header gives 2, not 1 - the status of a push that ran and+# failed. The three answered 1 while their own last sentence said "Nothing was sent to the TV.", so an owner+# (or an assistant following PROMPT.md) read a command line it could fix as the TV refusing the theme.+[ -f "$THEME/config.json" ] || { echo "no config.json in $THEME. Nothing was sent to the TV." >&2; exit 2; }# What the launcher makes of the file: Config.read() answers "no overlay" for anything that is not a JSON# object, so an array, a number or a string is a theme the TV drops - and it replaces the theme the set had,# which puts the built-in config.xml back. Reading the shape here, before anything is pushed, keeps a run@@ -137,8 +144,9 @@ case "$(theme_json_kind "$THEME/config.json")" inobject) ;;"not an object") echo "$THEME/config.json is not a JSON object of theme keys, so the launcher would ignore" \"it and the TV would go back to its built-in config (themes/README.md). Nothing was sent to the TV." >&2- exit 1 ;;- *) echo "$THEME/config.json is not valid JSON" >&2; exit 1 ;;+ exit 2 ;;+ *) echo "$THEME/config.json is not valid JSON, so there is no theme to push (themes/README.md says what the" \+ "file holds). Nothing was sent to the TV." >&2; exit 2 ;;esac# Every collection name is checked before anything changes on the TV: a name refused halfway through the push# left the new config.json and part of the collection behind. b64push.py refuses a path with '..' in it, so@@ -150,7 +158,11 @@ if [ -d "$THEME/wallpapers" ]; thencase "$IMAGE" in*.[jJ][pP][gG]|*.[jJ][pP][eE][gG]|*.[pP][nN][gG]|*.[wW][eE][bB][pP])NAME=$(basename "$IMAGE")- [[ "$NAME" =~ ^[A-Za-z0-9_.-]+$ && "$NAME" != *..* ]] || { echo "unsupported wallpaper filename: $NAME" >&2; exit 1; }+ if [[ ! "$NAME" =~ ^[A-Za-z0-9_.-]+$ || "$NAME" == *..* ]]; then+ echo "unsupported wallpaper filename: $NAME (b64push.py takes letters, digits, '.', '_' and '-', with no" \+ "'..' in the name). Nothing was sent to the TV." >&2+ exit 2+ fiNAMES="$NAMES $NAME" ;;esacdone