Skip to content

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

tools: protect SDK sandbox in core package guards (#2557)

SaviorOneZerobf5051249ed4
diff --git a/tests/test_core_packages.py b/tests/test_core_packages.py
index ce460c191..e3a2615ca 100644
--- a/tests/test_core_packages.py
+++ b/tests/test_core_packages.py
@@ -36,6 +36,7 @@ CORE = [
"com.google.android.ext.shared", "com.android.ext.shared",
"com.google.android.modulemetadata", "com.android.modulemetadata",
"com.google.android.overlay.modules.ext.services", "com.google.android.overlay.modules.permissioncontroller",
+ "com.android.sdksandbox",
"com.android.systemui", "com.android.shell", "com.android.phone",
"com.android.settings", "com.android.tv.settings",
"com.android.providers.settings", "com.android.providers.tv", "com.android.providers.media",
@@ -55,6 +56,10 @@ NOT_CORE = [
"android.ext.services.overlay", "android.ext.sharedlib", "android.extservices",
# Tested lists turn these off: FAST channels, and the Live TV app the factory disables on some sets.
"com.cltv.fast", "com.cltv.hybrid", "com.mediatek.tv.settings", "com.mediatek.tis.overlay",
+ # Only the exact SDK sandbox is protected for #2557; the other reported modules stay allowed.
+ "com.android.adservices.api", "com.android.ondevicepersonalization.services",
+ "com.android.federatedcompute.services", "com.android.sdksandbox.overlay",
+ "com.android.sdksandbox2", "com.example.sdksandbox",
]
@@ -178,6 +183,68 @@ class CorePackagesTest(unittest.TestCase):
self.assertIn("#884", result.stderr)
self.assertNotIn("could not reach", result.stderr)
+ def assert_sdk_sandbox_preflight(self, script, fix=False):
+ """The exact package in a mixed BOM/CRLF list must stop before any transport, even with overrides."""
+ shell = shutil.which("pwsh" if script == "disable.ps1" else "bash")
+ if script != "check.py" and not shell:
+ self.skipTest(f"{script} needs its shell on PATH")
+ with tempfile.TemporaryDirectory() as tmp:
+ repo = Path(tmp) / "repo"
+ tools = repo / "tools"
+ tools.mkdir(parents=True)
+ for name in (script, "recovery.py"):
+ shutil.copy2(ROOT / "tools" / name, tools / name)
+ touched = Path(tmp) / "transport-called"
+ (tools / "tv.py").write_text(
+ "from pathlib import Path\n"
+ "def connect(*args, **kwargs):\n"
+ f" Path({str(touched)!r}).touch()\n"
+ " raise AssertionError('unexpected transport')\n"
+ "if __name__ == '__main__':\n"
+ " connect()\n", encoding="utf-8")
+ for relative in ("venv/bin/python", "venv/Scripts/python.exe"):
+ client = tools / relative
+ client.parent.mkdir(parents=True, exist_ok=True)
+ client.write_text(f'#!/bin/sh\nexec "{sys.executable}" "$@"\n')
+ client.chmod(0o755)
+ listing = Path(tmp) / "debloat.txt"
+ listing.write_bytes(b"\xef\xbb\xbfcom.example.ads\r\n"
+ b"com.android.sdksandbox # issue 2557\r\n")
+ env = dict(os.environ, TV_HOST="192.0.2.1", FORCE_HOME="1", FORCE_SETUPWRAITH="1",
+ TVINPUT_ALLOW="1", HANDLERS_ALLOW="1")
+ if script == "check.py":
+ command = [sys.executable, "-I", str(tools / script)]
+ if fix:
+ command.append("--fix")
+ command.append(str(listing))
+ elif script == "disable.ps1":
+ command = [shell, "-NoProfile", "-NonInteractive", "-File", str(tools / script),
+ "-TvHost", "192.0.2.1", str(listing)]
+ else:
+ command = [shell, str(tools / script), str(listing)]
+ result = subprocess.run(command, cwd=repo, env=env, capture_output=True, text=True,
+ stdin=subprocess.DEVNULL, timeout=30)
+ output = result.stdout + result.stderr
+ if script == "check.py":
+ self.assertEqual(result.returncode, 2, output)
+ else:
+ self.assertNotEqual(result.returncode, 0, output)
+ self.assertIn("refusing", output)
+ self.assertIn("com.android.sdksandbox", re.sub(r"\s+", "", output))
+ self.assertFalse(touched.exists(), "the core guard must run before the transport")
+
+ def test_sdk_sandbox_disable_sh_refuses_with_all_overrides(self):
+ self.assert_sdk_sandbox_preflight("disable.sh")
+
+ def test_sdk_sandbox_disable_ps1_refuses_with_all_overrides(self):
+ self.assert_sdk_sandbox_preflight("disable.ps1")
+
+ def test_sdk_sandbox_check_refuses_before_connecting(self):
+ self.assert_sdk_sandbox_preflight("check.py")
+
+ def test_sdk_sandbox_check_fix_refuses_before_connecting(self):
+ self.assert_sdk_sandbox_preflight("check.py", fix=True)
+
if __name__ == "__main__":
unittest.main()
diff --git a/tools/disable.ps1 b/tools/disable.ps1
index c47aa87e3..ed1b855a8 100644
--- a/tools/disable.ps1
+++ b/tools/disable.ps1
@@ -59,7 +59,8 @@ if (-not $pkgs -or $pkgs.Count -eq 0) {
# ship under AOSP's bare names, android.ext.services and android.ext.shared (#1711). Keep both
# patterns in step with disable.sh and recovery.py (tests/test_core_packages.py). The TV middleware
# (com.cltv.mal, com.mediatek.tis / tv.service / tv.agent) is guarded too (#1578, a Haier boot loop).
-$coreRe = '^(android|android\.ext\.(services|shared)|com\.android\.systemui|com\.android\.shell|com\.android\.phone|com\.android\.settings|com\.android\.tv\.settings|com\.(google\.)?android\.(permissioncontroller|packageinstaller|ext\.services|ext\.shared|modulemetadata)|com\.google\.android\.overlay\.modules.*|com\.android\.providers\..*|com\.cltv\.mal|com\.mediatek\.(tis|tv\.service|tv\.agent))$'
+# Protect the exact SDK sandbox package (#2557); the reported boot-failure cause is unconfirmed.
+$coreRe = '^(android|android\.ext\.(services|shared)|com\.android\.sdksandbox|com\.android\.systemui|com\.android\.shell|com\.android\.phone|com\.android\.settings|com\.android\.tv\.settings|com\.(google\.)?android\.(permissioncontroller|packageinstaller|ext\.services|ext\.shared|modulemetadata)|com\.google\.android\.overlay\.modules.*|com\.android\.providers\..*|com\.cltv\.mal|com\.mediatek\.(tis|tv\.service|tv\.agent))$'
$coreOk = '^com\.android\.providers\.(calendar|contacts|userdictionary|blockednumber)$'
$core = @($pkgs | Where-Object { $_ -cmatch $coreRe -and $_ -cnotmatch $coreOk })
if ($core.Count -gt 0) {
diff --git a/tools/disable.sh b/tools/disable.sh
index 1315e823a..9e0e7941d 100755
--- a/tools/disable.sh
+++ b/tools/disable.sh
@@ -63,7 +63,8 @@ fi
# service (com.mediatek.tis). A Haier H50H5F restarted in a loop after a debloat with com.cltv.mal off
# (#1578), and the Haier-built AQUA MatrixTV list keeps all four.
# Keep CORE_RE and CORE_OK the same in disable.ps1 and recovery.py (tests/test_core_packages.py).
-CORE_RE='^(android|android\.ext\.(services|shared)|com\.android\.systemui|com\.android\.shell|com\.android\.phone|com\.android\.settings|com\.android\.tv\.settings|com\.(google\.)?android\.(permissioncontroller|packageinstaller|ext\.services|ext\.shared|modulemetadata)|com\.google\.android\.overlay\.modules.*|com\.android\.providers\..*|com\.cltv\.mal|com\.mediatek\.(tis|tv\.service|tv\.agent))$'
+# Protect the exact SDK sandbox package (#2557); the reported boot-failure cause is unconfirmed.
+CORE_RE='^(android|android\.ext\.(services|shared)|com\.android\.sdksandbox|com\.android\.systemui|com\.android\.shell|com\.android\.phone|com\.android\.settings|com\.android\.tv\.settings|com\.(google\.)?android\.(permissioncontroller|packageinstaller|ext\.services|ext\.shared|modulemetadata)|com\.google\.android\.overlay\.modules.*|com\.android\.providers\..*|com\.cltv\.mal|com\.mediatek\.(tis|tv\.service|tv\.agent))$'
CORE_OK='^com\.android\.providers\.(calendar|contacts|userdictionary|blockednumber)$'
CORE=$(printf '%s\n' "$PKGS" | grep -E "$CORE_RE" | grep -vE "$CORE_OK" || true)
if [ -n "$CORE" ]; then
diff --git a/tools/recovery.py b/tools/recovery.py
index 66f931df6..dadca79c9 100644
--- a/tools/recovery.py
+++ b/tools/recovery.py
@@ -59,7 +59,8 @@ VERSION = 1
# Ultra, a CVTE SMART_TV and a MIBOX4 list them that way). disable.sh and disable.ps1
# carry the same two patterns (tests/test_core_packages.py keeps the three in step).
# The TV middleware too: com.cltv.mal (a Haier H50H5F looped with it off, #1578), com.mediatek.tis, tv.service, tv.agent.
-CORE_RE = re.compile(r"^(android|android\.ext\.(services|shared)|com\.android\.systemui|com\.android\.shell|com\.android\.phone|com\.android\.settings|com\.android\.tv\.settings|com\.(google\.)?android\.(permissioncontroller|packageinstaller|ext\.services|ext\.shared|modulemetadata)|com\.google\.android\.overlay\.modules.*|com\.android\.providers\..*|com\.cltv\.mal|com\.mediatek\.(tis|tv\.service|tv\.agent))$")
+# Protect the exact SDK sandbox package (#2557); the reported boot-failure cause is unconfirmed.
+CORE_RE = re.compile(r"^(android|android\.ext\.(services|shared)|com\.android\.sdksandbox|com\.android\.systemui|com\.android\.shell|com\.android\.phone|com\.android\.settings|com\.android\.tv\.settings|com\.(google\.)?android\.(permissioncontroller|packageinstaller|ext\.services|ext\.shared|modulemetadata)|com\.google\.android\.overlay\.modules.*|com\.android\.providers\..*|com\.cltv\.mal|com\.mediatek\.(tis|tv\.service|tv\.agent))$")
CORE_OK = re.compile(r"^com\.android\.providers\.(calendar|contacts|userdictionary|blockednumber)$")