Skip to content

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

tools: handle mixed-case wallpaper extensions

SlivenRedac9fc3e69b7c
diff --git a/tests/test_theme_push_ownership.py b/tests/test_theme_push_ownership.py
index 7a68e4510..0a6c33e83 100644
--- a/tests/test_theme_push_ownership.py
+++ b/tests/test_theme_push_ownership.py
@@ -210,6 +210,67 @@ class ThemePushTest(unittest.TestCase):
put = self.command_for(name)
self.assertLess(put.index("content write"), put.index("cp "), put)
+ def test_collection_image_extensions_are_case_insensitive(self):
+ collection = self.theme / "wallpapers"
+ collection.mkdir()
+ extensions = ("jpg", "JPG", "JpG", "jpeg", "JPEG", "JpEg",
+ "png", "PNG", "PnG", "webp", "WEBP", "WeBp")
+ images = {f"image-{index}.{extension}": b"\x00\xffimage bytes " + extension.encode()
+ for index, extension in enumerate(extensions)}
+ for name, data in images.items():
+ (collection / name).write_bytes(data)
+ for name in ("notes.txt", "animation.gif", "image.avif", "backup.jpg.txt"):
+ (collection / name).write_bytes(b"not a collection image")
+ previous = self.device / "wallpapers"
+ previous.mkdir()
+ (previous / "old.jpg").write_bytes(b"old collection")
+
+ result = self.run_theme(str(self.theme))
+ self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
+ self.assertEqual(sorted(path.name for path in previous.iterdir()), sorted(images),
+ "the collection must contain every supported image and no unsupported files")
+ for name, data in images.items():
+ with self.subTest(name=name):
+ self.assertEqual((previous / name).read_bytes(), data)
+ self.assertIn(["write", "--uri", f"content://com.gathin.tvhome.theme/wallpapers/{name}"],
+ self.provider_calls())
+
+ def test_mixed_case_image_extension_still_checks_the_filename(self):
+ collection = self.theme / "wallpapers"
+ collection.mkdir()
+ (collection / "bad name.JpG").write_bytes(b"image bytes")
+
+ result = self.run_theme(str(self.theme))
+ self.assertNotEqual(result.returncode, 0, result.stdout + result.stderr)
+ self.assertIn("unsupported wallpaper filename: bad name.JpG", result.stderr)
+ self.assertFalse((self.device / "wallpapers" / "bad name.JpG").exists())
+
+ def test_mixed_case_collection_is_replaced_and_reset_without_the_provider(self):
+ collection = self.theme / "wallpapers"
+ collection.mkdir()
+ first = collection / "previous.JpG"
+ first.write_bytes(b"\x00\xfffirst picture")
+
+ pushed = self.run_theme(str(self.theme), FAKE_NO_PROVIDER="1")
+ self.assertEqual(pushed.returncode, 0, pushed.stdout + pushed.stderr)
+ device_collection = self.device / "wallpapers"
+ self.assertEqual(sorted(path.name for path in device_collection.iterdir()), [first.name])
+ self.assertEqual((device_collection / first.name).read_bytes(), first.read_bytes())
+
+ first.unlink()
+ second = collection / "next.PnG"
+ second.write_bytes(b"\x00\xffsecond picture")
+ replaced = self.run_theme(str(self.theme), FAKE_NO_PROVIDER="1")
+ self.assertEqual(replaced.returncode, 0, replaced.stdout + replaced.stderr)
+ self.assertEqual(sorted(path.name for path in device_collection.iterdir()), [second.name],
+ "without the provider, the shell must still remove the previous collection")
+ self.assertEqual((device_collection / second.name).read_bytes(), second.read_bytes())
+
+ reset = self.run_theme("--reset", FAKE_NO_PROVIDER="1")
+ self.assertEqual(reset.returncode, 0, reset.stdout + reset.stderr)
+ self.assertEqual(list(device_collection.iterdir()), [],
+ "reset must remove mixed-case images even without the provider")
+
def test_the_windows_script_puts_files_the_same_way(self):
"""theme.ps1 cannot run here, so pin the order that the fix depends on."""
script = (TOOLS / "theme.ps1").read_text(encoding="utf-8")
@@ -251,8 +312,9 @@ class ThemePushTest(unittest.TestCase):
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")
+ self.assertIn(f"{DEVICE_DIR}/wallpapers/*.[jJ][pP][gG]", clear[0])
+ self.assertIn(f"{DEVICE_DIR}/wallpapers/*.[wW][eE][bB][pP]", clear[0],
+ "the shell fallback clears every extension spelling the script pushes")
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")
diff --git a/tools/theme.sh b/tools/theme.sh
index 96b7f22eb..8fc50e517 100755
--- a/tools/theme.sh
+++ b/tools/theme.sh
@@ -64,7 +64,7 @@ del() { echo "rm -f $DIR/$1 2>/dev/null; content delete --uri $URI/$1 2>/dev/nul
# 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"
+CLEAR_WALLPAPERS="mkdir -p $DIR/wallpapers 2>/dev/null; rm -f $DIR/wallpapers/*.[jJ][pP][gG] $DIR/wallpapers/*.[jJ][pP][eE][gG] $DIR/wallpapers/*.[pP][nN][gG] $DIR/wallpapers/*.[wW][eE][bB][pP] 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); $(del wallpapers/captions.txt); $CLEAR_WALLPAPERS; printf '%s' '$REVISION' > $TMP-theme_revision; $(put theme_revision); $RESTART; echo reset" | tail -n 1
@@ -89,7 +89,7 @@ if [ -d "$THEME/wallpapers" ]; then
for IMAGE in "$THEME"/wallpapers/*; do
[ -f "$IMAGE" ] || continue
case "$IMAGE" in
- *.jpg|*.jpeg|*.png|*.webp|*.JPG|*.JPEG|*.PNG|*.WEBP)
+ *.[jJ][pP][gG]|*.[jJ][pP][eE][gG]|*.[pP][nN][gG]|*.[wW][eE][bB][pP])
NAME=$(basename "$IMAGE")
[[ "$NAME" =~ ^[A-Za-z0-9_.-]+$ ]] || { echo "unsupported wallpaper filename: $NAME" >&2; exit 1; }
"$PY" -I b64push.py "$IMAGE" "$(stage "wallpapers/$NAME")"