Skip to content

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

Merge PR #497: tools: an audit for voice, ACR and telemetry, with the evidence (#444)

Gathin23ac4741d550ea
diff --cc README.md
index 4b226ee07,443e8d499..3d75d51a9
--- a/README.md
+++ b/README.md
@@@ -338,15 -291,13 +338,16 @@@ tools/theme.sh themes/auror
| [`tools/disable.sh`](tools/disable.sh), [`restore.sh`](tools/restore.sh) | Apply or undo a debloat list, the undo from the state recorded before the change. |
| [`tools/recovery.py`](tools/recovery.py) | Writes the record `disable.sh` needs to undo itself, and prints the restore batch. |
| [`tools/check.py`](tools/check.py) | Compares the TV with the list that was applied, for what a firmware update undid; `--fix` puts it back. |
+ | [`tools/privacy.py`](tools/privacy.py) | Audits the TV for voice, ACR and telemetry candidates and prints the evidence for each; `--write` turns the findings into a list `disable.sh` and `restore.sh` already understand. |
| [`tools/theme.sh`](tools/theme.sh) | Push a folder from [`themes/`](themes/) to the launcher and restart Home. |
| [`tools/race_calendar.py`](tools/race_calendar.py) | Writes this season's F1 calendar into a theme for race-weekend mode, from the free Jolpica API. |
-| [`launcher/build-and-install.sh`](launcher/build-and-install.sh) | Builds a shrunk release (about 429 KB), installs it, switches Home, and rolls back if Home does not land on it. |
+| [`launcher/build-and-install.sh`](launcher/build-and-install.sh) | Builds a shrunk release (about 436 KB), installs it, switches Home, and rolls back if Home does not land on it. |
-Debloat list paths passed to `disable.sh` and `restore.sh` are relative to the directory you run
-from, so your own lists can live outside the repository. Absolute paths also work.
+The scripts never leave the TV without a Home app: they only disable a stock launcher they recognise,
+and skip the Home app in a list until another launcher answers HOME. Details below.
+
+<details>
+<summary><b>Windows (PowerShell)</b></summary>
Every script has a PowerShell twin next to it. On Windows with Android Studio installed nothing
else is needed:
@@@ -372,15 -318,31 +373,40 @@@ why, and disables the rest of the list
the TV with nothing to start. Run the same list again once `launcher/build-and-install.sh` has made
the new launcher Home and the entry is applied; `FORCE_HOME=1` (`$env:FORCE_HOME`) disables it anyway.
+</details>
+
+<details>
+<summary><b>Where your lists can live</b></summary>
+
+Debloat list paths passed to `disable.sh` and `restore.sh` are relative to the directory you run
+from, so your own lists can live outside the repository. Absolute paths also work.
+
+</details>
+ ## The microphone, and what can be said about it
+
+ "Which of these packages is listening?" has no honest one-line answer, and a permission scan makes
+ it worse: on many sets most packages run as `android.uid.system`, so fifty of them show
+ `RECORD_AUDIO: granted=true` and none of them record anything. On others the microphone is in the
+ remote, not the panel, and a package with no audio permission at all still sees everything on screen
+ — ACR clients such as `tv.inscape.tvclient.inscapeacr` identify content from the picture and need
+ only `INTERNET`.
+
+ `tools/privacy.py` reports what the TV actually says instead of guessing:
+ `TV_HOST=192.168.1.50 tools/venv/bin/python -I tools/privacy.py` prints voice, ACR and telemetry
+ candidates in three groups, each with its evidence — named by the firmware's own
+ `voice_interaction_service`, a known component from [`examples/`](examples/), or nothing but a
+ matching name — plus whether the package declares `RECORD_AUDIO`, whether it shares the system UID,
+ and whether `appops` shows the microphone op was ever used since boot.
+
+ `--write privacy.txt` turns the identified candidates into a normal debloat list, so applying it and
+ undoing it are the commands you already use (`tools/disable.sh`, `tools/restore.sh`). Packages that
+ only matched by name stay out unless you pass `--include-low`; they are the ones to check with
+ `dumpsys package <name>` first.
+
+ What the audit cannot do is prove intent. `appops` shows an op was touched, not what happened to the
+ stream afterwards, and no scan of package names proves a TV is or is not recording. Disabling an
+ assistant is a trade you make with a specific loss (the remote's mic button, voice search inside
+ apps), which is why the report names that loss per package instead of calling it a win.
## The launcher
diff --cc tests/test_privacy_audit.py
index 000000000,ecb03f6c5..aa44f80f5
mode 000000,100644..100644
--- a/tests/test_privacy_audit.py
+++ b/tests/test_privacy_audit.py
@@@ -1,0 -1,297 +1,292 @@@
+ """tools/privacy.py against a simulated TV (#444).
+
+ The point of the audit is what it refuses to claim, and no TV reproduces that on demand: on firmware
+ where most packages share android.uid.system, a permission scan flags fifty packages that record
+ nothing. tools/tv.py is replaced by a fake that answers from a JSON file, so the real audit logic
+ runs and only the ADB transport is simulated.
+
+ Run from the repository root: python3 -m unittest discover -s tests -v
+ """
+ import json
+ import os
+ from pathlib import Path
+ import shutil
+ import subprocess
+ import sys
+ import tempfile
+ import unittest
+
+
+ ROOT = Path(__file__).resolve().parents[1]
+
+ FAKE_TV = r'''
+ import json
+ import os
+ import sys
+
+ STATE_PATH = os.environ["FAKE_TV_STATE"]
+
+
+ def load():
+ with open(STATE_PATH) as f:
+ return json.load(f)
+
+
+ state = load()
+
+
+ def answer(command):
+ if command == "pm list packages":
+ return "".join(f"package:{name}\n" for name in state["installed"])
+ if command == "pm list packages -d":
+ return "".join(f"package:{name}\n" for name in state["disabled"])
+ if command.startswith("settings get secure "):
+ key = command.split()[-1]
+ value = state.get("voice", {}).get(key)
+ return ("null" if not value else value) + "\n"
+ if command.startswith("dumpsys package "):
+ return state.get("dumps", {}).get(command.split()[-1], "") + "\n"
+ if command.startswith("appops get "):
+ name = command.split()[2]
+ return state.get("appops", {}).get(name, "No operations.") + "\n"
+ return ""
+
+
+ class Device:
+ def shell(self, command, read_timeout_s=None):
+ return answer(command)
+
+ def close(self):
+ pass
+
+
+ def connect():
+ if state.get("unreachable"):
+ raise ConnectionError("could not connect to 192.168.1.50:5555")
+ return Device()
+
+
+ def main():
+ return 0
+
+
+ if __name__ == "__main__":
+ sys.exit(main())
+ '''
+
+ SYSTEM_DUMP = "userId=1000\nrequested permissions:\n android.permission.RECORD_AUDIO: granted=true\n"
+ OWN_DUMP = "userId=10123\nrequested permissions:\n android.permission.RECORD_AUDIO: granted=true\n"
+ INTERNET_DUMP = "userId=10124\nrequested permissions:\n android.permission.INTERNET: granted=true\n"
+
+
+ class PrivacyAuditTest(unittest.TestCase):
+ def setUp(self):
+ tmp = tempfile.TemporaryDirectory()
+ self.addCleanup(tmp.cleanup)
+ self.base = Path(tmp.name)
+ self.repo = self.base / "repo"
+ tools = self.repo / "tools"
+ tools.mkdir(parents=True)
+ shutil.copy2(ROOT / "tools" / "privacy.py", tools / "privacy.py")
+ (tools / "tv.py").write_text(FAKE_TV)
+ self.script = tools / "privacy.py"
+ self.state_path = self.base / "tv-state.json"
+ self.tv()
+
+ def tv(self, **overrides):
+ state = {
+ "installed": [
+ "com.google.android.katniss",
+ "tv.inscape.tvclient.inscapeacr",
+ "org.droidtv.usagelogger",
+ "com.example.voicecontrol",
+ "com.example.plain",
+ ],
+ "disabled": ["org.droidtv.usagelogger"],
+ "voice": {"voice_interaction_service":
+ "com.google.android.katniss/.search.serviceapi.KatnissVoiceInteractionService",
+ "voice_recognition_service":
+ "com.google.android.katniss/.search.serviceapi.KatnissVoiceInteractionService",
+ "assistant": "null"},
+ "dumps": {
+ "com.google.android.katniss": OWN_DUMP,
+ "tv.inscape.tvclient.inscapeacr": INTERNET_DUMP,
+ "com.example.voicecontrol": SYSTEM_DUMP,
+ "org.droidtv.usagelogger": "userId=10125\n",
+ },
+ "appops": {
+ "com.google.android.katniss": "No operations.",
+ "tv.inscape.tvclient.inscapeacr": "RECORD_AUDIO: time=+1m23s ago",
+ },
+ "unreachable": False,
+ }
+ state.update(overrides)
+ self.state_path.write_text(json.dumps(state))
+
+ def run_script(self, *args, host="192.168.1.50"):
+ env = dict(os.environ, TV_HOST=host, FAKE_TV_STATE=str(self.state_path))
+ return subprocess.run([sys.executable, str(self.script), *args], cwd=self.repo, env=env,
+ capture_output=True, text=True, stdin=subprocess.DEVNULL, timeout=120)
+
+ # The report
+
+ def test_firmware_nomination_outranks_the_package_name(self):
+ out = self.run_script().stdout
+ self.assertIn("Voice assistants and wake word", out)
+ self.assertIn("named by the TV: voice_interaction_service, voice_recognition_service", out)
+
+ def test_system_uid_is_reported_once_not_as_a_permission_claim(self):
+ out = self.run_script().stdout
+ self.assertIn("shares the system UID (uid 1000)", out)
+ # The same package must not also be advertised as holding the microphone permission.
+ entry = out.split("com.example.voicecontrol", 1)[1].split("\n\n", 1)[0]
+ self.assertNotIn("declares RECORD_AUDIO", entry)
+
+ def test_appops_separates_declared_from_used(self):
+ out = self.run_script().stdout
+ katniss = out.split("com.google.android.katniss", 1)[1].split("\n\n", 1)[0]
+ self.assertIn("declares RECORD_AUDIO", katniss)
+ self.assertIn("appops: no RECORD_AUDIO use since boot", katniss)
+ inscape = out.split("tv.inscape.tvclient.inscapeacr", 1)[1].split("\n\n", 1)[0]
+ self.assertIn("appops: RECORD_AUDIO was used since boot", inscape)
+ self.assertNotIn("declares RECORD_AUDIO", inscape)
+
+ def test_acr_is_kept_apart_from_the_microphone(self):
+ out = self.run_script().stdout
+ self.assertIn("ACR (identifies what is on screen, no microphone needed)", out)
+ self.assertIn("INTERNET, not RECORD_AUDIO", out)
+
+ def test_name_matches_are_not_presented_as_findings(self):
+ out = self.run_script().stdout
+ self.assertIn("Matched by name only, nothing else known", out)
+ self.assertIn("matched by name only", out)
+
+ def test_never_claims_a_package_is_listening(self):
+ out = self.run_script().stdout
+ self.assertIn("What this audit cannot tell you: whether audio ever leaves the TV", out)
+ self.assertIn("the microphone is in the remote rather than the panel", out)
+ for claim in ("is recording", "listens in the background", "spy"):
+ self.assertNotIn(claim, out)
+
+ def test_disabled_packages_are_shown_as_disabled(self):
+ out = self.run_script().stdout
+ self.assertIn("disabled org.droidtv.usagelogger", out)
+
+ def test_names_from_the_tv_are_not_passed_back_into_commands(self):
+ self.tv(installed=["com.example.ok; rm -rf /", "com.google.android.katniss"])
+ out = self.run_script().stdout
+ self.assertNotIn("rm -rf", out)
+
+ # The list it writes
+
+ def write(self, *args):
+ target = self.base / "privacy.txt"
+ return target, self.run_script("--write", str(target), *args)
+
+ def test_write_leaves_out_name_matches_and_already_disabled_packages(self):
+ target, result = self.write()
+ self.assertEqual(result.returncode, 0, result.stderr)
+ text = target.read_text()
+ self.assertIn("com.google.android.katniss", text)
+ self.assertIn("tv.inscape.tvclient.inscapeacr", text)
+ self.assertNotIn("com.example.voicecontrol", text)
+ self.assertNotIn("org.droidtv.usagelogger", text)
+ self.assertEqual([line for line in text.splitlines() if line.startswith("com.example.plain")],
+ [])
+
+ def test_written_list_is_a_list_disable_and_restore_accept(self):
+ target, _ = self.write()
+ lines = [line.split("#", 1)[0].strip() for line in target.read_text().splitlines()]
+ packages = [line for line in lines if line]
+ self.assertEqual(packages, ["com.google.android.katniss",
+ "tv.inscape.tvclient.inscapeacr"])
+ # The header has to spell out both commands, because the undo is the reason this is safe.
+ self.assertIn("tools/disable.sh", target.read_text())
+ self.assertIn("tools/restore.sh", target.read_text())
+ # And the list has to survive the parser the two scripts share, not just look right.
+ sys.path.insert(0, str(ROOT / "tools"))
+ import recovery
+ self.assertEqual(recovery.read_list(target), packages)
+
+ def test_write_refuses_to_overwrite_a_list(self):
+ target, _ = self.write()
+ target.write_text("# mine\n")
+ _, second = self.write()
+ self.assertNotEqual(second.returncode, 0)
+ self.assertIn("already exists", second.stderr)
+ self.assertEqual(target.read_text(), "# mine\n")
+
+ def test_include_low_writes_the_name_matches_too(self):
+ target, result = self.write("--include-low")
+ self.assertEqual(result.returncode, 0, result.stderr)
+ self.assertIn("com.example.voicecontrol", target.read_text())
+
+ def test_write_says_nothing_to_do_when_only_name_matches_were_found(self):
+ self.tv(installed=["com.example.voicecontrol"],
+ voice={}, dumps={"com.example.voicecontrol": SYSTEM_DUMP})
+ target, result = self.write()
+ self.assertNotEqual(result.returncode, 0)
+ self.assertIn("nothing identified to write", result.stderr)
+ self.assertFalse(target.exists())
+
+ # Failure modes
+
+ def test_unreachable_tv_names_the_setting_to_check(self):
+ self.tv(unreachable=True)
+ result = self.run_script()
+ self.assertNotEqual(result.returncode, 0)
+ self.assertIn("cannot reach the TV", result.stderr)
+ self.assertIn("tools/tv.py --probe", result.stderr)
+
+ def test_an_empty_package_list_is_an_error_not_an_empty_report(self):
+ self.tv(installed=[], disabled=[])
+ result = self.run_script()
+ self.assertNotEqual(result.returncode, 0)
+ self.assertIn("returned no packages", result.stderr)
+
+ def test_usage_error_for_unknown_arguments(self):
+ result = self.run_script("--write")
+ self.assertEqual(result.returncode, 2)
+ self.assertIn("usage: privacy.py", result.stderr)
+
+
+ class CatalogueTest(unittest.TestCase):
+ """The catalogue is the part a reader trusts; keep it honest and small."""
+
+ @classmethod
+ def setUpClass(cls):
+ sys.path.insert(0, str(ROOT / "tools"))
+ import privacy
+ cls.privacy = privacy
+
+ def test_every_entry_says_what_the_package_does(self):
+ for name, (category, note) in self.privacy.CATALOGUE.items():
+ with self.subTest(package=name):
+ self.assertIn(category, ("voice", "acr", "telemetry"))
+ self.assertGreater(len(note), 20, "a note has to say something")
+ self.assertRegex(name, self.privacy.PACKAGE_RE)
+
+ def test_voice_entries_are_assistants_and_acr_entries_are_not(self):
+ # An ACR package that reads the picture is useless to list under the microphone.
+ for name, (category, note) in self.privacy.CATALOGUE.items():
+ if category == "acr":
+ with self.subTest(package=name):
+ self.assertNotIn("microphone", note.split(",")[0])
+
+ def test_name_hint_does_not_match_ordinary_bloat(self):
+ for name in ("com.android.vending", "com.example.playground", "com.example.streaming"):
+ self.assertFalse(self.privacy.NAME_HINT.search(name), name)
+ for name in ("com.example.voice", "com.example.voicecontrol", "tv.example.acr.client",
+ "com.example.speech.service"):
+ self.assertTrue(self.privacy.NAME_HINT.search(name), name)
+
+
+ class DocumentationTest(unittest.TestCase):
+ def test_readme_lists_the_tool_and_what_it_cannot_say(self):
+ readme = (ROOT / "README.md").read_text(encoding="utf-8")
+ self.assertIn("[`tools/privacy.py`](tools/privacy.py)", readme)
+ self.assertIn("What the audit cannot do is prove intent", readme)
+
- def test_prompt_tells_the_assistant_to_audit_instead_of_guessing(self):
- prompt = (ROOT / "PROMPT.md").read_text(encoding="utf-8")
- self.assertIn("tools/privacy.py", prompt)
- self.assertIn("Never say a package records", prompt)
-
+
+ if __name__ == "__main__":
+ unittest.main()