Skip to content

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

tools: start cold benchmarks in the Home task

MIDHAT NASHAR203a553174f1
diff --git a/tests/test_bench_accessibility.py b/tests/test_bench_accessibility.py
index 652cbf291..e3297643c 100644
--- a/tests/test_bench_accessibility.py
+++ b/tests/test_bench_accessibility.py
@@ -84,7 +84,7 @@ class ColdStartOrderTest(unittest.TestCase):
def spy(command, read_timeout_s=None):
if command.startswith("settings put secure enabled_accessibility_services"):
order.append("restore")
- elif command.startswith("am start -W -n com.gathin.tvhome"):
+ elif command.startswith("am start -W ") and command.endswith("-n com.gathin.tvhome/.MainActivity"):
order.append("measure")
return original_shell(command, read_timeout_s)
tv.shell = spy
diff --git a/tests/test_bench_home.py b/tests/test_bench_home.py
index ad24fb751..d395318db 100644
--- a/tests/test_bench_home.py
+++ b/tests/test_bench_home.py
@@ -125,5 +125,29 @@ class ReturnToHomeTest(unittest.TestCase):
self.assertEqual(values, [0])
+class ColdStartHomeTest(unittest.TestCase):
+ def test_each_cold_start_targets_the_home_task_and_keeps_wait_time(self):
+ for component in (COMPONENT, "com.example.home/.Launcher"):
+ with self.subTest(component=component):
+ tv = mock.Mock()
+ tv.package_of.return_value = component.split("/")[0]
+ launch = ("am start -W -a android.intent.action.MAIN "
+ f"-c android.intent.category.HOME -n {component}")
+ waits = iter(("WaitTime: 410", "WaitTime: 430"))
+ tv.shell.side_effect = lambda command: next(waits) if command == launch else ""
+ with mock.patch.object(bench, "other_app", return_value=OTHER), \
+ mock.patch.object(bench, "accessibility_services", return_value=[]), \
+ mock.patch.object(bench, "restore_accessibility") as restore, \
+ mock.patch.object(bench.time, "sleep"):
+ values = bench.cold_start(tv, component, 2)
+ self.assertEqual(values, [410, 430])
+ self.assertEqual(tv.shell.call_args_list, [
+ mock.call(f"am start -W -n {OTHER}"),
+ mock.call(f"am force-stop {component.split('/')[0]}"),
+ mock.call(launch),
+ ] * 2)
+ restore.assert_called_once_with(tv, component.split("/")[0], [])
+
+
if __name__ == "__main__":
unittest.main()
diff --git a/tests/test_trace.py b/tests/test_trace.py
index 557a0d2fd..7d8e769ac 100644
--- a/tests/test_trace.py
+++ b/tests/test_trace.py
@@ -81,7 +81,8 @@ class ScenarioTest(unittest.TestCase):
def test_cold_stops_the_launcher_before_recording_and_starts_it_inside(self):
setup, steps = trace.scenario("cold", LAUNCHER, OTHER)
self.assertIn("am force-stop com.gathin.tvhome", setup)
- self.assertEqual(steps[0], f"am start -W -n {LAUNCHER}")
+ self.assertEqual(steps[0], "am start -W -a android.intent.action.MAIN "
+ f"-c android.intent.category.HOME -n {LAUNCHER}")
def test_coldsys_leaves_the_restart_to_android(self):
setup, steps = trace.scenario("coldsys", LAUNCHER, None)
diff --git a/tools/bench.py b/tools/bench.py
index 05ec974eb..f4b49c185 100644
--- a/tools/bench.py
+++ b/tools/bench.py
@@ -377,7 +377,10 @@ def cold_start(tv, component, repeats):
time.sleep(2)
tv.shell(f"am force-stop {package}")
time.sleep(3)
- out = tv.shell(f"am start -W -n {component}")
+ # An explicit component alone creates a regular task. Start the HOME task,
+ # so the next Home press cannot create a second launcher instance.
+ out = tv.shell(f"am start -W -a android.intent.action.MAIN "
+ f"-c android.intent.category.HOME -n {component}")
match = re.search(r"WaitTime:\s*(\d+)", out)
if match:
values.append(int(match.group(1)))
diff --git a/tools/trace.md b/tools/trace.md
index 4e749c1a9..9eef08660 100644
--- a/tools/trace.md
+++ b/tools/trace.md
@@ -70,6 +70,9 @@ and GPU waits where available; a draw's duration is not the full frame time.
- **Keep starred runs.** They're usually memory pressure on a 1 GB TV. Report them; don't drop them.
- **Don't run `am start` after a force-stop with Home in front.** Android has already restarted Home, so
`onResume` appears twice. Use `cold` or `coldsys`.
+- **Cold starts use the HOME intent.** `bench.py` and the `cold` trace send `MAIN` with the `HOME`
+ category. Starting only the component can create a regular task beside the Home task, so a later
+ Home press creates another instance. Compare runs recorded with the same launch command.
- **Check the remote afterwards.** A force-stop switches off the accessibility helpers. `trace.py` puts the
list back after the last run, but on some TCL sets a helper still won't bind (`docs/TROUBLESHOOTING.md`).
- **Look in the right place for GPU savings.** Less overdraw shows as GPU wait in `nav`, not as main-thread
diff --git a/tools/trace.py b/tools/trace.py
index 35c9b22e3..047ff0556 100644
--- a/tools/trace.py
+++ b/tools/trace.py
@@ -95,7 +95,8 @@ def scenario(name, launcher_component, other_component, setup=(), steps=()):
other = f"am start -n {other_component}" if other_component else None
if name == "cold":
return [other, "sleep 2", f"am force-stop {package}", "sleep 2"], \
- [f"am start -W -n {launcher_component}", "sleep 4"]
+ [f"am start -W -a android.intent.action.MAIN "
+ f"-c android.intent.category.HOME -n {launcher_component}", "sleep 4"]
if name == "coldsys":
return ["input keyevent KEYCODE_HOME", "sleep 2"], [f"am force-stop {package}", "sleep 5"]
if name == "home":