Skip to content

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

examples: three Undo lines and a Skyworth page hand restore.sh the stock launcher as its second argument

Mazin Kanuga86656331d4b0
diff --git a/examples/caxium-58-realtek-rtk2851p/debloat.txt b/examples/caxium-58-realtek-rtk2851p/debloat.txt
index 52e45c302..ba1591efd 100644
--- a/examples/caxium-58-realtek-rtk2851p/debloat.txt
+++ b/examples/caxium-58-realtek-rtk2851p/debloat.txt
@@ -2,7 +2,7 @@
# build RTK2851P (Realtek/RealtekATV/RealtekATV:9/RTK2851P, userdebug), 1.5 GB RAM.
#
# Apply: TV_HOST=<tv ip> tools/disable.sh examples/caxium-58-realtek-rtk2851p/debloat.txt
-# Undo: TV_HOST=<tv ip> tools/restore.sh examples/caxium-58-realtek-rtk2851p/debloat.txt
+# Undo: TV_HOST=<tv ip> tools/restore.sh examples/caxium-58-realtek-rtk2851p/debloat.txt cn.zeasn.launcher.vstoresubclient.toptech
# Everything is DISABLED, not uninstalled. Comment out any line you want to keep.
#
# Stock launcher is cn.zeasn.launcher.vstoresubclient.toptech (Zeasn). It is not in this list: disable it only
diff --git a/examples/skyworth-7s60-a5/debloat.txt b/examples/skyworth-7s60-a5/debloat.txt
index f5129bdb7..ce620ac18 100644
--- a/examples/skyworth-7s60-a5/debloat.txt
+++ b/examples/skyworth-7s60-a5/debloat.txt
@@ -4,7 +4,7 @@
# com.ccos.cooui.movieplatform.ElderMainActivity). TV/inputs: com.skyworth.tv.
#
# Apply: TV_HOST=<tv ip> tools/disable.sh examples/skyworth-7s60-a5/debloat.txt
-# Undo: TV_HOST=<tv ip> tools/restore.sh examples/skyworth-7s60-a5/debloat.txt
+# Undo: TV_HOST=<tv ip> tools/restore.sh examples/skyworth-7s60-a5/debloat.txt com.tianci.movieplatform
# Everything is DISABLED, not uninstalled. Comment out any line you want to keep.
#
# Disabled before this debloat, so not listed (restore.sh would turn them ON):
diff --git a/examples/skyworth-swtv-22ae-fhd/README.md b/examples/skyworth-swtv-22ae-fhd/README.md
index 51434244a..bb1bf3b64 100644
--- a/examples/skyworth-swtv-22ae-fhd/README.md
+++ b/examples/skyworth-swtv-22ae-fhd/README.md
@@ -18,7 +18,7 @@ comment out what your set does not have before applying it.
## Stock launcher
- **Launcher:** `com.google.android.apps.tv.launcherx` (`.home.HomeActivity`)
-- When restoring or building/installing, pass `STOCK_LAUNCHER=com.google.android.apps.tv.launcherx`.
+- When restoring, pass it to `tools/restore.sh` as the second argument; when building/installing, pass `STOCK_LAUNCHER=com.google.android.apps.tv.launcherx` to `launcher/build-and-install.sh`.
## Live TV
- **Live TV app/package:** `com.mediatek.wwtv.tvcenter`
diff --git a/examples/tcl-65q550g/debloat.txt b/examples/tcl-65q550g/debloat.txt
index 66c7cc3d6..d09cea98f 100644
--- a/examples/tcl-65q550g/debloat.txt
+++ b/examples/tcl-65q550g/debloat.txt
@@ -1,7 +1,7 @@
# TCL 65Q550G (TCL BeyondTV4, codename UNKNOWN), Google TV 11, firmware V8-R51MT08-LF1V095.021344
#
# Apply: TV_HOST=<tv ip> tools/disable.sh examples/tcl-65q550g/debloat.txt
-# Undo: TV_HOST=<tv ip> tools/restore.sh examples/tcl-65q550g/debloat.txt
+# Undo: TV_HOST=<tv ip> tools/restore.sh examples/tcl-65q550g/debloat.txt com.google.android.apps.tv.launcherx
# Everything is DISABLED, not uninstalled. Comment out any line you want to keep.
#
# Tested on one unit over Ethernet: setupwraith owned saved Wi-Fi networks and claimed HOME;
diff --git a/tests/test_folder_undo_agrees.py b/tests/test_folder_undo_agrees.py
new file mode 100644
index 000000000..52a7c20ed
--- /dev/null
+++ b/tests/test_folder_undo_agrees.py
@@ -0,0 +1,101 @@
+"""A list's Undo line and its folder README's restore command hand restore.sh the same stock launcher.
+
+`tools/restore.sh <list> [stock launcher]` enables the package it is given, or
+`com.google.android.tvlauncher` when it is given none (see tests/test_stock_launcher_undo.py). An owner
+copies whichever undo they find first: the list header, or the README in the same folder. When the two
+pass different packages, one of them leaves the stock home disabled. The Skyworth 7S60_A5 README
+passes com.tianci.movieplatform, the Coocaa home it tells the owner to disable, while the list's own
+Undo line passed nothing.
+
+Only restore commands for the folder's own list are compared, in the bash and PowerShell forms.
+
+Run from the repository root: python3 -m unittest discover -s tests -v
+"""
+import re
+import tempfile
+import unittest
+from pathlib import Path
+
+
+ROOT = Path(__file__).resolve().parents[1]
+
+DEFAULT_STOCK = "com.google.android.tvlauncher"
+PACKAGE = r"[A-Za-z_][A-Za-z0-9_]*(?:\.[A-Za-z0-9_]+)+"
+# `restore.sh examples/x/debloat.txt [package]`, `restore.ps1 examples\x\debloat.txt [-Stock package]`,
+# with the list and the package as a page may quote them.
+COMMAND = re.compile(
+ r"restore\.(?:sh|ps1)\s+[\"'`]?([A-Za-z0-9_./\\-]+\.txt)[\"'`]?"
+ r"(?:\s+(?:-Stock\s+)?[\"'`]?(" + PACKAGE + r"))?")
+
+
+def passed(text, own):
+ """The stock launchers the restore commands for list `own` hand restore.sh, the default included."""
+ found = set()
+ for line in text.splitlines():
+ for name, stock in COMMAND.findall(line):
+ if name.replace("\\", "/") == own:
+ found.add(stock or DEFAULT_STOCK)
+ return found
+
+
+def disagreements(root):
+ """How many folders were compared, and one sentence for each whose list and README disagree."""
+ compared = 0
+ wrong = []
+ for readme in sorted((root / "examples").glob("*/README.md")):
+ own = f"examples/{readme.parent.name}/debloat.txt"
+ if not (root / own).is_file():
+ continue
+ in_list = passed((root / own).read_text(encoding="utf-8"), own)
+ in_readme = passed(readme.read_text(encoding="utf-8"), own)
+ if not (in_list and in_readme):
+ continue
+ compared += 1
+ if in_list != in_readme:
+ wrong.append(f"{own}: its Undo passes {', '.join(sorted(in_list))}, "
+ f"its README.md passes {', '.join(sorted(in_readme))}")
+ return compared, wrong
+
+
+class FolderUndoAgreesTest(unittest.TestCase):
+ def test_list_and_readme_pass_the_same_stock_launcher(self):
+ compared, wrong = disagreements(ROOT)
+ self.assertGreaterEqual(compared, 20, "the sweep compared too few folders to be meaningful")
+ self.assertEqual([], wrong, "\n".join(wrong))
+
+ def test_no_package_means_the_default(self):
+ own = "examples/x/debloat.txt"
+ self.assertEqual({DEFAULT_STOCK}, passed("# Undo: tools/restore.sh examples/x/debloat.txt\n", own))
+ self.assertEqual({"com.tianci.movieplatform"},
+ passed("tools/restore.sh examples/x/debloat.txt com.tianci.movieplatform\n", own))
+
+ def test_the_powershell_form_is_read(self):
+ own = "examples/x/debloat.txt"
+ line = "tools\\restore.ps1 examples\\x\\debloat.txt -Stock com.google.android.apps.tv.launcherx\n"
+ self.assertEqual({"com.google.android.apps.tv.launcherx"}, passed(line, own))
+
+ def test_a_folder_that_disagrees_is_reported(self):
+ with tempfile.TemporaryDirectory() as tmp:
+ root = Path(tmp)
+ folder = root / "examples" / "x"
+ folder.mkdir(parents=True)
+ (folder / "debloat.txt").write_text(
+ "# Undo: TV_HOST=<tv ip> tools/restore.sh examples/x/debloat.txt\n", encoding="utf-8")
+ (folder / "README.md").write_text(
+ "tools/restore.sh examples/x/debloat.txt com.tianci.movieplatform\n", encoding="utf-8")
+ compared, wrong = disagreements(root)
+ self.assertEqual(1, compared)
+ self.assertEqual(["examples/x/debloat.txt: its Undo passes com.google.android.tvlauncher, "
+ "its README.md passes com.tianci.movieplatform"], wrong)
+ (folder / "debloat.txt").write_text(
+ "# Undo: TV_HOST=<tv ip> tools/restore.sh examples/x/debloat.txt com.tianci.movieplatform\n",
+ encoding="utf-8")
+ self.assertEqual((1, []), disagreements(root))
+
+ def test_another_lists_restore_is_not_compared(self):
+ self.assertEqual(set(), passed("tools/restore.sh examples/y/debloat.txt com.example.home\n",
+ "examples/x/debloat.txt"))
+
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/tests/test_restore_references.py b/tests/test_restore_references.py
index 4229095d6..87a7289d2 100644
--- a/tests/test_restore_references.py
+++ b/tests/test_restore_references.py
@@ -15,6 +15,11 @@ list as its first argument and the stock launcher as its second, so the CVTE T97
`tools/restore.sh ... com.cvte.tv.launcher.highend` was refused before a single package came back,
which the reference pattern above never read because there was no `.txt` in the line.
+`STOCK_LAUNCHER=<package>` is how `launcher/build-and-install.sh` takes the stock launcher, from the
+environment; restore.sh never reads it. The Skyworth SWTV-22AE-FHD page said to pass
+`STOCK_LAUNCHER=` "when restoring", which leaves restore.sh on its default launcher, so a line that
+pairs a restore with that setting has to name the installer it belongs to.
+
Run from the repository root: python3 -m unittest discover -s tests -v
"""
import os
@@ -42,6 +47,10 @@ PAIR = re.compile(r"tools[/\\]restore\.sh\s+(\S+)\s+(\S+)")
PACKAGE = re.compile(r"[A-Za-z_][A-Za-z0-9_]*(\.[A-Za-z0-9_]+)+")
# A token as a page wraps it: `code`, "quoted", and the punctuation that ends the sentence.
WRAPPER = "`'\",;."
+# "restore.sh", "Restore", "when restoring"; not RESTORE_KEY_SERVICES, an installer setting.
+RESTORING = re.compile(r"(?i)\brestor(?:e|ing)\b")
+STOCK_SETTING = re.compile(r"STOCK_LAUNCHER\b")
+INSTALLER = re.compile(r"build-and-install")
def unwrapped(token):
@@ -113,6 +122,23 @@ def commands_without_a_list(root):
if not unwrapped(first).endswith(".txt") and "<" not in first]
+def restore_with_stock_setting(root):
+ """(file, line number, names the installer, sets it) for every line about a restore that names
+ STOCK_LAUNCHER; "sets it" is the `STOCK_LAUNCHER=` form an owner would type."""
+ found = []
+ for path, text in walk(root):
+ for number, line in enumerate(text.splitlines(), 1):
+ if RESTORING.search(line) and STOCK_SETTING.search(line):
+ found.append((path, number, bool(INSTALLER.search(line)), "STOCK_LAUNCHER=" in line))
+ return found
+
+
+def stock_setting_for_restore(root):
+ """(file, line number) for the lines that set STOCK_LAUNCHER= for a restore and name no installer."""
+ return [(path, number) for path, number, installer, sets in restore_with_stock_setting(root)
+ if sets and not installer]
+
+
class RestoreReferencesTest(unittest.TestCase):
def test_every_reference_names_a_list_that_is_there(self):
missing = [(str(path), name) for path, name in read_references(ROOT)
@@ -171,6 +197,23 @@ class RestoreReferencesTest(unittest.TestCase):
self.assertIn('STOCK="${2:', text,
"restore.sh no longer takes the stock launcher as its second argument")
+ def test_a_restore_is_not_told_to_take_stock_launcher_from_the_environment(self):
+ # The Skyworth SWTV-22AE-FHD page said "When restoring or building/installing, pass
+ # `STOCK_LAUNCHER=...`". restore.sh reads only its second argument, so an owner who did that
+ # got com.google.android.tvlauncher back instead of launcherx.
+ self.assertGreaterEqual(len(restore_with_stock_setting(ROOT)), 4,
+ "the sweep should read the lines that mention restore.sh and "
+ "STOCK_LAUNCHER together; it found fewer, so it cannot fail on one")
+ wrong = [(str(path), number) for path, number in stock_setting_for_restore(ROOT)]
+ self.assertEqual([], wrong,
+ "these lines set STOCK_LAUNCHER= for a restore without naming "
+ "launcher/build-and-install.sh; restore.sh takes the launcher as its second "
+ "argument and never reads that setting")
+ for script in ("restore.sh", "restore.ps1"):
+ text = (ROOT / "tools" / script).read_text(encoding="utf-8")
+ self.assertNotIn("STOCK_LAUNCHER", text,
+ f"{script} reads STOCK_LAUNCHER now, so the rule above is out of date")
+
# ---- the reader itself, so the two tests above cannot pass by reading nothing ---------------
def write(self, root, path, text):
@@ -290,6 +333,28 @@ class RestoreReferencesTest(unittest.TestCase):
"restore.sh would turn them ON, and `tools/restore.sh` takes the list first.\n")
self.assertEqual([], restore_commands(root))
+ def test_stock_launcher_set_for_a_restore_is_reported(self):
+ with tempfile.TemporaryDirectory() as tmp:
+ root = Path(tmp)
+ self.write(root, "examples/x/README.md",
+ "- When restoring or building/installing, pass "
+ "`STOCK_LAUNCHER=com.google.android.apps.tv.launcherx`.\n")
+ self.assertEqual([(Path("examples/x/README.md"), 1)], stock_setting_for_restore(root))
+
+ def test_stock_launcher_set_for_the_installer_is_quiet(self):
+ with tempfile.TemporaryDirectory() as tmp:
+ root = Path(tmp)
+ self.write(root, "examples/x/debloat.txt",
+ "# Stock launcher: com.example.home (pass it to restore.sh, and to the installer as\n"
+ "# STOCK_LAUNCHER=com.example.home launcher/build-and-install.sh)\n"
+ "# Stock launcher: com.example.home (pass it as STOCK_LAUNCHER / to restore.sh).\n"
+ "TV_HOST=<tv ip> RESTORE_KEY_SERVICES=1 STOCK_LAUNCHER=com.example.home make\n"
+ "- When restoring, pass it to `tools/restore.sh` as the second argument; when "
+ "building/installing, pass `STOCK_LAUNCHER=com.example.home` to "
+ "`launcher/build-and-install.sh`.\n")
+ self.assertEqual([], stock_setting_for_restore(root))
+ self.assertEqual([3, 5], [number for _, number, _, _ in restore_with_stock_setting(root)])
+
def test_the_powershell_twin_is_a_named_parameter_command(self):
# restore.ps1 takes -List and -Stock and has no package-shaped bare argument, so none of this
# is read as a two-argument bash command.
diff --git a/tests/test_stock_launcher_undo.py b/tests/test_stock_launcher_undo.py
index a976cb5c2..a3ebd9e19 100644
--- a/tests/test_stock_launcher_undo.py
+++ b/tests/test_stock_launcher_undo.py
@@ -21,7 +21,10 @@ one of those passed packages; `com.google.android.tvlauncher` is exempt because
A list can also leave the stock launcher off its active lines and let `launcher/build-and-install.sh`
disable it once the new launcher owns Home. That counts as disabling it when the line naming it says so
(`build-and-install.sh disables it`), or when the list hands the package to the installer as
-`STOCK_LAUNCHER=<package>`, the setting the installer disables.
+`STOCK_LAUNCHER=<package>`, the setting the installer disables. A line can also name the package
+itself (`build-and-install.sh disables launcherx`), and `STOCK_LAUNCHER=<that package>` is the stock
+launcher named on that line or before it. A package the installer is said to disable is checked even
+when no line calls it the stock launcher.
Run from the repository root: python3 -m unittest discover -s tests -v
"""
@@ -44,6 +47,15 @@ STOCK_ENV = re.compile(r"STOCK_LAUNCHER\s*[=:]\s*(" + PACKAGE + r")")
# "does not disable" and "it would disable" are not it.
INSTALL_DISABLES = re.compile(
r"(?i)build-and-install(?:\.sh|\.ps1)?\b(?:(?!\bnever\b)[^.])*\bdisables\b")
+# The same, with the package it disables named: `launcher/build-and-install.sh disables launcherx
+# itself`, `(build-and-install disables com.google.android.tvlauncher itself)`.
+INSTALL_DISABLES_NAMED = re.compile(
+ r"(?i)build-and-install(?:\.sh|\.ps1)?\b(?:(?!\bnever\b)[^.])*\bdisables\s+(launcherx\b|"
+ + PACKAGE + r")")
+# Google TV's stock launcher as list headers shorten it.
+SHORT_NAMES = {"launcherx": "com.google.android.apps.tv.launcherx"}
+# `STOCK_LAUNCHER=<that package>`: the stock launcher named on this line or an earlier one.
+STOCK_ENV_BACK = re.compile(r"STOCK_LAUNCHER\s*=\s*<th(?:at|is) package>")
# An active line's own trailing comment, e.g. `com.google.android.apps.tv.launcherx # stock Google TV
# home; com.gathin.tvhome is Home now`. The phrase has to end the naming: "stock launcher
# recommendation rows" (com.google.android.tvrecommendations) is not a launcher.
@@ -98,15 +110,25 @@ def restore_invocations(text):
def install_disables(text):
"""The packages the list says launcher/build-and-install.sh disables, mapped to the lines that say so.
- Only a package the line names as the stock launcher counts, and every `STOCK_LAUNCHER=<package>`:
- that is the package the installer disables. `STOCK_LAUNCHER=none` names no package.
+ A package the line names as the stock launcher counts, a package the line says the installer
+ disables by name (`disables launcherx`), and every `STOCK_LAUNCHER=<package>`: that is the package
+ the installer disables. `STOCK_LAUNCHER=none` names no package, and `STOCK_LAUNCHER=<that package>`
+ is the stock launcher named on that line or before it.
"""
disabled = {}
+ named_stock = None
for number, line in enumerate(text.splitlines(), 1):
+ claimed = [match.group(1) for match in STOCK_CLAIM.finditer(line)]
+ if claimed:
+ named_stock = claimed[-1]
named = [match.group(1) for match in STOCK_ENV.finditer(line)]
if INSTALL_DISABLES.search(line):
- named += [match.group(1) for match in STOCK_CLAIM.finditer(line)]
- for package in named:
+ named += claimed
+ named += [SHORT_NAMES.get(match.group(1).lower(), match.group(1))
+ for match in INSTALL_DISABLES_NAMED.finditer(line)]
+ if named_stock and STOCK_ENV_BACK.search(line):
+ named.append(named_stock)
+ for package in dict.fromkeys(named):
disabled.setdefault(package, []).append(number)
return disabled
@@ -115,9 +137,10 @@ def undo_problems(text):
"""Why this list's undo does not reach its own stock launcher, one sentence each."""
active = {package for _, package in active_packages(text)}
passed = {package for _, package in restore_invocations(text) if package}
+ claims = stock_claims(text)
installer = install_disables(text)
problems = []
- for package, lines in sorted(stock_claims(text).items()):
+ for package in sorted(set(claims) | set(installer)):
if package == DEFAULT_STOCK or package in passed:
continue
if package in active:
@@ -126,10 +149,13 @@ def undo_problems(text):
how = f"launcher/build-and-install.sh disables it (line {installer[package][0]})"
else:
continue
+ if package in claims:
+ said = f"line {claims[package][0]} calls {package} the stock launcher and {how}"
+ else:
+ said = f"line {installer[package][0]} says launcher/build-and-install.sh disables {package}"
problems.append(
- f"line {lines[0]} calls {package} the stock launcher and {how}, but the "
- f"restore command in this file does not pass it (restore.sh falls back to "
- f"{DEFAULT_STOCK}, which this set does not ship)")
+ f"{said}, but the restore command in this file does not pass it (restore.sh falls back "
+ f"to {DEFAULT_STOCK}, which this set does not ship)")
return problems
@@ -241,8 +267,47 @@ class StockLauncherUndoTest(unittest.TestCase):
self.assertEqual({}, install_disables(kept))
self.assertEqual([], undo_problems(kept))
+ def test_the_installer_disabling_launcherx_by_name_counts(self):
+ text = (
+ "# Undo: TV_HOST=<tv ip> tools/restore.sh examples/x/debloat.txt\n"
+ "com.google.android.feedback\n"
+ "# Batch 5 - with the launcher in this repo installed (launcher/build-and-install.sh disables launcherx)\n"
+ "com.google.android.tungsten.setupwraith\n"
+ )
+ self.assertEqual({}, stock_claims(text))
+ self.assertEqual({"com.google.android.apps.tv.launcherx": [3]}, install_disables(text))
+ problems = undo_problems(text)
+ self.assertEqual(1, len(problems))
+ self.assertIn("line 3 says launcher/build-and-install.sh disables "
+ "com.google.android.apps.tv.launcherx", problems[0])
+ passed = text.replace("debloat.txt\n", "debloat.txt com.google.android.apps.tv.launcherx\n")
+ self.assertEqual([], undo_problems(passed))
+ default = (
+ "# --- After launcher/ owns Home (build-and-install disables com.google.android.tvlauncher itself)\n"
+ "# Undo: TV_HOST=<tv ip> tools/restore.sh examples/x/debloat.txt\n"
+ )
+ self.assertEqual({DEFAULT_STOCK: [1]}, install_disables(default))
+ self.assertEqual([], undo_problems(default))
+
+ def test_stock_launcher_that_package_is_the_one_named_before(self):
+ text = (
+ "# Undo: TV_HOST=<tv ip> tools/restore.sh examples/x/debloat.txt\n"
+ "# Stock launcher is cn.zeasn.launcher.vstoresubclient.toptech (Zeasn). It is not in this list: disable it only\n"
+ "# once a replacement Home is installed (launcher/build-and-install.sh with STOCK_LAUNCHER=<that package>).\n"
+ )
+ self.assertEqual({"cn.zeasn.launcher.vstoresubclient.toptech": [3]}, install_disables(text))
+ problems = undo_problems(text)
+ self.assertEqual(1, len(problems))
+ self.assertIn("line 2 calls cn.zeasn.launcher.vstoresubclient.toptech the stock launcher and "
+ "launcher/build-and-install.sh disables it (line 3)", problems[0])
+ passed = text.replace("debloat.txt\n", "debloat.txt cn.zeasn.launcher.vstoresubclient.toptech\n")
+ self.assertEqual([], undo_problems(passed))
+ nothing_named = text.splitlines(True)[2]
+ self.assertEqual({}, install_disables(nothing_named))
+
def test_an_installer_that_leaves_it_alone_needs_nothing(self):
for note in ("launcher/build-and-install.sh never disables it here",
+ "launcher/build-and-install.sh never disables launcherx here",
"launcher/build-and-install.sh does not disable it",
"do not run build-and-install.sh with its defaults: it would disable it"):
with self.subTest(note=note):