Skip to content

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

tools: privacy.py answers 2 when nothing was asked of the TV

xbsheng8e268ff021f9
diff --git a/tests/test_privacy_audit.py b/tests/test_privacy_audit.py
index 0bd7d15c7..fbc8ff974 100644
--- a/tests/test_privacy_audit.py
+++ b/tests/test_privacy_audit.py
@@ -250,9 +250,24 @@ class PrivacyAuditTest(unittest.TestCase):
def test_unreachable_tv_names_the_setting_to_check(self):
self.tv(unreachable=True)
result = self.run_script()
- self.assertNotEqual(result.returncode, 0)
+ # 2, the status every tool answers for a run that never read the TV: 1 is a run that
+ # reached it and then failed, and a wrapper around this script reads the split.
+ self.assertEqual(result.returncode, 2, result.stderr)
self.assertIn("cannot reach the TV", result.stderr)
self.assertIn("tools/tv.py --probe", result.stderr)
+ self.assertIn("Nothing was asked of the TV.", result.stderr)
+ self.assertEqual(result.stdout, "")
+
+ def test_a_run_without_the_adb_client_is_2(self):
+ # A client that is not there at all: `import tv` fails, and nothing was sent.
+ (self.repo / "tools" / "tv.py").unlink()
+ result = self.run_script()
+ self.assertEqual(result.returncode, 2, result.stderr)
+ self.assertIn("cannot load tools/tv.py", result.stderr)
+ self.assertIn("python3 -m venv tools/venv", result.stderr)
+ self.assertIn("Nothing was asked of the TV.", result.stderr)
+ self.assertNotIn("Traceback", result.stderr)
+ self.assertEqual(result.stdout, "")
def test_an_empty_package_list_is_an_error_not_an_empty_report(self):
self.tv(installed=[], disabled=[])
diff --git a/tests/test_privacy_write_name.py b/tests/test_privacy_write_name.py
index 9c9bdb6d5..6fa27bbc5 100644
--- a/tests/test_privacy_write_name.py
+++ b/tests/test_privacy_write_name.py
@@ -102,20 +102,21 @@ class PrivacyWriteNameTest(unittest.TestCase):
(self.repo / "lists").mkdir()
self.tv(unreachable=True)
result = self.write("--write", "lists")
- self.assertEqual(result.returncode, 1, result.stderr)
+ self.assertEqual(result.returncode, 2, result.stderr)
self.assertNotIn("Traceback", result.stderr)
self.assertIn("lists is a folder", result.stderr)
self.assertIn("lists/privacy.txt", result.stderr)
self.assertIn("Nothing was asked of the TV.", result.stderr)
self.assertNotIn("cannot reach the TV", result.stderr)
self.assertNotIn("already exists", result.stderr)
+ self.assertEqual(result.stdout, "")
self.assertEqual(list((self.repo / "lists").iterdir()), [])
def test_a_folder_with_a_trailing_separator_is_the_folder(self):
(self.repo / "lists").mkdir()
self.tv(unreachable=True)
result = self.write("--write", "lists/")
- self.assertEqual(result.returncode, 1, result.stderr)
+ self.assertEqual(result.returncode, 2, result.stderr)
self.assertIn("lists/ is a folder", result.stderr)
self.assertIn("lists/privacy.txt", result.stderr)
self.assertNotIn("already exists", result.stderr)
@@ -125,7 +126,7 @@ class PrivacyWriteNameTest(unittest.TestCase):
def test_a_folder_that_is_not_there_keeps_its_own_message(self):
self.tv(unreachable=True)
result = self.write("--write", "no-such-folder/privacy.txt")
- self.assertEqual(result.returncode, 1, result.stderr)
+ self.assertEqual(result.returncode, 2, result.stderr)
self.assertIn("there is no folder no-such-folder", result.stderr)
self.assertNotIn("is a folder", result.stderr)
@@ -133,7 +134,7 @@ class PrivacyWriteNameTest(unittest.TestCase):
(self.repo / "privacy.txt").write_text("# hand edits\n")
self.tv(unreachable=True)
result = self.write("--write", "privacy.txt")
- self.assertEqual(result.returncode, 1, result.stderr)
+ self.assertEqual(result.returncode, 2, result.stderr)
self.assertIn("privacy.txt already exists", result.stderr)
self.assertEqual((self.repo / "privacy.txt").read_text(), "# hand edits\n")
diff --git a/tests/test_privacy_write_target_first.py b/tests/test_privacy_write_target_first.py
index b2c455906..780448a77 100644
--- a/tests/test_privacy_write_target_first.py
+++ b/tests/test_privacy_write_target_first.py
@@ -88,28 +88,30 @@ class PrivacyWriteTargetTest(unittest.TestCase):
target.write_text("# hand edits\n")
self.tv(unreachable=True)
result = self.write("privacy.txt")
- self.assertEqual(result.returncode, 1)
+ self.assertEqual(result.returncode, 2, result.stderr)
self.assertIn("privacy.txt already exists; move it aside or choose another name.",
result.stderr)
self.assertIn("Nothing was asked of the TV.", result.stderr)
self.assertNotIn("cannot reach the TV", result.stderr)
+ self.assertEqual(result.stdout, "")
self.assertEqual(target.read_text(), "# hand edits\n")
def test_a_missing_folder_is_refused_before_the_tv_is_asked(self):
self.tv(unreachable=True)
result = self.write("no-such-folder/privacy.txt")
- self.assertEqual(result.returncode, 1)
+ self.assertEqual(result.returncode, 2, result.stderr)
self.assertNotIn("Traceback", result.stderr)
self.assertIn("there is no folder no-such-folder", result.stderr)
self.assertIn("Nothing was asked of the TV.", result.stderr)
self.assertNotIn("cannot reach the TV", result.stderr)
+ self.assertEqual(result.stdout, "")
self.assertFalse((self.repo / "no-such-folder").exists())
def test_a_folder_that_is_a_file_is_refused_too(self):
(self.repo / "lists").write_text("not a folder\n")
self.tv(unreachable=True)
result = self.write("lists/privacy.txt")
- self.assertEqual(result.returncode, 1)
+ self.assertEqual(result.returncode, 2, result.stderr)
self.assertNotIn("Traceback", result.stderr)
self.assertIn("there is no folder lists", result.stderr)
self.assertNotIn("cannot reach the TV", result.stderr)
diff --git a/tools/privacy.py b/tools/privacy.py
index 671d9d46f..1fa7d21b9 100644
--- a/tools/privacy.py
+++ b/tools/privacy.py
@@ -19,6 +19,14 @@ package is listening.
Disabling is left to `tools/disable.sh`, so the undo path is the one every list already uses: the
record written before the first change, replayed by `tools/restore.sh`.
+
+Exit status: 0 the audit ran (the report printed, or the list written), 1 it reached the TV and then
+failed (the list could not be written, nothing was identified to write, a file that appeared while
+the audit ran), 2 the run never got as far as the TV: an argument was refused, the `--write` target
+cannot be written, `tools/tv.py` could not be loaded, or the connection failed in one of the ways
+tv.py explains (a refused port, a Wireless debugging port, a handshake that timed out, a TV that
+cannot be reached). Why it stopped goes to stderr, which a wrapper that throws the report on stdout
+away still shows.
"""
import os
import re
@@ -153,13 +161,21 @@ def connect():
try:
import tv
except ImportError as e:
- raise SystemExit(f"cannot load tools/tv.py ({e}).\nrun: python3 -m venv tools/venv && "
- "tools/venv/bin/pip install -r tools/requirements.txt")
+ # Exit 2, where SystemExit(str) exits 1 by itself: no command was sent, and 1 is the status
+ # this file keeps for a run that reached the TV and then failed. b64push.py, check.py and
+ # bench.py split the two the same way, which is what a wrapper around this script reads.
+ sys.stderr.write(f"cannot load tools/tv.py ({e}).\n"
+ "run: python3 -m venv tools/venv && "
+ "tools/venv/bin/pip install -r tools/requirements.txt\n"
+ "Nothing was asked of the TV.\n")
+ raise SystemExit(2)
try:
return tv.connect()
except Exception as e:
- raise SystemExit(f"cannot reach the TV at {os.environ.get('TV_HOST', 'TV_HOST')}: {e}\n"
- "Check TV_HOST and that USB debugging is still on (tools/tv.py --probe).")
+ sys.stderr.write(f"cannot reach the TV at {os.environ.get('TV_HOST', 'TV_HOST')}: {e}\n"
+ "Check TV_HOST and that USB debugging is still on (tools/tv.py --probe).\n"
+ "Nothing was asked of the TV.\n")
+ raise SystemExit(2)
def query_packages(dev):
@@ -450,7 +466,11 @@ def main():
# and `dumpsys package` is slow on old firmware, all for a file that could not be written.
problem = target_problem(args[1])
if problem:
- raise SystemExit(f"{problem} Nothing was asked of the TV.")
+ # Exit 2: the argument was wrong, so no package was probed - the status the two usage
+ # refusals above answer, and the one a wrapper reads as "nothing was sent to the TV"
+ # rather than a run that reached it and failed. SystemExit(str) would exit 1.
+ sys.stderr.write(f"{problem} Nothing was asked of the TV.\n")
+ return 2
dev = connect()
try: