Skip to content

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

Home guard: a factory-test app is not another Home

Gathin23035754649a78
diff --git a/README.md b/README.md
index d8f20ef0f..5c9c3f5fa 100644
--- a/README.md
+++ b/README.md
@@ -385,7 +385,8 @@ The install scripts ask the TV which launcher owns Home and only disable one the
`tools/disable.sh` (`disable.ps1`) applies the same rule before it disables anything: if the list
contains the app that owns Home and no other app on the TV answers HOME, it skips that entry, says
-why, and disables the rest of the list. So a list applied before the launcher handover cannot leave
+why, and disables the rest of the list. The setup wizard, the settings apps, a vendor `FallbackHome`
+and factory-test apps (Xiaomi's `com.duokan.factorytest`) answer HOME too and don't count. So a list applied before the launcher handover cannot leave
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.
@@ -612,7 +613,8 @@ and says so.
It runs the same safety checks as `tools/disable.sh` before it disables anything, since an update is
the moment they matter again: it leaves setupwraith on while the saved Wi-Fi network belongs to it
(`FORCE_SETUPWRAITH=1` on Ethernet), leaves the packages under the HDMI/AV inputs on
-(`TVINPUT_ALLOW=1` if you really want them off), and never takes Home to a vendor `FallbackHome`.
+(`TVINPUT_ALLOW=1` if you really want them off), and never takes Home to a vendor `FallbackHome` or
+a factory-test app.
Each package it leaves on comes with the reason and exits 1, because the TV is not back to the list
until you deal with that one by hand.
diff --git a/docs/TROUBLESHOOTING.md b/docs/TROUBLESHOOTING.md
index aaa4a0056..9527a4e55 100644
--- a/docs/TROUBLESHOOTING.md
+++ b/docs/TROUBLESHOOTING.md
@@ -196,7 +196,10 @@ Things that bit us or contributors, so they don't bite you. Commands use `tools/
`tools/disable.sh` now does that check itself: when the list holds the app that owns Home and
nothing else on the TV answers HOME, it skips that entry and says so (`FORCE_HOME=1` overrides),
so applying a list before the handover no longer leaves the TV without a launcher. Apply the list
- again after the install script has made the new launcher Home to disable the old one.
+ again after the install script has made the new launcher Home to disable the old one. A factory
+ test app does not count as something else: on a Xiaomi Mi TV 4A
+ `com.duokan.factorytest/.FactoryLauncher` answers HOME, so the guard leaves it out, along with any
+ package named `*factorytest*`, `*factory_test*` or `*factorymode*`.
- **The TV stays on the boot logo with ADB gone** after a list, seen on a KitKat-era set
([COOP COTV-0001](https://github.com/Gathin23/cleanyourtv/issues/795): Realtek `rtd298x`, Android
4.4.2, SDK 19). 17 packages were disabled over Ethernet ADB, each answered `new state:
diff --git a/tests/test_drift_check.py b/tests/test_drift_check.py
index 9c9aa10c1..9f287277a 100644
--- a/tests/test_drift_check.py
+++ b/tests/test_drift_check.py
@@ -358,6 +358,19 @@ class DriftCheckTest(unittest.TestCase):
self.assertIn(f"Home: set to {CUSTOM}/.MainActivity", result.stdout)
self.assertNotIn(FALLBACK, " ".join(self.sent()))
+ def test_fix_does_not_take_home_to_a_factory_test_app(self):
+ # com.duokan.factorytest/.FactoryLauncher answers HOME on a Xiaomi Mi TV 4A; Home on it is the
+ # factory test screen, so with no launcher left --fix changes nothing rather than move Home there.
+ self.write_list(["com.example.music", STOCK])
+ self.tv(installed=["com.example.music", "com.example.store", STOCK, "com.duokan.factorytest"],
+ disabled=["com.example.music", "com.example.store"],
+ home=f"{STOCK}/.MainActivity",
+ home_activities=[FACTORY, f"{STOCK}/.MainActivity"])
+ result = self.run_check("--fix", str(self.list_path))
+ self.assertEqual(result.returncode, 1)
+ self.assertIn("launcher/build-and-install.sh", result.stdout)
+ self.assertNotIn("set-home-activity", " ".join(self.sent()))
+
def test_fix_refuses_a_home_only_a_fallback_can_take(self):
self.write_list(["com.example.music", STOCK])
self.tv(installed=["com.example.music", "com.example.store", STOCK, "com.tcl.tv"],
@@ -394,6 +407,8 @@ MEDIATEK_INPUT = "com.mediatek.tvinput"
BASE = ["com.example.music", "com.example.store", STOCK, CUSTOM]
# What a TCL set shows when no launcher is enabled; not a home the viewer can use.
FALLBACK = "com.tcl.keycustomfunctionservice/.FallbackHome"
+# Xiaomi's factory test, which answers HOME on a Mi TV 4A.
+FACTORY = "com.duokan.factorytest/.FactoryLauncher"
if __name__ == "__main__":
diff --git a/tests/test_home_guard.py b/tests/test_home_guard.py
index 5aa6c804d..5a2218974 100644
--- a/tests/test_home_guard.py
+++ b/tests/test_home_guard.py
@@ -223,6 +223,21 @@ class HomeGuardTest(unittest.TestCase):
"a vendor fallback is not a launcher to fall back on")
self.assertIn(f"Skipping {STOCK}", self.output(result))
+ def test_a_factory_test_app_does_not_count_as_another_home(self):
+ # A Xiaomi Mi TV 4A answers the HOME query with com.duokan.factorytest/.FactoryLauncher next to
+ # the launcher and a FallbackHome. Counting the factory test as another Home let a list disable
+ # the owner and hand Home to the factory test screen.
+ for entry in self.entries():
+ for factory in ("com.duokan.factorytest/.FactoryLauncher", "com.example.factory_test/.Main",
+ "com.mediatek.factorymode/.FactoryHome"):
+ with self.subTest(entry=entry, factory=factory):
+ self.tv(claims=[factory, STOCK, "com.android.tv.settings/.system.FallbackHome"])
+ result, sent = self.disable(entry)
+ self.assertEqual(result.returncode, 0, self.output(result))
+ self.assertNotIn(f"pm disable-user --user 0 {STOCK}", sent,
+ "a factory test app is not a launcher to fall back on")
+ self.assertIn(f"Skipping {STOCK}", self.output(result))
+
def test_a_tv_that_cannot_list_its_homes_is_left_with_one(self):
# tv.py fails or the TV answers nothing: the owner is the only Home this run knows about.
for entry in self.entries():
diff --git a/tools/check.py b/tools/check.py
index c2f54cb91..b63e131e1 100644
--- a/tools/check.py
+++ b/tools/check.py
@@ -38,6 +38,9 @@ NOT_LAUNCHERS = {"com.google.android.tungsten.setupwraith", "com.android.tv.sett
# com.android.tv.settings/.system.FallbackHome). disable.sh already refuses to count one as a
# launcher (#435); --fix must not move Home onto one either, or the next boot lands in the placeholder.
FALLBACK_HOME_RE = re.compile(r"/\S*FallbackHome$")
+# A factory-test app is not one either: com.duokan.factorytest/.FactoryLauncher answers HOME on a
+# Xiaomi Mi TV 4A, and Home on it is the factory test screen (disable.sh skips these too).
+FACTORY_HOME_RE = re.compile(r"factorytest|factory_test|factorymode", re.I)
# The first-run wizard's app. Android deletes a Wi-Fi network saved by it the moment it is disabled.
SETUPWRAITH = "com.google.android.tungsten.setupwraith"
INPUT_PERMISSION = "android.permission.TV_INPUT_HARDWARE"
@@ -82,7 +85,7 @@ def launcher_to_use(dev, listed, preferred=None):
return match[0]
candidates = [c for c in home_activities(dev)
if home_of(c) not in listed and home_of(c) not in NOT_LAUNCHERS
- and not FALLBACK_HOME_RE.search(c)]
+ and not FALLBACK_HOME_RE.search(c) and not FACTORY_HOME_RE.search(home_of(c))]
if not candidates:
return None
own = [c for c in candidates if home_of(c) == recovery.CUSTOM_LAUNCHER]
diff --git a/tools/disable.ps1 b/tools/disable.ps1
index 26cd0cfd2..796890736 100644
--- a/tools/disable.ps1
+++ b/tools/disable.ps1
@@ -78,7 +78,8 @@ if (-not $env:FORCE_HOME) {
} | Sort-Object -Unique)
# The setup wizard and the settings apps answer HOME too, but they are not launchers (disable.sh).
$notLaunchers = @('com.google.android.tungsten.setupwraith', 'com.android.tv.settings', 'com.android.settings', 'com.android.provision')
- $others = @($claims | Where-Object { $_ -ne $homePkg -and $pkgs -notcontains $_ -and $notLaunchers -notcontains $_ })
+ # Nor is a factory-test app (com.duokan.factorytest/.FactoryLauncher answers HOME on a Mi TV 4A).
+ $others = @($claims | Where-Object { $_ -ne $homePkg -and $pkgs -notcontains $_ -and $notLaunchers -notcontains $_ -and $_ -notmatch 'factorytest|factory_test|factorymode' })
if ($others.Count -eq 0) {
Write-Warning "Skipping ${homePkg}: it owns Home, and no other app that can answer Home is installed and staying enabled. Make the new launcher Home first (launcher\build-and-install.ps1), then run this list again to disable the old one; or set `$env:FORCE_HOME=1 if you can still reach the TV."
$pkgs = @($pkgs | Where-Object { $_ -ne $homePkg })
diff --git a/tools/disable.sh b/tools/disable.sh
index 915dcd181..7a978817a 100755
--- a/tools/disable.sh
+++ b/tools/disable.sh
@@ -86,7 +86,10 @@ if [ -n "$HOME_PKG" ] && printf '%s\n' "$PKGS" | grep -xF "$HOME_PKG" >/dev/null
# A vendor's own fallback does not count either: TCL Android TV sets register
# com.tcl.keycustomfunctionservice/.FallbackHome (and com.android.tv.settings/.system.FallbackHome),
# a placeholder the firmware shows when no launcher is enabled, not a home the viewer can use.
+ # Nor does a factory-test app: on a Xiaomi Mi TV 4A com.duokan.factorytest/.FactoryLauncher answers
+ # HOME, and handing Home to it leaves the viewer on the factory test screen.
OTHERS=$(printf '%s\n' "$CLAIMS" | grep -vE '/[^ ]*FallbackHome$' | cut -d/ -f1 | sort -u \
+ | grep -viE 'factorytest|factory_test|factorymode' \
| grep -vxF "$HOME_PKG" | grep -vxF "$PKGS" \
| grep -vxF -e com.google.android.tungsten.setupwraith -e com.android.tv.settings -e com.android.settings -e com.android.provision || true)
if [ -z "$OTHERS" ]; then