Skip to content

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

tools: theme.sh --reset clears the theme's wallpapers/ collection

xbsheng10ed5d86ed3e
diff --git a/tests/test_theme_push_ownership.py b/tests/test_theme_push_ownership.py
index 935b8e7b4..7a68e4510 100644
--- a/tests/test_theme_push_ownership.py
+++ b/tests/test_theme_push_ownership.py
@@ -219,6 +219,56 @@ class ThemePushTest(unittest.TestCase):
self.assertLess(put.index("content write"), put.index("cp $t $dir/$name"), put)
self.assertIn("Unsupported operation", put, "Android 8/9 exit 0 without writing; cp has to run then")
+ def test_reset_clears_the_wallpaper_collection(self):
+ """--reset promises the built-in config.xml, but the picker reads wallpapers/ from the TV itself."""
+ (self.device / "config.json").write_bytes(self.config)
+ (self.device / "wallpaper.jpg").write_bytes(b"old wallpaper")
+ collection = self.device / "wallpapers"
+ collection.mkdir()
+ for name in ("01-dusk.jpg", "02-dunes.PNG", "03-lake.webp"):
+ (collection / name).write_bytes(b"\x89picture")
+ (collection / "captions.txt").write_text("01-dusk.jpg\tDusk\n", encoding="utf-8")
+ result = self.run_theme("--reset")
+ self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
+ self.assertEqual(sorted(p.name for p in collection.iterdir()), [],
+ "the launcher's wallpaper picker lists this folder itself, so a reset that leaves "
+ "pictures in it still offers the theme it just removed")
+ self.assertFalse((self.device / "config.json").exists())
+ self.assertFalse((self.device / "wallpaper.jpg").exists())
+
+ def test_a_push_and_a_reset_clear_the_collection_with_one_command(self):
+ """One clear, used by both paths: two copies are how --reset came to miss the collection."""
+ (self.theme / "wallpapers").mkdir()
+ (self.theme / "wallpapers" / "dusk.jpg").write_bytes(b"\xff\xd8dusk")
+ pushed = self.run_theme(str(self.theme))
+ self.assertEqual(pushed.returncode, 0, pushed.stdout + pushed.stderr)
+ push_commands = self.shell_commands()
+ self.log.unlink()
+ reset = self.run_theme("--reset")
+ self.assertEqual(reset.returncode, 0, reset.stdout + reset.stderr)
+ reset_commands = self.shell_commands()
+
+ clear = [c for c in push_commands
+ if "content delete --uri content://com.gathin.tvhome.theme/wallpapers 2>/dev/null" in c]
+ self.assertEqual(len(clear), 1, f"a push empties the collection first: {push_commands}")
+ self.assertIn(f"{DEVICE_DIR}/wallpapers/*.jpg", clear[0])
+ self.assertIn(f"{DEVICE_DIR}/wallpapers/*.WEBP", clear[0], "a picture named .WEBP counts too")
+ joined = " | ".join(reset_commands)
+ self.assertIn(clear[0], joined,
+ "the reset has to run the very same clear, or the two paths drift apart again")
+ self.assertIn(f"content delete --uri content://com.gathin.tvhome.theme/wallpapers/captions.txt", joined)
+
+ def test_the_windows_script_clears_the_collection_on_reset(self):
+ """theme.ps1 cannot run here, so the -Reset branch is pinned as text against theme.sh."""
+ script = (TOOLS / "theme.ps1").read_text(encoding="utf-8")
+ reset = next(line for line in script.splitlines() if line.strip().startswith("& $py -I tv.py \"mkdir -p $dir"))
+ self.assertIn("$(Drop 'wallpapers/captions.txt')", reset)
+ self.assertIn("$clearWallpapers", reset, "one shared clear, as in theme.sh")
+ clear = next(line for line in script.splitlines() if line.startswith("$clearWallpapers = "))
+ self.assertIn("rm -f $dir/wallpapers/*.jpg", clear)
+ self.assertIn("content delete --uri $uri/wallpapers", clear)
+ self.assertNotIn("captions", clear, "the captions file is dropped on its own line, as in theme.sh")
+
if __name__ == "__main__":
unittest.main()
diff --git a/tools/theme.ps1 b/tools/theme.ps1
index 2d57d9354..3022679cf 100644
--- a/tools/theme.ps1
+++ b/tools/theme.ps1
@@ -1,5 +1,5 @@
-# Windows version of theme.sh: push a theme folder (config.json and optionally wallpaper.jpg) to the
-# launcher on the TV and restart Home. See themes/README.md for the keys.
+# Windows version of theme.sh: push a theme folder (config.json, and optionally a wallpaper.jpg or a
+# wallpapers/ collection) to the launcher on the TV and restart Home. See themes/README.md for the keys.
#
# Usage: tools\theme.ps1 -TvHost 192.168.1.50 themes\aurora
# tools\theme.ps1 -TvHost 192.168.1.50 -Reset
@@ -49,8 +49,14 @@ function Stage($name) { "$tmp-$($name -replace '/', '-')" }
function Put($name) { $t = Stage $name; "rm -f $dir/$name 2>/dev/null; { o=`$(content write --uri $uri/$name < $t 2>&1) && case `"`$o`" in *'Unsupported operation'*) false ;; esac; } || cp $t $dir/$name 2>/dev/null; rm -f $t" }
function Drop($name) { "rm -f $dir/$name 2>/dev/null; content delete --uri $uri/$name 2>/dev/null" }
+# The collection a theme can push. A push empties it before writing the theme's own pictures, and -Reset has to
+# empty it too: the launcher's wallpaper picker lists that folder itself, and an on-TV pick of one of its
+# pictures is read back from it, so a reset that left the pictures behind still shows the theme it just removed.
+# Both paths use this one string (the same one theme.sh has).
+$clearWallpapers = "mkdir -p $dir/wallpapers 2>/dev/null; rm -f $dir/wallpapers/*.jpg $dir/wallpapers/*.jpeg $dir/wallpapers/*.png $dir/wallpapers/*.webp $dir/wallpapers/*.JPG $dir/wallpapers/*.JPEG $dir/wallpapers/*.PNG $dir/wallpapers/*.WEBP 2>/dev/null; content delete --uri $uri/wallpapers 2>/dev/null"
+
if ($Reset) {
- & $py -I tv.py "mkdir -p $dir 2>/dev/null; $(Drop 'config.json'); $(Drop 'wallpaper.jpg'); printf '%s' '$revision' > $tmp-theme_revision; $(Put 'theme_revision'); $restart; echo reset"
+ & $py -I tv.py "mkdir -p $dir 2>/dev/null; $(Drop 'config.json'); $(Drop 'wallpaper.jpg'); $(Drop 'wallpapers/captions.txt'); $clearWallpapers; printf '%s' '$revision' > $tmp-theme_revision; $(Put 'theme_revision'); $restart; echo reset"
exit 0
}
if (-not $Theme) { throw 'usage: theme.ps1 <theme folder> | -Reset' }
@@ -63,7 +69,7 @@ try { Get-Content $config -Raw | ConvertFrom-Json | Out-Null } catch { throw "$c
& $py -I tv.py (Put 'config.json')
$wall = Join-Path $Theme 'wallpaper.jpg'
if (Test-Path $wall) { & $py -I b64push.py $wall "$tmp-wallpaper.jpg"; & $py -I tv.py (Put 'wallpaper.jpg') } else { & $py -I tv.py (Drop 'wallpaper.jpg') | Out-Null }
-& $py -I tv.py "mkdir -p $dir/wallpapers 2>/dev/null; rm -f $dir/wallpapers/*.jpg $dir/wallpapers/*.jpeg $dir/wallpapers/*.png $dir/wallpapers/*.webp $dir/wallpapers/*.JPG $dir/wallpapers/*.JPEG $dir/wallpapers/*.PNG $dir/wallpapers/*.WEBP 2>/dev/null; content delete --uri $uri/wallpapers 2>/dev/null" | Out-Null
+& $py -I tv.py $clearWallpapers | Out-Null
$wallpapers = Join-Path $Theme 'wallpapers'
if (Test-Path $wallpapers -PathType Container) {
Get-ChildItem $wallpapers -File | Where-Object { $_.Extension -match '^\.(jpg|jpeg|png|webp)$' } | ForEach-Object {
diff --git a/tools/theme.sh b/tools/theme.sh
index ddd4fdd6d..96b7f22eb 100755
--- a/tools/theme.sh
+++ b/tools/theme.sh
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
-# Push a theme (a folder with config.json and optionally wallpaper.jpg) to the launcher on the TV and
-# restart Home so it picks it up. The launcher reads the files from its external files directory and
-# overlays config.json on its built-in config.xml; see themes/README.md for the keys.
+# Push a theme (a folder with config.json, and optionally a wallpaper.jpg or a wallpapers/ collection) to the
+# launcher on the TV and restart Home so it picks it up. The launcher reads the files from its external files
+# directory and overlays config.json on its built-in config.xml; see themes/README.md for the keys.
#
# Usage: TV_HOST=192.168.1.50 tools/theme.sh themes/aurora
# TV_HOST=192.168.1.50 tools/theme.sh --reset # remove the overlay, back to config.xml
@@ -60,8 +60,14 @@ stage() { echo "$TMP-${1//\//-}"; }
put() { echo "rm -f $DIR/$1 2>/dev/null; { o=\$(content write --uri $URI/$1 < $(stage "$1") 2>&1) && case \"\$o\" in *'Unsupported operation'*) false ;; esac; } || cp $(stage "$1") $DIR/$1 2>/dev/null; rm -f $(stage "$1")"; }
del() { echo "rm -f $DIR/$1 2>/dev/null; content delete --uri $URI/$1 2>/dev/null"; }
+# The collection a theme can push. A push empties it before writing the theme's own pictures, and --reset has to
+# empty it too: the launcher's wallpaper picker (LauncherSettingsActivity.showWallpaperPicker) lists that folder
+# itself, and an on-TV pick of one of its pictures is read back from it (WallpaperRotation.chosen), so a reset
+# that left the pictures behind still shows the theme it just removed. Both paths use this one string.
+CLEAR_WALLPAPERS="mkdir -p $DIR/wallpapers 2>/dev/null; rm -f $DIR/wallpapers/*.jpg $DIR/wallpapers/*.jpeg $DIR/wallpapers/*.png $DIR/wallpapers/*.webp $DIR/wallpapers/*.JPG $DIR/wallpapers/*.JPEG $DIR/wallpapers/*.PNG $DIR/wallpapers/*.WEBP 2>/dev/null; content delete --uri $URI/wallpapers 2>/dev/null"
+
if [ "${1:-}" = --reset ]; then
- tv "mkdir -p $DIR 2>/dev/null; $(del config.json); $(del wallpaper.jpg); printf '%s' '$REVISION' > $TMP-theme_revision; $(put theme_revision); $RESTART; echo reset" | tail -n 1
+ tv "mkdir -p $DIR 2>/dev/null; $(del config.json); $(del wallpaper.jpg); $(del wallpapers/captions.txt); $CLEAR_WALLPAPERS; printf '%s' '$REVISION' > $TMP-theme_revision; $(put theme_revision); $RESTART; echo reset" | tail -n 1
exit 0
fi
THEME="${THEME_ARG:?usage: theme.sh <theme folder> | --reset}"
@@ -78,7 +84,7 @@ if [ -f "$THEME/wallpaper.jpg" ]; then
else
tv "$(del wallpaper.jpg)" >/dev/null
fi
-tv "mkdir -p $DIR/wallpapers 2>/dev/null; rm -f $DIR/wallpapers/*.jpg $DIR/wallpapers/*.jpeg $DIR/wallpapers/*.png $DIR/wallpapers/*.webp $DIR/wallpapers/*.JPG $DIR/wallpapers/*.JPEG $DIR/wallpapers/*.PNG $DIR/wallpapers/*.WEBP 2>/dev/null; content delete --uri $URI/wallpapers 2>/dev/null" >/dev/null
+tv "$CLEAR_WALLPAPERS" >/dev/null
if [ -d "$THEME/wallpapers" ]; then
for IMAGE in "$THEME"/wallpapers/*; do
[ -f "$IMAGE" ] || continue