Skip to content

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

tools: match.py counts the second list a folder ships beside its debloat.txt

xbsheng3e898a41c9f9
diff --git a/tests/test_match.py b/tests/test_match.py
index ee5897e64..8e810cc98 100644
--- a/tests/test_match.py
+++ b/tests/test_match.py
@@ -1,6 +1,6 @@
"""tools/match.py reads a saved `pm list packages` and counts how the tested lists treat each package.
-It reads files only: a package file and a folder of */debloat.txt lists. For each package it prints how
+It reads files only: a package file and a folder of */debloat*.txt lists. For each package it prints how
many lists disable it, how many name it commented out, and the note those lines give it most often; a
package disable.sh refuses as one of Android's core packages (#884) is printed as `never`. A packages
file or examples folder that cannot be used ends the run at 2 with one line, no traceback.
@@ -123,18 +123,43 @@ class TallyTest(MatchCase):
counts, _ = match.tally(["com.example.ads"], self.examples)
self.assertEqual(["com.example.ads"], list(counts))
- def test_only_debloat_txt_one_folder_down_is_read(self):
+ def test_every_list_beside_debloat_txt_is_read(self):
+ # A folder may ship a second list beside debloat.txt - google-chromecast-gtv-4k/debloat-keep-cast.txt,
+ # sony-bravia-4k-ur3/debloat-display-only.txt - and tools/disable.sh applies one like any other, so
+ # the tally reads it too. One folder down only, as before: a bare debloat.txt at the top of
+ # examples/, or a list inside a subfolder, is not one of examples/'s lists.
self.add_list("a", "com.example.ads\n")
- (self.examples / "a" / "debloat-extra.txt").write_text("com.example.ads\n")
+ (self.examples / "a" / "debloat-extra.txt").write_text("com.example.ads\ncom.example.extra\n")
(self.examples / "debloat.txt").write_text("com.example.ads\n")
+ (self.examples / "a" / "nested" / "debloat.txt").parent.mkdir()
+ (self.examples / "a" / "nested" / "debloat.txt").write_text("com.example.ads\n")
+ counts, read = match.tally(["com.example.ads", "com.example.extra"], self.examples)
+ self.assertEqual(2, read)
+ self.assertEqual((2, 0, ""), counts["com.example.ads"])
+ self.assertEqual((1, 0, ""), counts["com.example.extra"])
+
+ def test_a_package_only_a_second_list_disables_is_counted(self):
+ # The shape examples/oppo-k9-55-oppocnm632/debloat-extra.txt has: com.changba.sd is on that list
+ # alone, and the tally printed 0 for it while the tool read debloat.txt only.
+ self.add_list("a", "com.example.ads\n")
+ (self.examples / "a" / "debloat-extra.txt").write_text("com.changba.sd # karaoke\n")
+ counts, read = match.tally(["com.changba.sd"], self.examples)
+ self.assertEqual(2, read)
+ self.assertEqual((1, 0, "karaoke"), counts["com.changba.sd"])
+
+ def test_a_second_list_counts_as_its_own_list(self):
+ # The counts are per list, as the closing line says, so a package both of a folder's lists carry
+ # reads as two lists rather than one folder.
+ self.add_list("a", "com.example.ads\n")
+ (self.examples / "a" / "debloat-keep-two.txt").write_text("com.example.ads\n")
counts, read = match.tally(["com.example.ads"], self.examples)
- self.assertEqual(1, read)
- self.assertEqual((1, 0, ""), counts["com.example.ads"])
+ self.assertEqual(2, read)
+ self.assertEqual((2, 0, ""), counts["com.example.ads"])
def test_a_folder_without_lists_stops(self):
with self.assertRaises(SystemExit) as caught:
match.tally(["com.example.ads"], self.examples)
- self.assertIn("no */debloat.txt", str(caught.exception.code))
+ self.assertIn("no */debloat*.txt", str(caught.exception.code))
def test_a_list_that_is_a_directory_stops_the_whole_tally(self):
self.add_list("a", "com.example.ads\n")
@@ -220,7 +245,7 @@ class MainTest(MatchCase):
code, out, err = self.run_main(str(packages), "--examples", str(self.examples))
self.assertEqual(2, code)
self.assertEqual("", out)
- self.assertIn("no */debloat.txt", err)
+ self.assertIn("no */debloat*.txt", err)
def test_the_default_examples_folder_is_this_checkout(self):
self.assertEqual(ROOT / "examples", match.EXAMPLES)
diff --git a/tests/test_sweeps_read_second_lists.py b/tests/test_sweeps_read_second_lists.py
index ad09a2bc3..881367dc7 100644
--- a/tests/test_sweeps_read_second_lists.py
+++ b/tests/test_sweeps_read_second_lists.py
@@ -10,9 +10,14 @@ check (tests/test_stock_launcher_undo.py) and the rule that a list's undo names
or an undo that names another file passed all three. tests/test_core_packages.py and
tests/test_apply_override_caveat.py already read both.
-Each test below runs the function a sweep calls (format_problems, sweep, commands_for_another_list) on
-a temp tree whose second list breaks that sweep's rule, so a sweep that goes back to reading
-debloat.txt alone fails here.
+tools/match.py's per-package tally was the fourth: it printed how many examples/*/debloat.txt disable a
+package, so a package only a second list carries - examples/oppo-k9-55-oppocnm632/debloat-extra.txt's
+com.changba.sd, com.google.android.videos on four of the eight second lists - read as 0, "no tested list
+has tried this", in the one tool an owner runs before disabling something.
+
+Each test below runs the function a sweep calls (format_problems, sweep, commands_for_another_list,
+match.tally) on a temp tree whose second list breaks that sweep's rule, so a sweep that goes back to
+reading debloat.txt alone fails here.
Run from the repository root: python3 -m unittest discover -s tests -v
"""
@@ -28,6 +33,9 @@ import test_restore_references as references # noqa: E402
import test_stock_launcher_undo as stock_undo # noqa: E402
ROOT = Path(__file__).resolve().parents[1]
+sys.path.insert(0, str(ROOT / "tools"))
+import match # noqa: E402
+
KEEP_CAST = ROOT / "examples" / "google-chromecast-gtv-4k" / "debloat-keep-cast.txt"
LAUNCHERX = "com.google.android.apps.tv.launcherx"
@@ -88,6 +96,18 @@ class SecondListsTest(unittest.TestCase):
self.assertEqual([("examples/x/debloat-keep-two.txt", "examples/x/debloat.txt")],
references.commands_for_another_list(root, pattern))
+ def test_the_tally_reads_a_second_list(self):
+ # tools/match.py counted only debloat.txt, so a package on the second list alone printed as 0 -
+ # the answer an owner reads as "no tested list disables this".
+ with tempfile.TemporaryDirectory() as tmp:
+ examples = Path(tmp) / "examples"
+ write(examples, "x/debloat.txt", "com.example.one\n")
+ write(examples, "x/debloat-extra.txt", "com.example.two # karaoke\n")
+ counts, read = match.tally(["com.example.one", "com.example.two"], examples)
+ self.assertEqual(2, read, "the second list was not counted")
+ self.assertEqual((1, 0, ""), counts["com.example.one"])
+ self.assertEqual((1, 0, "karaoke"), counts["com.example.two"])
+
if __name__ == "__main__":
unittest.main()
diff --git a/tools/match.py b/tools/match.py
index e2c613548..528e8678c 100644
--- a/tools/match.py
+++ b/tools/match.py
@@ -4,10 +4,13 @@
match.py <saved pm list packages> [--examples <folder>]
Save the TV's packages once (`tools/venv/bin/python -I tools/tv.py 'pm list packages' > packages.txt`),
-then run this: for every package in that file it prints how many examples/*/debloat.txt disable it, how
-many name it commented out (kept on), and the trailing comment those lines give it most often. A package
-that disable.sh refuses as one of Android's core packages (#884) is marked `never`, whatever any list
-says.
+then run this: for every package in that file it prints how many of the lists in examples/ disable it,
+how many name it commented out (kept on), and the trailing comment those lines give it most often. A
+folder can hold a second list beside its debloat.txt - google-chromecast-gtv-4k/debloat-keep-cast.txt,
+sony-bravia-4k-ur3/debloat-display-only.txt - and tools/disable.sh applies one like any other, so every
+debloat*.txt is read rather than the first only: a package that one of them alone disables is a package
+some tested set turned off, and counting it as 0 would read as no list having tried it. A package that
+disable.sh refuses as one of Android's core packages (#884) is marked `never`, whatever any list says.
It reads files only: no TV, no ADB client, nothing written. It ranks nothing and suggests no list; the
counts are what the lists say, not a verdict for this TV.
@@ -76,10 +79,12 @@ def read_list(text):
def tally(packages, examples):
- """{package: (disabled, commented, most common note)} over every examples/*/debloat.txt."""
- lists = sorted(Path(examples).glob("*/debloat.txt"))
+ """{package: (disabled, commented, most common note)} over every examples/*/debloat*.txt."""
+ # The same discovery tests/test_examples.py and tests/test_stock_launcher_undo.py sweep with: a folder
+ # may ship a second list beside debloat.txt, and tools/disable.sh takes it like the first.
+ lists = sorted(Path(examples).glob("*/debloat*.txt"))
if not lists:
- raise SystemExit(f"{examples}: no */debloat.txt lists in it")
+ raise SystemExit(f"{examples}: no */debloat*.txt lists in it")
wanted = set(packages)
disabled, commented = Counter(), Counter()
notes = {name: Counter() for name in packages}