Skip to content

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

theme.sh, theme.ps1: restart through the Home intent when the launcher is Home

Caner1a0ff66e2315
diff --git a/tools/theme.ps1 b/tools/theme.ps1
index 00d15ee61..2a9f91598 100644
--- a/tools/theme.ps1
+++ b/tools/theme.ps1
@@ -25,8 +25,10 @@ $revision = [guid]::NewGuid().ToString('N')
# 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, 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"
+# the list back and switch accessibility on again. When the launcher is already Home it comes back through the Home
+# intent, since `am start -n` from the shell leaves a second MainActivity behind the Home one; before the handover
+# it is started by name as before.
+$restart = "a=`$(settings get secure enabled_accessibility_services); am force-stop $pkg; case `"`$(cmd package resolve-activity --brief -a android.intent.action.MAIN -c android.intent.category.HOME | tail -n 1)`" in $pkg/*) am start -a android.intent.action.MAIN -c android.intent.category.HOME >/dev/null ;; *) am start -n $pkg/.MainActivity >/dev/null ;; esac; 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.
diff --git a/tools/theme.sh b/tools/theme.sh
index f8b08200c..b63e81809 100755
--- a/tools/theme.sh
+++ b/tools/theme.sh
@@ -32,7 +32,10 @@ tv() { "$PY" -I tv.py "$@"; }
# itself goes off and on again, so switch it off with the list cleared and wait a second before writing back.
# By then Android has already emptied the list and switched accessibility off (Xiaomi MiTV-MOOR2, Android 11), so
# clearing it changed nothing and the services stayed crashed: write the list back first, so the clear is a change.
-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 \"\$a\"; settings put secure accessibility_enabled 1; 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"
+# When the launcher is already Home, it comes back through the Home intent: `am start -n` from the shell brings it
+# back in an ordinary task, and the next Home press starts a second MainActivity next to it. Otherwise (a theme
+# pushed before the handover) it is started by name as before, so the new look still shows.
+RESTART="a=\$(settings get secure enabled_accessibility_services); am force-stop $PKG; case \"\$(cmd package resolve-activity --brief -a android.intent.action.MAIN -c android.intent.category.HOME | tail -n 1)\" in $PKG/*) am start -a android.intent.action.MAIN -c android.intent.category.HOME >/dev/null ;; *) am start -n $PKG/.MainActivity >/dev/null ;; esac; case \"\$a\" in *$PKG*) sleep 1; settings put secure enabled_accessibility_services \"\$a\"; settings put secure accessibility_enabled 1; 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.