Skip to content

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

tools: theme.sh leaves wallpapers/ to the launcher, so pictures land on a fresh install

TheeCoderAhmeddb5eb919e50b
diff --git a/docs/TROUBLESHOOTING.md b/docs/TROUBLESHOOTING.md
index dc4fcaa18..11159ea43 100644
--- a/docs/TROUBLESHOOTING.md
+++ b/docs/TROUBLESHOOTING.md
@@ -768,7 +768,12 @@ Things that bit us or contributors, so they don't bite you. Commands use `tools/
themed before and did nothing on a fresh install or right after a reinstall. `theme.sh` now removes the
shell's copy and writes through the `ThemeProvider` first (the provider cannot truncate a file the shell
owns); on an older checkout, pushing the theme again after `launcher/build-and-install.sh` has written
- the files once also fixes the ownership.
+ the files once also fixes the ownership. The `wallpapers/` folder went the same way, seen on a Vestel
+ BODRUM (Android 14, `UKNV.260428.001`): `theme.sh` made it with `mkdir`, so it belonged to the shell
+ (`drwxrws--- shell ext_data_rw`) and the provider got EACCES writing the pictures into it, while the
+ config still landed. `theme.sh` now leaves that folder to the provider. A set that already has one from an
+ older checkout needs it removed once (it is empty), then push the theme again:
+ `tools/tv.py 'rmdir /sdcard/Android/data/com.gathin.tvhome/files/wallpapers'`.
- **Google TV comes back after a few remote presses**, seen on XGIMI (MoGo 3 Pro, Google TV 14). The
remote's app buttons (YouTube, Netflix, Prime Video), the programmable button, the profile button and power
all send F keys that the system hands to `com.xgimi.xrmservice/.XgimiGlobalKeyBroadcast` as global keys
diff --git a/tests/test_theme_push_ownership.py b/tests/test_theme_push_ownership.py
index 313d32b9d..6aef065db 100644
--- a/tests/test_theme_push_ownership.py
+++ b/tests/test_theme_push_ownership.py
@@ -70,7 +70,10 @@ else:
# Stands in for `content write/delete` against content://com.gathin.tvhome.theme, which on a TV runs inside
# the launcher's process and so creates files owned by the launcher. FAKE_NO_PROVIDER models firmware or a
-# launcher version without the provider.
+# launcher version without the provider. A real `content` reports an exception from the provider as text ("Error
+# while accessing provider" and a stack trace): FAKE_PROVIDER_ERROR is a provider that is not there, and a write
+# into a folder the shell created fails the same way, because the launcher gets EACCES in a folder that is the
+# shell's. Both stubs exit 0, like the Android 8 one, so the status alone cannot tell them from a write.
FAKE_CONTENT = r'''#!/usr/bin/env python3
import json
import os
@@ -86,9 +89,18 @@ if os.environ.get("FAKE_NO_CONTENT_WRITE") and args[0] == "write":
print("usage: adb shell content [subcommand] [options]")
print("[ERROR] Unsupported operation: write")
sys.exit(0)
+if os.environ.get("FAKE_PROVIDER_ERROR"):
+ print("Error while accessing provider:com.gathin.tvhome.theme")
+ print("java.lang.IllegalStateException: Could not find provider: com.gathin.tvhome.theme")
+ sys.exit(0)
action, uri = args[0], args[args.index("--uri") + 1]
path = os.path.join(os.environ["FAKE_DIR"], uri.split("com.gathin.tvhome.theme/", 1)[1])
if action == "write":
+ shell_dirs = os.environ["FAKE_SHELL_DIRS"]
+ if os.path.exists(shell_dirs) and os.path.dirname(path) in open(shell_dirs).read().splitlines():
+ print("Error while accessing provider:com.gathin.tvhome.theme")
+ print("java.io.FileNotFoundException: open failed: EACCES (Permission denied)")
+ sys.exit(0)
os.makedirs(os.path.dirname(path), exist_ok=True)
with open(path, "wb") as f:
f.write(sys.stdin.buffer.read())
@@ -119,6 +131,15 @@ class ThemePushTest(unittest.TestCase):
content = self.bin / "content"
content.write_text(FAKE_CONTENT)
content.chmod(0o755)
+ # A folder `mkdir` makes in the adb shell belongs to the shell (drwxrws--- shell ext_data_rw): list it, and
+ # the stub provider refuses to write into it, as the launcher does on a TV.
+ mkdir = self.bin / "mkdir"
+ mkdir.write_text('#!/bin/sh\n[ "$1" = -p ] && shift\n'
+ 'for dir in "$@"; do\n'
+ ' [ -d "$dir" ] || echo "$dir" >> "$FAKE_SHELL_DIRS"\n'
+ ' /bin/mkdir -p "$dir"\n'
+ 'done\n')
+ mkdir.chmod(0o755)
# The recovery helper runs real shell status checks. Model framework reads
# and starts too, while keeping this fixture focused on provider ownership.
for name, body in {
@@ -134,6 +155,7 @@ class ThemePushTest(unittest.TestCase):
self.stage = self.base / "stage"
self.log = self.base / "log.jsonl"
self.content_log = self.base / "content.jsonl"
+ self.shell_dirs = self.base / "shell-dirs.txt"
self.theme = self.base / "aurora"
self.theme.mkdir()
self.config = json.dumps({"background": "#101418", "app_keys": []}, indent=2).encode()
@@ -145,6 +167,7 @@ class ThemePushTest(unittest.TestCase):
full = {k: v for k, v in os.environ.items() if k != "TV_HOST"}
full.update({"TV_HOST": "192.0.2.10", "FAKE_LOG": str(self.log), "FAKE_DIR": str(self.device),
"FAKE_STAGE": str(self.stage), "FAKE_CONTENT_LOG": str(self.content_log),
+ "FAKE_SHELL_DIRS": str(self.shell_dirs),
"PATH": f"{self.bin}:{full.get('PATH', '')}"}, **env)
return subprocess.run(["bash", str(self.tools / "theme.sh"), *args], env=full,
capture_output=True, text=True, timeout=300)
@@ -159,6 +182,11 @@ class ThemePushTest(unittest.TestCase):
return []
return [json.loads(line)["content"] for line in self.content_log.read_text().splitlines()]
+ def shell_created_dirs(self):
+ if not self.shell_dirs.exists():
+ return []
+ return self.shell_dirs.read_text().splitlines()
+
def command_for(self, name):
"""The one device command that puts `name` on the TV, in every shape theme.sh uses it."""
matches = [c for c in self.shell_commands() if f"{DEVICE_DIR}/{name}" in c and "content write" in c]
@@ -197,6 +225,38 @@ class ThemePushTest(unittest.TestCase):
self.assertEqual((self.device / "wallpaper.jpg").read_bytes(), b"\xff\xd8jpeg bytes")
self.assertEqual((self.device / "theme_revision").stat().st_size, 32)
+ def test_a_fresh_install_gets_its_wallpapers_folder_from_the_provider(self):
+ """A folder the shell makes is the shell's, so the launcher's provider fails with EACCES writing into it."""
+ (self.theme / "wallpapers").mkdir()
+ (self.theme / "wallpapers" / "dusk.jpg").write_bytes(b"\xff\xd8dusk")
+ result = self.run_theme(str(self.theme))
+ self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
+ self.assertNotIn(str(self.device / "wallpapers"), self.shell_created_dirs(),
+ "the provider creates wallpapers/ as the launcher; mkdir leaves it to the shell")
+ self.assertEqual((self.device / "wallpapers" / "dusk.jpg").read_bytes(), b"\xff\xd8dusk",
+ "the picture has to land on the TV, not only be reported as applied")
+ self.assertIn(["write", "--uri", "content://com.gathin.tvhome.theme/wallpapers/dusk.jpg"],
+ self.provider_calls())
+
+ def test_a_reset_does_not_leave_a_shell_owned_wallpapers_folder_behind(self):
+ """The next push would hit the same EACCES: --reset on a fresh install ran the same mkdir."""
+ result = self.run_theme("--reset")
+ self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
+ self.assertNotIn(str(self.device / "wallpapers"), self.shell_created_dirs())
+
+ def test_a_provider_error_is_a_failed_write_so_cp_runs(self):
+ """"Error while accessing provider" is text from `content`, so like Unsupported operation it needs a check."""
+ (self.theme / "wallpaper.jpg").write_bytes(b"\xff\xd8jpeg bytes")
+ (self.theme / "wallpapers").mkdir()
+ (self.theme / "wallpapers" / "dusk.jpg").write_bytes(b"\xff\xd8dusk")
+ result = self.run_theme(str(self.theme), FAKE_PROVIDER_ERROR="1")
+ self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
+ self.assertEqual((self.device / "config.json").read_bytes(), self.config,
+ "put() removes the file first, so without cp the theme would be gone")
+ self.assertEqual((self.device / "wallpaper.jpg").read_bytes(), b"\xff\xd8jpeg bytes")
+ self.assertEqual((self.device / "wallpapers" / "dusk.jpg").read_bytes(), b"\xff\xd8dusk",
+ "the fallback makes the collection's folder itself, now that the clear no longer does")
+
def test_reset_clears_the_overlay_through_the_provider(self):
(self.device / "config.json").write_bytes(self.config)
(self.device / "wallpaper.jpg").write_bytes(b"old wallpaper")
@@ -307,6 +367,10 @@ class ThemePushTest(unittest.TestCase):
self.assertLess(put.index("rm -f $dir/$name"), put.index("content write"), put)
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")
+ self.assertIn("Error while accessing provider", put, "so does a provider that throws, as in theme.sh")
+ self.assertLess(put.index("mkdir -p"), put.index("cp $t $dir/$name"), "cp needs the folder: " + put)
+ clear = next(line for line in script.splitlines() if line.startswith("$clearWallpapers = "))
+ self.assertNotIn("mkdir", clear, "a folder the shell makes is one the launcher cannot write into")
def test_reset_clears_the_wallpaper_collection(self):
"""--reset promises the built-in config.xml, but the picker reads wallpapers/ from the TV itself."""
diff --git a/tools/theme.ps1 b/tools/theme.ps1
index 6b8877aa4..703e6961d 100644
--- a/tools/theme.ps1
+++ b/tools/theme.ps1
@@ -53,15 +53,19 @@ $tmp = '/data/local/tmp/cyt-theme'
# A file's staging path; wallpapers/a.jpg is staged as $tmp-wallpapers-a.jpg.
function Stage($name) { "$tmp-$($name -replace '/', '-')" }
# Android 8 and 9 have no `content write`: they print "[ERROR] Unsupported operation: write" but exit 0, so
-# that message counts as a failure and cp runs.
-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" }
+# that message counts as a failure and cp runs. So does "Error while accessing provider", which `content` prints
+# when the launcher has no provider or gets EACCES.
+# A folder the shell makes is the shell's (drwxrws--- shell ext_data_rw), and the provider, which runs as the
+# launcher, then gets EACCES writing into it. Nothing makes wallpapers/ up front: the provider creates it with the
+# first picture, and only the cp fallback, where the shell does the writing, runs mkdir.
+function Put($name) { $t = Stage $name; $d = "$dir/$name" -replace '/[^/]*$', ''; "rm -f $dir/$name 2>/dev/null; { o=`$(content write --uri $uri/$name < $t 2>&1) && case `"`$o`" in *'Unsupported operation'*|*'Error while accessing provider'*) false ;; esac; } || { mkdir -p $d 2>/dev/null; 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/*.[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"
+$clearWallpapers = "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 ($Reset) {
Invoke-Tv 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')" | Out-Null
diff --git a/tools/theme.sh b/tools/theme.sh
index 1db38a240..f20ef82fe 100755
--- a/tools/theme.sh
+++ b/tools/theme.sh
@@ -67,14 +67,19 @@ TMP=/data/local/tmp/cyt-theme
stage() { echo "$TMP-${1//\//-}"; }
# Android 8 and 9 have no `content write`: they print the usage and "[ERROR] Unsupported operation: write" but
# exit 0, so the exit status alone would skip cp and leave the file deleted. Treat that message as a failure.
-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")"; }
+# `content` also reports an exception from the provider as text - no provider in the launcher, or the launcher
+# getting EACCES - so "Error while accessing provider" is a failure too, and cp runs instead of the file going.
+# A folder is the shell's when the shell makes it (drwxrws--- shell ext_data_rw), and the provider, which runs as the
+# launcher, then gets EACCES writing into it. Nothing makes wallpapers/ up front: the provider creates it with the
+# first picture, and only the cp fallback, where the shell does the writing, runs mkdir.
+put() { echo "rm -f $DIR/$1 2>/dev/null; { o=\$(content write --uri $URI/$1 < $(stage "$1") 2>&1) && case \"\$o\" in *'Unsupported operation'*|*'Error while accessing provider'*) false ;; esac; } || { mkdir -p $(dirname "$DIR/$1") 2>/dev/null; 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/*.[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"
+CLEAR_WALLPAPERS="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)" >/dev/null