Skip to content

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

theme scripts: restart Home first, then make the accessibility helper rebind

Samuel Hinton6a134907df98
diff --git a/tools/theme.ps1 b/tools/theme.ps1
index 98a45b46d..aef09ae05 100644
--- a/tools/theme.ps1
+++ b/tools/theme.ps1
@@ -22,8 +22,10 @@ $dir = "/sdcard/Android/data/$pkg/files"
$revision = [guid]::NewGuid().ToString('N')
# Restart Home so it rereads the theme. Android drops a force-stopped app's accessibility services from the
# enabled list (asynchronously, so wait a second), which would switch off InputKeyService/HomeKeyService;
-# put the list back if it had ours and switch accessibility on again.
-$restart = "a=`$(settings get secure enabled_accessibility_services); am force-stop $pkg; case `"`$a`" in *$pkg*) sleep 1; settings put secure enabled_accessibility_services `"`$a`"; settings put secure accessibility_enabled 1 ;; esac; am start -n $pkg/.MainActivity >/dev/null"
+# put the list back if it had ours. Writing the same list back is not enough: the force-stop also turns
+# accessibility_enabled off, and the service only binds again once the list changes. So restart first, then
+# clear the list, write it back and switch accessibility on again.
+$restart = "a=`$(settings get secure enabled_accessibility_services); am force-stop $pkg; am start -n $pkg/.MainActivity >/dev/null; case `"`$a`" in *$pkg*) sleep 1; settings put secure enabled_accessibility_services ''; settings put secure enabled_accessibility_services `"`$a`"; settings put secure accessibility_enabled 1 ;; esac"
if ($Reset) {
& $py -I tv.py "mkdir -p $dir; rm -f $dir/config.json $dir/wallpaper.jpg; printf '%s' '$revision' > $dir/theme_revision; $restart; echo reset"
diff --git a/tools/theme.sh b/tools/theme.sh
index f7b1fcf9b..26f56fab9 100755
--- a/tools/theme.sh
+++ b/tools/theme.sh
@@ -24,8 +24,10 @@ tv() { "$PY" -I tv.py "$@"; }
# Restart Home so it rereads the theme. Android drops a force-stopped app's accessibility services from the
# enabled list, which would switch off InputKeyService/HomeKeyService, so put the list back if it had ours.
# Android removes them asynchronously while it handles the restart, so wait a second before writing the
-# list back, and switch accessibility on again as build-and-install does.
-RESTART="a=\$(settings get secure enabled_accessibility_services); am force-stop $PKG; case \"\$a\" in *$PKG*) sleep 1; settings put secure enabled_accessibility_services \"\$a\"; settings put secure accessibility_enabled 1 ;; esac; am start -n $PKG/.MainActivity >/dev/null"
+# list back. Writing the same list back is not enough: the force-stop also turns accessibility_enabled off,
+# and the service only binds again once the list changes. So restart first, then clear the list, write it
+# back and switch accessibility on again as build-and-install does.
+RESTART="a=\$(settings get secure enabled_accessibility_services); am force-stop $PKG; am start -n $PKG/.MainActivity >/dev/null; case \"\$a\" in *$PKG*) sleep 1; settings put secure enabled_accessibility_services ''; settings put secure enabled_accessibility_services \"\$a\"; settings put secure accessibility_enabled 1 ;; esac"
if [ "${1:-}" = --reset ]; then
tv "mkdir -p $DIR; rm -f $DIR/config.json $DIR/wallpaper.jpg; printf '%s' '$REVISION' > $DIR/theme_revision; $RESTART; echo reset" | tail -n 1