Skip to content

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

addons: start Smart Home before writing config

GaneshVarma11560649c027d
diff --git a/addons/smart-home/install.sh b/addons/smart-home/install.sh
index b51e7afd6..b74b26b85 100755
--- a/addons/smart-home/install.sh
+++ b/addons/smart-home/install.sh
@@ -32,7 +32,10 @@ case "$OUT" in *Success*) ;; *) echo "ERROR: pm install failed" >&2; exit 1 ;; e
if [ -n "$CONFIG" ]; then
STAGE=/data/local/tmp/smart-home-config.json
tv --push "$CONFIG" "$STAGE" >/dev/null
- # The provider can take a moment to appear after pm install. tv.py does not pass the remote
+ # On some TVs the shell cannot start this provider until the app is running.
+ # Start it before writing, then allow its process to come up.
+ tv "am start -n $PKG/.MainActivity >/dev/null; sleep 2; echo opened"
+ # The provider can take a moment to appear after the app starts. tv.py does not pass the remote
# shell's exit status through, so require a success marker from content write itself. Android's
# content command can print a provider error and still exit 0, so success must also be silent.
OUT=$(tv "ok=0; for attempt in 1 2 3; do if write_out=\$(content write --user 0 --uri content://$PKG.config/config.json < $STAGE 2>&1) && [ -z \"\$write_out\" ]; then ok=1; break; fi; [ -z \"\$write_out\" ] || printf '%s\n' \"\$write_out\"; [ \"\$attempt\" -eq 3 ] || sleep 1; done; if rm -f $STAGE && [ \"\$ok\" -eq 1 ]; then echo __SMART_HOME_CONFIG_OK__; fi")
diff --git a/tests/test_smart_home_install.py b/tests/test_smart_home_install.py
index 1ce434626..fadd2c196 100644
--- a/tests/test_smart_home_install.py
+++ b/tests/test_smart_home_install.py
@@ -55,7 +55,7 @@ else:
bin_dir.mkdir()
for name, body in {
"pm": '#!/bin/sh\necho Success\n',
- "am": '#!/bin/sh\nexit 0\n',
+ "am": '#!/bin/sh\ntouch "$FAKE_ROOT/app-running"\nexit 0\n',
"sleep": '#!/bin/sh\nexit 0\n',
"content": '''#!/bin/sh
count_file="$FAKE_ROOT/count"
@@ -64,6 +64,7 @@ count=$((count + 1))
echo "$count" > "$count_file"
case "$CONTENT_MODE" in
success) exit 0 ;;
+ provider_requires_launch) if [ -f "$FAKE_ROOT/app-running" ]; then exit 0; fi; echo 'Could not find provider' >&2; exit 0 ;;
error_then_success) if [ "$count" -lt 3 ]; then echo 'Could not find provider' >&2; fi; exit 0 ;;
error) echo 'Could not find provider' >&2; exit 0 ;;
nonzero) echo 'write failed' >&2; exit 1 ;;
@@ -102,6 +103,12 @@ esac
self.assertIn("config pushed", result.stdout)
self.assertFalse((self.root / "smart-home-config.json").exists())
+ def test_provider_that_requires_running_app_receives_config(self):
+ result = self.install("provider_requires_launch")
+ self.assertEqual(result.returncode, 0, result.stderr)
+ self.assertEqual(self.attempts(), 1)
+ self.assertIn("config pushed", result.stdout)
+
def test_silent_success_needs_one_attempt(self):
result = self.install("success")
self.assertEqual(result.returncode, 0, result.stderr)