Skip to content

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

launcher: an install without RESTORE_KEY_SERVICES takes WRITE_SECURE_SETTINGS back

Rasmus Kjær Damgaard61ec917afe18
diff --git a/docs/TROUBLESHOOTING.md b/docs/TROUBLESHOOTING.md
index baf9f6c29..ffe0b5d71 100644
--- a/docs/TROUBLESHOOTING.md
+++ b/docs/TROUBLESHOOTING.md
@@ -1265,7 +1265,8 @@ first two writes are what make the opt-in survive, so read why:
- `WRITE_SECURE_SETTINGS` is what lets the launcher write the helper back onto the list at screen-on.
Without it `GuardKeep` gives up silently and the helper stays off after the first standby, which looks
like the helper having died. `RESTORE_KEY_SERVICES=1` at install already grants it
- ([the force-stop section](#accessibility-helper-enabled-but-the-remote-button-does-nothing)).
+ ([the force-stop section](#accessibility-helper-enabled-but-the-remote-button-does-nothing)), and an install
+ without it takes the grant back, so once the opt-in is on, pass it on every reinstall.
- `GuardRevival` is the listener the system re-binds once the process is gone, and firmware that kills
third-party apps in standby takes the screen-on watch with it. The rebind is what re-arms it.
diff --git a/launcher/build-and-install.ps1 b/launcher/build-and-install.ps1
index 5cb61cb04..f4e6bd599 100644
--- a/launcher/build-and-install.ps1
+++ b/launcher/build-and-install.ps1
@@ -7,7 +7,7 @@
# [-InputKeyService] remote's Input button opens the input switcher (Google TV), plus config.xml
# input_key_keycodes and app_keys; re-pass on every install
# [-HomeKeyService] remotes whose Home button sends KEYCODE_ALL_APPS (Xiaomi sticks)
-# [-RestoreKeyServices] grants WRITE_SECURE_SETTINGS for restore_key_services (helpers back after a force stop)
+# [-RestoreKeyServices] grants WRITE_SECURE_SETTINGS for restore_key_services (helpers back after a force stop); revoked without it
param(
[string]$TvHost = $env:TV_HOST,
[string]$StockLauncher = '',
@@ -155,7 +155,11 @@ function Enable-Service([string]$Name) {
}
if ($InputKeyService) { Enable-Service 'InputKeyService' }
if ($HomeKeyService) { Enable-Service 'HomeKeyService' }
+# The grant follows the switch on every install: pm install -r keeps a grant, so a run without the switch takes it
+# back. WRITE_SECURE_SETTINGS opens every secure and global setting, not only the accessibility list.
if ($RestoreKeyServices) {
'pm grant com.gathin.tvhome android.permission.WRITE_SECURE_SETTINGS && echo restore-granted' | & $py -I ..\tools\tv.py --batch
+} else {
+ 'pm revoke com.gathin.tvhome android.permission.WRITE_SECURE_SETTINGS 2>/dev/null; echo secure-settings-revoked' | & $py -I ..\tools\tv.py --batch
}
Write-Host 'Installed. Press Home on the remote to see it.'
diff --git a/launcher/build-and-install.sh b/launcher/build-and-install.sh
index f5d5a448e..b9b32821c 100755
--- a/launcher/build-and-install.sh
+++ b/launcher/build-and-install.sh
@@ -208,7 +208,7 @@ esac
# It also handles input_key_keycodes and app_keys (config.xml or a theme; a YouTube button)
# HOME_KEY_SERVICE=1 remotes whose Home button sends KEYCODE_ALL_APPS instead of HOME, e.g. Xiaomi
# sticks: the key is routed to the launcher (HomeKeyService)
-# RESTORE_KEY_SERVICES=1 grants WRITE_SECURE_SETTINGS, so that with restore_key_services (config.xml or a
+# RESTORE_KEY_SERVICES=1 grants WRITE_SECURE_SETTINGS (a run without it revokes it), so that with restore_key_services (config.xml or a
# theme) Home puts these helpers back after a force stop of the launcher
# TCL firmware (TclAppBoot) refuses to bind an app's accessibility service while the app is not running unless it
# holds the AUTO_START app-op, so grant it first; other TVs do not know the op and ignore it. Builds name it
@@ -223,7 +223,11 @@ enable_service() { # appends to enabled_accessibility_services without droppin
}
if [ "${INPUT_KEY_SERVICE:-0}" = 1 ]; then enable_service InputKeyService; fi
if [ "${HOME_KEY_SERVICE:-0}" = 1 ]; then enable_service HomeKeyService; fi
+# The grant follows the switch on every install: pm install -r keeps a grant, so a run without the switch takes it
+# back. WRITE_SECURE_SETTINGS opens every secure and global setting, not only the accessibility list.
if [ "${RESTORE_KEY_SERVICES:-0}" = 1 ]; then
"$PY" -I ../tools/tv.py "pm grant com.gathin.tvhome android.permission.WRITE_SECURE_SETTINGS && echo restore-granted"
+else
+ "$PY" -I ../tools/tv.py "pm revoke com.gathin.tvhome android.permission.WRITE_SECURE_SETTINGS 2>/dev/null; echo secure-settings-revoked"
fi
echo "Installed. Press Home on the remote to see it."