Debloat any Android or Google TV over Wi-Fi and get an Apple TV-style home.
Python adbadblockandroid-tvandroid-tv-launcherapple-tvbloatware-removalclaude-codedebloatfire-tvgoogle-tvlauncherprivacysmart-tvsony-braviatclvibe-codingxiaomi
launcher: ask the TV's SDK level before building, and answer #576
xbsheng9c6a98fb97b0
diff --git a/PROMPT.md b/PROMPT.mdindex a3766df22..e4ea0efa0 100644--- a/PROMPT.md+++ b/PROMPT.md@@ -81,6 +81,11 @@ Launcherdeclares `android.intent.category.HOME` unless it carries the manufacturer's signature. If youhit either, do the debloat half, say plainly that the launcher half is impossible here, and stopretrying installs. The matching `examples/` header says which case your TV is.+- Check the TV's SDK level before promising the launcher, too: `tools/tv.py 'getprop+ ro.build.version.sdk'` against `grep minSdk launcher/app/build.gradle` (26 = Android 8.0). A set+ below it answers `INSTALL_FAILED_OLDER_SDK`; lowering `minSdk` is a source change you would then+ maintain yourself, and an APK rebuilt elsewhere is nothing this repo can verify. On those sets offer+ the debloat half and say the launcher cannot be installed.- Don't install a third-party launcher that charges for basics like wallpapers. Build a small nativeAndroid TV launcher instead (Java, AndroidX RecyclerView, minSdk matching the TV, debug build is fine),install it over ADB, set it as the default home and disable the stock launcher. If several apps claimdiff --git a/README.md b/README.mdindex c9aafb767..f3b19f6c7 100644--- a/README.md+++ b/README.md@@ -308,6 +308,10 @@ AndroidX RecyclerView and nothing heavier. Built for sets with 1 GB of RAM: no bnetwork, no background services. It needs JDK 17 and Android SDK platform 34 to build; on macOS,`brew install openjdk@17 android-commandlinetools` and `sdkmanager "platforms;android-34" "build-tools;34.0.0"`. On Linuxthe install script finds `~/Android/Sdk` and the `java` on your PATH.+The **TV** needs Android 8.0 (API 26) or newer: `minSdk` is a compile-time floor in+[`launcher/app/build.gradle`](launcher/app/build.gradle), and the install script asks the TV for+`ro.build.version.sdk` before it builds, so an older set is told both numbers instead of failing at+`pm install` (see [Troubleshooting](docs/TROUBLESHOOTING.md) for what is left on such a set).- **Configure** in [`config.xml`](launcher/app/src/main/res/values/config.xml): dock order, hidden apps, the Live TV package, columns (tiles shrink from 5 up), rows under the dock, an optional VPN app for the network pill, and `reduced_motion` for TVs whose GPU cannot keep up.- **App library (optional):** enable `app_library` in config.xml or a theme to browse installed apps and add or remove Home shortcuts with the remote. See [the app library guide](docs/app-library.md).diff --git a/docs/TROUBLESHOOTING.md b/docs/TROUBLESHOOTING.mdindex b23592a85..b3197e246 100644--- a/docs/TROUBLESHOOTING.md+++ b/docs/TROUBLESHOOTING.md@@ -81,6 +81,25 @@ Things that bit us or contributors, so they don't bite you. Commands use `tools/- **Play Protect blocked the launcher** ("unsafe app blocked, built for an older version of Android")and `pm install` hung, then failed with `INSTALL_FAILED_VERIFICATION_FAILURE`, while it targetedSDK 29. It targets 34 now; if you built an old checkout, rebuild.+- **`pm install` fails with `INSTALL_FAILED_OLDER_SDK`** on a set older than the launcher: the APK's+ `minSdk` is a compile-time floor, so a TV on Android 7.0/7.1 (SDK 24/25) cannot take the published+ build at all ([#576](https://github.com/Gathin23/cleanyourtv/issues/576)). Read both numbers before+ changing anything: `tools/tv.py 'getprop ro.build.version.sdk'` and+ `grep minSdk launcher/app/build.gradle` (26, i.e. Android 8.0, at the time of writing).+ `launcher/build-and-install.sh` now asks the TV first and stops with both numbers, so nothing is+ built or pushed for a set that will refuse it; `build-and-install.ps1` only reports it after+ `pm install`, which fails safely with the stock launcher untouched. Lowering `minSdk` is a source+ change, not a setting, and it means maintaining your own copy: the launcher uses AndroidX and+ framework calls newer than API 25, so expect compile errors or a launcher that starts and then+ crashes. An APK produced by rebuilding the project elsewhere (an assistant, an online builder, a+ "rebuilt for API 25" zip from a forum) is not something this repository can check, and the install+ scripts only push the APK they compiled themselves: a build signed with another key does not+ install over this one (`INSTALL_FAILED_UPDATE_INCOMPATIBLE`), so uninstall the old one first if you+ go that way, and keep the stock launcher enabled until the new one really starts. On a set below+ `minSdk` the debloat and privacy half still applies, from the TV's own home screen: it is the+ launcher that cannot be installed, not the lists. If the `Failure [...]` line names+ `INSTALL_FAILED_VERIFICATION_FAILURE` instead, that is the bullet above - the firmware's installer+ verifier, not the API level.- **Screenshots come out empty** while Live TV, an HDMI input or Netflix is on screen, seen on TCLand a [Sony KDL-49W800G](https://github.com/Gathin23/cleanyourtv/issues/92). Press Home before`screencap`. An empty capture means nothing about the ADB connection or playback; check thosediff --git a/examples/README.md b/examples/README.mdindex efc67da78..19f769ec2 100644--- a/examples/README.md+++ b/examples/README.md@@ -79,7 +79,7 @@ on that firmware, grouped and commented. These are starting points: comment out| `sony-bravia-9-ii/` | Sony BRAVIA 9 II (K-65XR90M2, BRAVIA_AE3, MediaTek MT5838) | Google TV 14 | Samba TV ACR, Sony/Qterics device agents, IDD, My BRAVIA promos, Sony Select and Sony tab, demo mode; setupwraith off for the launcher, but it owns Wi-Fi saved during setup and disabling it deletes that network; Chromecast off by choice || `sony-bravia-bf1/` | Sony BRAVIA BF1 (BRAVIA 2 II class, BRAVIA_BF1_4K_A, MediaTek) | Google TV 12 | Samba TV, Sony promos/Select, demo mode, preloaded apps; Home switch in steps (setupwraith), ambient screensaver, applicationdisabler re-enables IoT || `sony-kd-49x8307c/` | Sony BRAVIA KD-49X8307C (2015, "BRAVIA 4K 2015", SVP-DTV15, MediaTek), EU firmware | Android TV 7.0 | MediaTek MT5890 platform: Qterics/Sony device agents, Discover/BIVL recommendation services, Sony shelf, retail demo, help apps, Play Movies; stock launcher is `com.google.android.leanbacklauncher`, not tvlauncher, so pass it to `restore.sh`; `com.sony.dtv.tvx` also plays every HDMI input, keep it; voice and YouView off by choice; 1.5 GB RAM, free RAM increased from ~120 MB to ~500 MB; reboot-checked; list only, the launcher needs Android 8 (minSdk 26, see #146) |-| `sony-kd-55x8509c/` | Sony BRAVIA KD-55X8509C (2015, "BRAVIA 4K 2015", SVP-DTV15, MediaTek), EU firmware | Android TV 7.0 | Oldest chip in the Sony lists: Qterics/Sony device agents, Discover/BIVL and the recommendation services, Sony Select/shelf, retail demo, help apps, dead Video Unlimited; the stock launcher is `com.google.android.leanbacklauncher`, not tvlauncher, so pass it to `restore.sh`; `com.sony.dtv.tvx` also plays every HDMI input, keep it; voice and YouView off by choice; 1.5 GB, 1,144 → 991 MB used RAM; list only, the launcher half needs minSdk 24 (see #104) |+| `sony-kd-55x8509c/` | Sony BRAVIA KD-55X8509C (2015, "BRAVIA 4K 2015", SVP-DTV15, MediaTek), EU firmware | Android TV 7.0 | Oldest chip in the Sony lists: Qterics/Sony device agents, Discover/BIVL and the recommendation services, Sony Select/shelf, retail demo, help apps, dead Video Unlimited; the stock launcher is `com.google.android.leanbacklauncher`, not tvlauncher, so pass it to `restore.sh`; `com.sony.dtv.tvx` also plays every HDMI input, keep it; voice and YouView off by choice; 1.5 GB, 1,144 → 991 MB used RAM; list only, the launcher half needs Android 8 (minSdk 26, see #146) || `sony-kd-55x85j/` | Sony BRAVIA KD-55X85J (2021, BRAVIA_VH2, MediaTek MT5895), South America | Google TV 12 | Same build as the VH2 EU list; Samba TV ACR, Sony/Qterics agents, IDD, Sony promos/Select/tab, partner auto-installs, demo mode; Input key works without the service; setupwraith, launcherx and dreamx off after the launcher, ClockDream screensaver; reboot-checked || `sony-kd-55xe8596/` | Sony BRAVIA KD-55XE8596 (2017, "BRAVIA 4K GB", BRAVIA_ATV2_EU, MediaTek MT5891), UK | Android TV 9 | Same product as `sony-bravia-4k-gb/` on the older S52 build: Samba TV ACR, Sony/Qterics agents, Sony Select/promos/Discover, recommendation rows, partner auto-installs, demo mode, hotel/pro-mode b2b packages; Chromecast, mirroring, DLNA, USB media, Assistant and phone remote kept; UK Live TV hands over to YouView, so launch `com.sony.dtv.tvx`; webapi kept for Home Assistant || `sony-kd-65x80j/` | Sony BRAVIA KD-65X80J (2021, BRAVIA_VH2, MediaTek), India | Google TV 10 | Samba TV, Sony device agents, Sony Select/tab, hotel-mode services, BRAVIA CAM leftovers; setupwraith off for a custom launcher; 4 GB /data fills up, trim caches before installing |diff --git a/launcher/build-and-install.sh b/launcher/build-and-install.shindex 169977997..d28b33d56 100755--- a/launcher/build-and-install.sh+++ b/launcher/build-and-install.sh@@ -3,6 +3,22 @@set -euo pipefailcd "$(dirname "$0")": "${TV_HOST:?set TV_HOST to the TV IP address, e.g. TV_HOST=192.168.1.50 $0}"+TOOLS="$(cd ../tools && pwd)" # absolute, so the venv's Python doesn't warn about "../" in its prefix+PY=$TOOLS/venv/bin/python+[ -x "$PY" ] || PY=$TOOLS/venv/Scripts/python.exe+export MSYS_NO_PATHCONV=1+# Below minSdk, `pm install` refuses the APK with INSTALL_FAILED_OLDER_SDK - and only after gradle has+# spent a minute building and b64push has pushed the APK to the TV (#576). Ask the TV first. The+# number comes from the build file, so it follows the launcher instead of a hard-coded copy here.+MIN_SDK=$(sed -n 's/^[[:space:]]*minSdk[[:space:]][[:space:]]*\([0-9]\{1,3\}\)[[:space:]]*$/\1/p' app/build.gradle 2>/dev/null | head -n 1 || true)+TV_SDK=$("$PY" -I "$TOOLS/tv.py" 'getprop ro.build.version.sdk' 2>/dev/null | tr -dc '0-9' || true)+if [ -n "$MIN_SDK" ] && [ -n "$TV_SDK" ] && [ "$TV_SDK" -lt "$MIN_SDK" ]; then+ echo "ERROR: this TV runs SDK $TV_SDK and the launcher is built with minSdk $MIN_SDK (app/build.gradle)," >&2+ echo "so pm install would answer INSTALL_FAILED_OLDER_SDK. Nothing was built, pushed or disabled." >&2+ echo "The debloat half of the repo still applies to that set, from its own home screen; the launcher" >&2+ echo "half would need your own build with a lower minSdk (docs/TROUBLESHOOTING.md)." >&2+ exit 1+fi# macOS: java_home or Homebrew; Linux: the java on PATH.export JAVA_HOME="${JAVA_HOME:-$(/usr/libexec/java_home -v 17 2>/dev/null || { [ -d /opt/homebrew/opt/openjdk@17 ] && echo /opt/homebrew/opt/openjdk@17; } || java -XshowSettings:properties -version 2>&1 | awk '/java.home/ {print $3}')}"# Android Studio's default SDK location on macOS, then on Linux, then Homebrew's command-line tools.@@ -11,10 +27,6 @@ export ANDROID_HOME="${ANDROID_HOME:-/opt/homebrew/share/android-commandlinetoolexport PATH="$JAVA_HOME/bin:$PATH"[ -f local.properties ] || echo "sdk.dir=$ANDROID_HOME" > local.properties./gradlew assembleRelease -q --console=plain-TOOLS="$(cd ../tools && pwd)" # absolute, so the venv's Python doesn't warn about "../" in its prefix-PY=$TOOLS/venv/bin/python-[ -x "$PY" ] || PY=$TOOLS/venv/Scripts/python.exe-export MSYS_NO_PATHCONV=1# Which app owns Home differs by build (com.google.android.tvlauncher on Android TV,# com.google.android.apps.tv.launcherx on newer Google TV), so ask the TV instead of guessing.# Only a launcher we recognise is accepted: the answer can also be Android's chooser ("android"),@@ -68,6 +80,12 @@ OUT=$("$PY" -I ../tools/tv.py 'pm install -r /data/local/tmp/tvhome.apk; rm -f /echo "$OUT"case "$OUT" in*Success*) ;;+ *INSTALL_FAILED_OLDER_SDK*)+ # The pre-flight above missed it (a TV whose getprop did not answer, or an APK built elsewhere):+ # name the real cause instead of leaving the raw Failure line to be read as an ADB problem.+ echo "ERROR: pm install refused the APK as too new for this set (INSTALL_FAILED_OLDER_SDK): the TV runs an older SDK than the launcher's minSdk ${MIN_SDK:-in app/build.gradle}." >&2+ echo "The stock launcher was left untouched. Read both numbers and see docs/TROUBLESHOOTING.md." >&2+ exit 1 ;;*) echo "ERROR: pm install failed; the stock launcher was left untouched." >&2; exit 1 ;;esac# Start the launcher on its own, before the stock Home is touched. In the batch below a start thatdiff --git a/tests/test_launcher_min_sdk.py b/tests/test_launcher_min_sdk.pynew file mode 100644index 000000000..438935027--- /dev/null+++ b/tests/test_launcher_min_sdk.py@@ -0,0 +1,237 @@+"""The install script asks the TV's SDK level before it builds, and the docs answer #576.++A set older than the launcher's minSdk used to cost a gradle build, a push and a `pm install` that+answered INSTALL_FAILED_OLDER_SDK - a Failure line that reads like an ADB problem. The scripts now+read minSdk from launcher/app/build.gradle (so a lower-minSdk build follows without touching the+shell script) and stop before the build. Both halves are pinned here: the guard against a fake TV,+and the text that explains what is left to do on such a set (#576).++Run from the repository root: python3 -m unittest discover -s tests -v+"""+import json+import os+from pathlib import Path+import re+import shutil+import subprocess+import sys+import tempfile+import unittest+++ROOT = Path(__file__).resolve().parents[1]+STOCK_HOME = "com.google.android.tvlauncher/.MainActivity"+NEW_HOME = "com.gathin.tvhome/.MainActivity"+TROUBLE = ROOT / "docs" / "TROUBLESHOOTING.md"+README = ROOT / "README.md"+EXAMPLES = ROOT / "examples" / "README.md"+PROMPT = ROOT / "PROMPT.md"++# Stands in for tools/tv.py: answers the SDK level, the Home query and pm install, and keeps the+# commands the script sent so a test can prove nothing reached the TV.+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 save():+ with open(STATE_PATH, "w") as f:+ json.dump(state, f)+++def run(command):+ if "getprop ro.build.version.sdk" in command:+ return state["sdk"] + "\n"+ if "pm install" in command:+ return state["install_output"]+ if "am start" in command:+ return "Status: ok\n"+ if "set-home-activity" in command:+ state["home"] = NEW+ return ""+ if "resolve-activity" in command:+ return state["home"] + "\n"+ return ""+++def main():+ args = [a for a in sys.argv[1:] if a != "-I"]+ if any(a.endswith("b64push.py") for a in args):+ print("pushed")+ return 0+ if "--batch" in args:+ commands = [line.strip() for line in sys.stdin+ if line.strip() and not line.strip().startswith("#")]+ elif args:+ commands = [args[-1]]+ else:+ commands = []+ for command in commands:+ state["commands"].append(command)+ sys.stdout.write(run(command))+ sys.stdout.flush()+ save()+ return 0+++sys.exit(main())+'''.replace("NEW", repr(NEW_HOME))+++class MinSdkGuardTest(unittest.TestCase):+ def setUp(self):+ tmp = tempfile.TemporaryDirectory()+ self.addCleanup(tmp.cleanup)+ self.base = Path(tmp.name)+ self.launcher = self.base / "launcher"+ (self.launcher / "app").mkdir(parents=True)+ shutil.copy2(ROOT / "launcher" / "build-and-install.sh", self.launcher)+ self.gradle = self.launcher / "app" / "build.gradle"+ self.gradle.write_text("android {\n defaultConfig {\n minSdk 26\n }\n}\n")+ # The build step only has to leave a marker: no JDK or SDK is involved here.+ self.marker = self.base / "built"+ gradlew = self.launcher / "gradlew"+ gradlew.write_text(f'#!/bin/sh\ntouch "{self.marker}"\n'+ 'mkdir -p app/build/outputs/apk/release\n'+ 'printf apk > app/build/outputs/apk/release/app-release.apk\n')+ gradlew.chmod(0o755)+ tools = self.base / "tools"+ (tools / "venv" / "bin").mkdir(parents=True)+ (tools / "b64push.py").write_text("")+ fake = self.base / "fake_tv.py"+ fake.write_text(FAKE_TV)+ client = tools / "venv" / "bin" / "python"+ client.write_text(f'#!/bin/sh\nexec "{sys.executable}" "{fake}" "$@"\n')+ client.chmod(0o755)+ self.state_path = self.base / "tv-state.json"+ self.home = self.base / "home"+ self.home.mkdir()++ def install(self, **overrides):+ state = {+ "sdk": "34",+ "home": STOCK_HOME,+ "install_output": "Success\n",+ "commands": [],+ }+ state.update(overrides)+ self.state_path.write_text(json.dumps(state))+ env = {k: v for k, v in os.environ.items()+ if k not in ("STOCK_LAUNCHER", "INPUT_KEY_SERVICE", "HOME_KEY_SERVICE")}+ env.update(TV_HOST="192.168.1.50", FAKE_TV_STATE=str(self.state_path),+ HOME=str(self.home), JAVA_HOME=str(self.base / "java"),+ ANDROID_HOME=str(self.base / "android-sdk"))+ result = subprocess.run(+ ["bash", str(self.launcher / "build-and-install.sh")],+ cwd=self.launcher, env=env, capture_output=True, text=True, timeout=180,+ )+ with open(self.state_path) as f:+ state = json.load(f)+ return result, state++ def test_a_tv_below_min_sdk_is_stopped_before_the_build(self):+ result, state = self.install(sdk="25")+ self.assertNotEqual(result.returncode, 0)+ self.assertIn("SDK 25", result.stderr)+ self.assertIn("minSdk 26", result.stderr)+ self.assertIn("INSTALL_FAILED_OLDER_SDK", result.stderr)+ self.assertIn("Nothing was built", result.stderr)+ self.assertFalse(self.marker.exists(), "the APK must not be built for a set that refuses it")+ self.assertEqual(state["commands"], ["getprop ro.build.version.sdk"],+ "the SDK probe is all that may reach the TV")++ def test_a_tv_at_min_sdk_installs(self):+ result, state = self.install(sdk="26")+ self.assertEqual(result.returncode, 0, result.stderr)+ self.assertIn("Installed.", result.stdout)+ self.assertTrue(self.marker.exists())+ self.assertTrue(any("pm install" in c for c in state["commands"]))++ def test_the_number_comes_from_the_build_file(self):+ # What #608 (minSdk 24) changes: the guard has to follow the build file, not a copy of it.+ self.gradle.write_text("android {\n defaultConfig {\n minSdk 24\n }\n}\n")+ result, _ = self.install(sdk="25")+ self.assertEqual(result.returncode, 0, result.stderr)+ self.assertTrue(self.marker.exists())++ def test_an_unanswered_getprop_does_not_block_the_install(self):+ result, _ = self.install(sdk="")+ self.assertEqual(result.returncode, 0, result.stderr)+ self.assertTrue(self.marker.exists())++ def test_a_missing_build_file_does_not_block_the_install(self):+ self.gradle.unlink()+ result, _ = self.install(sdk="25")+ self.assertEqual(result.returncode, 0, result.stderr)++ def test_install_refused_for_the_sdk_names_the_cause(self):+ result, state = self.install(+ sdk="34",+ install_output="Failure [INSTALL_FAILED_OLDER_SDK: Failed parse during installPackageLI: "+ "requires newer sdk version]\n",+ )+ self.assertNotEqual(result.returncode, 0)+ self.assertIn("minSdk 26", result.stderr)+ self.assertIn("stock launcher was left untouched", result.stderr)+ self.assertFalse(any("pm disable-user" in c for c in state["commands"]))+++class Android7DocsTest(unittest.TestCase):+ """The text #576 asked for: what an older set can and cannot do with this repo."""++ def setUp(self):+ self.trouble = re.sub(r"\s+", " ", TROUBLE.read_text(encoding="utf-8"))+ self.readme = re.sub(r"\s+", " ", README.read_text(encoding="utf-8"))+ self.prompt = re.sub(r"\s+", " ", PROMPT.read_text(encoding="utf-8"))++ def test_troubleshooting_has_the_older_sdk_bullet(self):+ self.assertIn("INSTALL_FAILED_OLDER_SDK", self.trouble)+ start = self.trouble.index("INSTALL_FAILED_OLDER_SDK")+ bullet = self.trouble[max(0, start - 200):start + 2200]+ self.assertIn("getprop ro.build.version.sdk", bullet)+ self.assertIn("launcher/app/build.gradle", bullet)+ self.assertIn("#576", bullet)+ # The half that still works has to be named, and so does the one that does not.+ self.assertIn("debloat", bullet.lower())+ self.assertIn("minSdk", bullet)++ def test_troubleshooting_sends_a_rebuilt_apk_elsewhere(self):+ start = self.trouble.index("INSTALL_FAILED_OLDER_SDK")+ bullet = self.trouble[max(0, start - 200):start + 2600]+ self.assertIn("INSTALL_FAILED_VERIFICATION_FAILURE", bullet,+ "the firmware-verifier case is the other reason an install fails")+ self.assertIn("build-and-install.sh", bullet)++ def test_readme_states_the_launcher_requirement_with_a_pointer(self):+ start = self.readme.index("## The launcher")+ section = self.readme[start:start + 1600]+ self.assertIn("API 26", section)+ self.assertIn("launcher/app/build.gradle", section)+ self.assertIn("docs/TROUBLESHOOTING.md", section)++ def test_prompt_tells_an_assistant_not_to_promise_it(self):+ self.assertIn("minSdk", self.prompt)+ self.assertIn("ro.build.version.sdk", self.prompt)++ def test_the_stale_min_sdk_24_row_is_gone(self):+ rows = [line for line in EXAMPLES.read_text(encoding="utf-8").split("\n")+ if line.startswith("| `sony-kd-55x8509c/`")]+ self.assertEqual(len(rows), 1)+ self.assertNotIn("minSdk 24", rows[0])+ self.assertIn("minSdk 26", rows[0])+++if __name__ == "__main__":+ unittest.main()