Skip to content

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

Merge PR #424: theme.sh: switch accessibility off before writing the service list back

Gathin23baf2d7e02b21
diff --cc tools/theme.ps1
index 3d0cc732c,03b36dd0a..3912c8046
--- a/tools/theme.ps1
+++ b/tools/theme.ps1
@@@ -24,20 -24,12 +24,21 @@@ $revision = [guid]::NewGuid().ToString(
# enabled list (asynchronously, so wait a second), which would switch off InputKeyService/HomeKeyService;
# 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"
+ # clear the list, switch accessibility off (some TVs keep the service "crashed" and unbound otherwise), write
+ # the list 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 accessibility_enabled 0; sleep 1; settings put secure enabled_accessibility_services `"`$a`"; settings put secure accessibility_enabled 1 ;; esac"
+# Some firmware (TCL G07, Android 11) locks the shell out of Android/data. Files are staged in
+# /data/local/tmp and copied in, or written through the launcher's ThemeProvider when that is refused.
+$uri = "content://$pkg.theme"
+$tmp = '/data/local/tmp/cyt-theme'
+# A file's staging path; wallpapers/a.jpg is staged as $tmp-wallpapers-a.jpg.
+function Stage($name) { "$tmp-$($name -replace '/', '-')" }
+function Put($name) { $t = Stage $name; "cp $t $dir/$name 2>/dev/null || content write --uri $uri/$name < $t; rm -f $t" }
+function Del($name) { "rm -f $dir/$name 2>/dev/null; content delete --uri $uri/$name 2>/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; $restart; echo reset"
+ & $py -I tv.py "mkdir -p $dir 2>/dev/null; $(Del 'config.json'); $(Del 'wallpaper.jpg'); printf '%s' '$revision' > $tmp-theme_revision; $(Put 'theme_revision'); $restart; echo reset"
exit 0
}
if (-not $Theme) { throw 'usage: theme.ps1 <theme folder> | -Reset' }
diff --cc tools/theme.sh
index 2c260a9a0,d2e159592..889a8b699
--- a/tools/theme.sh
+++ b/tools/theme.sh
@@@ -27,20 -27,13 +27,22 @@@ tv() { "$PY" -I tv.py "$@";
# Android removes them asynchronously while it handles the restart, so wait a second before writing the
# 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"
+ # back and switch accessibility on again as build-and-install does. Some TVs (TCL Smart TV Pro G03, Android 11)
+ # also keep the service in their "crashed" list after the force-stop and leave it unbound until accessibility
+ # itself goes off and on again, so switch it off with the list cleared and wait a second before writing back.
+ 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 accessibility_enabled 0; sleep 1; settings put secure enabled_accessibility_services \"\$a\"; settings put secure accessibility_enabled 1 ;; esac"
+# Some firmware (TCL G07, Android 11) locks the shell out of Android/data. Files are staged in
+# /data/local/tmp and copied in, or written through the launcher's ThemeProvider when that is refused.
+URI=content://$PKG.theme
+TMP=/data/local/tmp/cyt-theme
+# A file's staging path; wallpapers/a.jpg is staged as $TMP-wallpapers-a.jpg.
+stage() { echo "$TMP-${1//\//-}"; }
+put() { echo "cp $(stage "$1") $DIR/$1 2>/dev/null || content write --uri $URI/$1 < $(stage "$1"); rm -f $(stage "$1")"; }
+del() { echo "rm -f $DIR/$1 2>/dev/null; content delete --uri $URI/$1 2>/dev/null"; }
+
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
+ tv "mkdir -p $DIR 2>/dev/null; $(del config.json); $(del wallpaper.jpg); printf '%s' '$REVISION' > $TMP-theme_revision; $(put theme_revision); $RESTART; echo reset" | tail -n 1
exit 0
fi
THEME="${THEME_ARG:?usage: theme.sh <theme folder> | --reset}"