Skip to content

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

tools: reuse the other activity during launcher measurements

MIDHAT NASHAR9ac17b490d5d
diff --git a/tests/test_bench_home.py b/tests/test_bench_home.py
index d395318db..c6bb49cdf 100644
--- a/tests/test_bench_home.py
+++ b/tests/test_bench_home.py
@@ -44,7 +44,7 @@ class LogTV:
raise AssertionError(f"unexpected grep arguments: {grep}")
return "\n".join(line for line in next(self.logs)
if any(re.search(pattern, line) for pattern in args[1::2]))
- if command in (f"am start -W -n {OTHER}", "logcat -c -b main", "input keyevent 3"):
+ if command in (f"am start -W --activity-reorder-to-front -n {OTHER}", "logcat -c -b main", "input keyevent 3"):
return ""
raise AssertionError(f"unexpected shell command: {command}")
@@ -68,7 +68,7 @@ class ReturnToHomeTest(unittest.TestCase):
values, commands = self.measure([home(), resume(tag=tag, extra=extra)],
component=component)
self.assertEqual(values, [125])
- self.assertEqual(commands[:3], [f"am start -W -n {OTHER}",
+ self.assertEqual(commands[:3], [f"am start -W --activity-reorder-to-front -n {OTHER}",
"logcat -c -b main", "input keyevent 3"])
def test_an_old_resume_without_a_current_resume_is_not_a_sample(self):
@@ -142,7 +142,7 @@ class ColdStartHomeTest(unittest.TestCase):
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 start -W --activity-reorder-to-front -n {OTHER}"),
mock.call(f"am force-stop {component.split('/')[0]}"),
mock.call(launch),
] * 2)
diff --git a/tests/test_trace.py b/tests/test_trace.py
index 7d8e769ac..5fe5f72c1 100644
--- a/tests/test_trace.py
+++ b/tests/test_trace.py
@@ -75,11 +75,12 @@ class FakeDevice:
class ScenarioTest(unittest.TestCase):
def test_setup_stays_out_of_the_recording(self):
setup, steps = trace.scenario("home", LAUNCHER, OTHER)
- self.assertIn(f"am start -n {OTHER}", setup)
+ self.assertIn(f"am start --activity-reorder-to-front -n {OTHER}", setup)
self.assertEqual(steps, ["input keyevent KEYCODE_HOME", "sleep 4"])
def test_cold_stops_the_launcher_before_recording_and_starts_it_inside(self):
setup, steps = trace.scenario("cold", LAUNCHER, OTHER)
+ self.assertIn(f"am start --activity-reorder-to-front -n {OTHER}", setup)
self.assertIn("am force-stop com.gathin.tvhome", setup)
self.assertEqual(steps[0], "am start -W -a android.intent.action.MAIN "
f"-c android.intent.category.HOME -n {LAUNCHER}")
diff --git a/tools/bench.py b/tools/bench.py
index f4b49c185..fccf63b5f 100644
--- a/tools/bench.py
+++ b/tools/bench.py
@@ -373,7 +373,9 @@ def cold_start(tv, component, repeats):
services = accessibility_services(tv, package)
try:
for _ in range(repeats):
- tv.shell(f"am start -W -n {other}")
+ # Reuse Settings even if its task was first opened with ACTION_SETTINGS.
+ # A component-only start can otherwise stack another activity on every run.
+ tv.shell(f"am start -W --activity-reorder-to-front -n {other}")
time.sleep(2)
tv.shell(f"am force-stop {package}")
time.sleep(3)
@@ -403,7 +405,7 @@ def return_to_home(tv, component, repeats):
if class_name.startswith("."):
class_name = component.split("/", 1)[0] + class_name
for _ in range(repeats):
- tv.shell(f"am start -W -n {other}")
+ tv.shell(f"am start -W --activity-reorder-to-front -n {other}")
time.sleep(3)
clear_log(tv)
tv.shell("input keyevent 3")
diff --git a/tools/trace.md b/tools/trace.md
index 9eef08660..b057f56c9 100644
--- a/tools/trace.md
+++ b/tools/trace.md
@@ -35,7 +35,10 @@ TV_HOST=<tv ip> tools/venv/bin/python -I tools/trace.py home --runs 5 --out trac
- **Output:** each run writes `<scenario>-<n>.pftrace` (10–20 MB) and a `.json` with the commands and the
TV's model and build. `traces/` is gitignored.
-- **The other app:** `--app package/activity`, or by default the TV's Settings.
+- **The other app:** `--app package/activity`, or by default the TV's Settings. Both this tool and
+ `bench.py` bring an existing instance to the front across runs, rather than stacking new Settings
+ activities. They do not clear the other app's data or force-stop it. Check that it is responsive
+ after a long session; an already accumulated history is not removed by this flag.
## Report
diff --git a/tools/trace.py b/tools/trace.py
index 047ff0556..ea4215530 100644
--- a/tools/trace.py
+++ b/tools/trace.py
@@ -92,7 +92,8 @@ def recording_ms(steps):
def scenario(name, launcher_component, other_component, setup=(), steps=()):
"""(setup, steps) shell commands for a scenario. Setup runs before the recording starts."""
package = launcher_component.split("/")[0]
- other = f"am start -n {other_component}" if other_component else None
+ # Reuse the other activity across runs instead of growing its task history.
+ other = f"am start --activity-reorder-to-front -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 -a android.intent.action.MAIN "