Skip to content

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

theme.sh: fall back to cp on Android 8 and 9, whose content has no write

Riku Pirttinokkacb195fa9dfca
diff --git a/tests/test_theme_push_ownership.py b/tests/test_theme_push_ownership.py
index 26f34412b..935b8e7b4 100644
--- a/tests/test_theme_push_ownership.py
+++ b/tests/test_theme_push_ownership.py
@@ -81,6 +81,11 @@ with open(os.environ["FAKE_CONTENT_LOG"], "a") as f:
f.write(json.dumps({"content": args}) + "\n")
if os.environ.get("FAKE_NO_PROVIDER"):
sys.exit(1)
+if os.environ.get("FAKE_NO_CONTENT_WRITE") and args[0] == "write":
+ # Android 8 and 9: `content` has no write subcommand; it prints its usage and this line, and exits 0.
+ print("usage: adb shell content [subcommand] [options]")
+ print("[ERROR] Unsupported operation: write")
+ 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":
@@ -170,6 +175,16 @@ class ThemePushTest(unittest.TestCase):
"firmware without the provider keeps the old path")
self.assertTrue(self.provider_calls(), "the provider is tried first")
+ def test_android_8_without_content_write_falls_back_to_cp(self):
+ """Android 8/9 `content` has no write: it exits 0 after printing an error, so the status alone is not enough."""
+ (self.theme / "wallpaper.jpg").write_bytes(b"\xff\xd8jpeg bytes")
+ result = self.run_theme(str(self.theme), FAKE_NO_CONTENT_WRITE="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 / "theme_revision").stat().st_size, 32)
+
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")
@@ -202,6 +217,7 @@ class ThemePushTest(unittest.TestCase):
self.assertIn("rm -f $dir/$name", put)
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")
if __name__ == "__main__":
diff --git a/tools/theme.ps1 b/tools/theme.ps1
index 8f79c5a04..d91790615 100644
--- a/tools/theme.ps1
+++ b/tools/theme.ps1
@@ -41,7 +41,9 @@ $uri = "content://$pkg.theme"
$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 '/', '-')" }
-function Put($name) { $t = Stage $name; "rm -f $dir/$name 2>/dev/null; content write --uri $uri/$name < $t 2>/dev/null || cp $t $dir/$name 2>/dev/null; rm -f $t" }
+# 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" }
function Drop($name) { "rm -f $dir/$name 2>/dev/null; content delete --uri $uri/$name 2>/dev/null" }
if ($Reset) {
diff --git a/tools/theme.sh b/tools/theme.sh
index 7a75a7023..ddd4fdd6d 100755
--- a/tools/theme.sh
+++ b/tools/theme.sh
@@ -55,7 +55,9 @@ URI=content://$PKG.theme
TMP=/data/local/tmp/cyt-theme
# A file's staging path; wallpapers/a.jpg is staged as $TMP-wallpapers-a.jpg.
stage() { echo "$TMP-${1//\//-}"; }
-put() { echo "rm -f $DIR/$1 2>/dev/null; content write --uri $URI/$1 < $(stage "$1") 2>/dev/null || cp $(stage "$1") $DIR/$1 2>/dev/null; rm -f $(stage "$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")"; }
del() { echo "rm -f $DIR/$1 2>/dev/null; content delete --uri $URI/$1 2>/dev/null"; }
if [ "${1:-}" = --reset ]; then