Skip to content

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

Merge PR #211: theme pushes keep the accessibility helpers enabled

Gathin237a23d682cf17
diff --cc tools/theme.ps1
index 566a22d2b,8001a0bfe..98a45b46d
--- a/tools/theme.ps1
+++ b/tools/theme.ps1
@@@ -19,10 -19,12 +19,14 @@@ $py = 'venv\Scripts\python.exe
if (-not (Test-Path $py)) { throw 'run: python -m venv tools\venv; tools\venv\Scripts\python.exe -m pip install -r tools\requirements.txt' }
$pkg = 'com.gathin.tvhome'
$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, which would switch off InputKeyService/HomeKeyService, so put the list back if it had ours.
-$restart = "a=`$(settings get secure enabled_accessibility_services); am force-stop $pkg; case `"`$a`" in *$pkg*) settings put secure enabled_accessibility_services `"`$a`" ;; esac; am start -n $pkg/.MainActivity >/dev/null"
++# 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"
if ($Reset) {
- & $py -I tv.py "mkdir -p $dir; rm -f $dir/config.json $dir/wallpaper.jpg; printf '%s' '$revision' > $dir/theme_revision; am force-stop $pkg; am start -n $pkg/.MainActivity >/dev/null; echo reset"
- & $py -I tv.py "rm -f $dir/config.json $dir/wallpaper.jpg; $restart; echo 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"
exit 0
}
if (-not $Theme) { throw 'usage: theme.ps1 <theme folder> | -Reset' }
@@@ -34,6 -36,5 +38,6 @@@ try { Get-Content $config -Raw | Conver
& $py -I tv.py --push $config "$dir/config.json"
$wall = Join-Path $Theme 'wallpaper.jpg'
if (Test-Path $wall) { & $py -I b64push.py $wall "$dir/wallpaper.jpg" } else { & $py -I tv.py "rm -f $dir/wallpaper.jpg" | Out-Null }
+& $py -I tv.py "printf '%s' '$revision' > $dir/theme_revision" | Out-Null
- & $py -I tv.py "am force-stop $pkg; am start -n $pkg/.MainActivity >/dev/null; echo applied"
+ & $py -I tv.py "$restart; echo applied"
Write-Host "Theme $(Split-Path $Theme -Leaf) is on the TV. Undo with: tools\theme.ps1 -TvHost $TvHost -Reset"
diff --cc tools/theme.sh
index 4dd7052eb,95c836ad6..f7b1fcf9b
--- a/tools/theme.sh
+++ b/tools/theme.sh
@@@ -17,13 -17,13 +17,18 @@@ PY=venv/bin/pytho
export MSYS_NO_PATHCONV=1
PKG=com.gathin.tvhome
DIR=/sdcard/Android/data/$PKG/files
+# A unique marker lets the launcher clear on-TV layout/motion choices after every theme push,
+# including a push of identical config.json bytes and --reset.
+REVISION="$("$PY" -I -c 'import uuid; print(uuid.uuid4().hex)')"
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.
-RESTART="a=\$(settings get secure enabled_accessibility_services); am force-stop $PKG; case \"\$a\" in *$PKG*) settings put secure enabled_accessibility_services \"\$a\" ;; esac; am start -n $PKG/.MainActivity >/dev/null"
++# 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"
if [ "${1:-}" = --reset ]; then
- tv "mkdir -p $DIR; rm -f $DIR/config.json $DIR/wallpaper.jpg; printf '%s' '$REVISION' > $DIR/theme_revision; am force-stop $PKG; am start -n $PKG/.MainActivity >/dev/null; echo reset" | tail -n 1
- tv "rm -f $DIR/config.json $DIR/wallpaper.jpg; $RESTART; echo reset" | tail -n 1
++ tv "mkdir -p $DIR; rm -f $DIR/config.json $DIR/wallpaper.jpg; printf '%s' '$REVISION' > $DIR/theme_revision; $RESTART; echo reset" | tail -n 1
exit 0
fi
THEME="${THEME_ARG:?usage: theme.sh <theme folder> | --reset}"
@@@ -38,6 -38,5 +43,6 @@@ if [ -f "$THEME/wallpaper.jpg" ]; the
else
tv "rm -f $DIR/wallpaper.jpg" >/dev/null
fi
+tv "printf '%s' '$REVISION' > $DIR/theme_revision" >/dev/null
- tv "am force-stop $PKG; am start -n $PKG/.MainActivity >/dev/null; echo applied" | tail -n 1
+ tv "$RESTART; echo applied" | tail -n 1
echo "Theme $(basename "$THEME") is on the TV. Undo with: tools/theme.sh --reset"